README
Affinity SDK for browser
Browser SDK extends CORE SDK. Make sure to check the CORE SDK documentation.
How to install
npm i --save @affinityproject/wallet-browser-sdk
Initialize
If you want to specify issuer's URL, pass it in the options.
You can also specify the stack environment to be used in env
variable.
env
- (optional) is enum which can be dev
| staging
| prod
(staging
is used by default).
const options = {
issuerUrl: 'https://affinity-issuer.staging.affinity-project.org'
}
const commonNetworkMember = new CommonNetworkMember(password, encryptedSeed, options)
options
- (optional) if not defined, values posted above will be used.
Initialize from user access token
Returns SDK instance when user is logged in, and throws
COR-9 / UnprocessableEntityError
if user is logged out.
import { AffinityWallet } from '@affinityproject/wallet-browser-sdk'
const affinityWallet = await AffinityWallet.init(options)
options
- optional, if not defined default settings will be used.
Create encrypted message
const encryptedMessage = await affinityWallet.createEncryptedMessage(toDid, object)
toDid
- DID, string value of document to be resolved.
object
- value to be encrypted by public key.
Read encrypted message
const message = await affinityWallet.readEncryptedMessage(encryptedMessage)
encryptedMessage
- message to be decrypted.
Put credential to VC vault
await affinityWallet.saveCredentials([signedCredential])
accepts array of credentials to store in the vault.
Pull credential from VC vault
const credentials = await affinityWallet.getCredentials(shareRequestToken)
shareRequestToken
- optional parameter (if passed - returns VC,
which match the request, if not - then returns all VCs).
Get credential issued during signup process
Behaves the same as the wallet-core-sdk confirmSignIn
method, but with the added option to issue a VC to the user's vault automatically upon signup with a verified email or phone number.
Confirm sign in (if using confirmSignIn for both sign up and login scenarios)
const issueSignupCredential = true
const { isNew, commonNetworkMember: affinityWallet } = await AffinityWallet.confirmSignIn(token, confirmationCode, options, issueSignupCredential)
token
- AWS Cognito Access Token
confirmationCode
- 6 digits code, generated and sent by AWS Cognito/SES.
options
- (optional) if not defined defaults will be used.
issueVC
- (optional) if not defined, set to false
Returns isNew
flag, identifying whether new account was created, and
initialized instance of SDK - affinityWallet
.
Confirm sign up
const issueSignupCredential = true
const affinityWallet = await AffinityWallet.confirmSignUp(token, confirmationCode, options, issueSignupCredential)
token
- AWS Cognito Access Token
confirmationCode
- 6 digits code, generated and sent by AWS Cognito/SES.
options
- (optional) used to specify environment stack (dev | staging | prod).
issueVC
- (optional) if not defined, set to false
Delete credential by ID
await affinityWallet.deleteCredential(credentialId)
For example:
const credentials = await affinityWallet.getCredentials() // get all credentials
const credentialId = ... // select credential which should be deleted, f.e `claimId:12345678`
await affinityWallet.deleteCredential(credentialId)