-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add credentials module * Adds changelog * Adds changelog * Make private storage property mandatory
- Loading branch information
1 parent
cab5a7e
commit c942c3c
Showing
7 changed files
with
152 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
'@spruceid/ssx': minor | ||
--- | ||
|
||
This adds the Credentials Modules, which allows developers to fetch credentials issued on SpruceKit Credential Issuer. | ||
This module requires Storage Module, so you must enable both to make it work. | ||
|
||
```ts | ||
const ssx = SSX({ | ||
modules: { | ||
storage: true, | ||
credentials: true | ||
} | ||
}) | ||
|
||
await ssx.signIn(); | ||
|
||
const { data } = ssx.credentials.list(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { SSXExtension } from "@spruceid/ssx-core/client"; | ||
import { IStorage } from "./Storage"; | ||
import { Response, Request } from './Storage/kepler'; | ||
|
||
|
||
export interface ICredentialsList { | ||
credentialType?: string, | ||
request?: Request, | ||
removePrefix?: boolean | ||
} | ||
|
||
export interface ICredentials extends SSXExtension { | ||
/** | ||
* Retrieves the stored value associated with the specified credential key. | ||
* @param credential - The unique identifier for the stored value. | ||
* @returns A Promise that resolves to the value associated with the given credential key or undefined if the credential key does not exist. | ||
*/ | ||
get(credential: string): Promise<Response>; | ||
|
||
/** | ||
* Lists all credential keys available. | ||
* @param credentialType - The credential identifier for the stored value. | ||
* @returns A Promise that resolves to an array of strings representing the stored credentials keys. | ||
*/ | ||
list(options: ICredentialsList): Promise<Response>; | ||
|
||
} | ||
export class Credentials implements ICredentials { | ||
public namespace = 'credentials'; | ||
private prefix: string = 'shared/credentials'; | ||
private storage: IStorage; | ||
|
||
constructor(storage: IStorage) { | ||
this.storage = storage; | ||
} | ||
|
||
public async get(credential: string): Promise<Response> { | ||
return this.storage.get(credential, { prefix: this.prefix }); | ||
} | ||
|
||
public async list(options: ICredentialsList): Promise<Response> { | ||
const defaultOptions = { | ||
prefix: this.prefix, | ||
}; | ||
const { prefix, credentialType, request, removePrefix } = { ...defaultOptions, ...options }; | ||
return this.storage.list({ prefix, path: credentialType, removePrefix, request }); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './UserAuthorization'; | ||
export * from './Storage'; | ||
export * from './Credentials'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters