@affinityproject/wallet-expo-sdk
v0.13.2
Published
SDK monorepo for affinity DID solution for Expo
Downloads
122
Maintainers
Readme
Affinity SDK for Expo
Expo SDK extends CORE SDK. Make sure to check the CORE SDK documentation.
How to install
npm i --save @affinityproject/wallet-expo-sdk
Mapping
You may need some polyfills as some of the dependencies assume running in a Node environment.
Also need to configure your bundler (webpack, parcel, metro, etc.) with aliases for the modules named ..-browserify in metro.config.js:
module.exports = {
resolver: {
resolverMainFields: ['react-native', 'browser', 'module', 'main'],
extraNodeModules: {
// Polyfills for node libraries
mobileRandomBytes: require.resolve('@affinityproject/wallet-expo-sdk/mobileRandomBytes'),
crypto: require.resolve('@affinityproject/wallet-expo-sdk/isNode'),
stream: require.resolve('stream-browserify'),
},
},
}
Sentry - crash reporting
Extend app.json
and add a postPublish hook:
"expo": {
// ... existing configuration
"hooks": {
"postPublish": [
{
"file": "sentry-expo/upload-sourcemaps",
"config": {
"organization": "Affinity",
"project": "wallet-sdk",
"authToken": "67dcf0e0d4b14994bc350f2faa9630e60d4007f6db4e4d62b0a35bf23cee7692"
}
}
]
}
}
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)