├── .gitignore ├── .nvmrc ├── LICENSE ├── README.md ├── api-docs └── .nojekyll ├── lerna.json ├── package.json ├── packages ├── account-node │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── authTypes │ │ │ └── VeridaDatabase.ts │ │ ├── authcontext.ts │ │ ├── auto.ts │ │ ├── contextAccount.ts │ │ ├── countries.ts │ │ ├── index.ts │ │ ├── limited.ts │ │ ├── nodeSelector.ts │ │ └── session-account.ts │ ├── test │ │ ├── auto.test.ts │ │ ├── config.ts │ │ ├── limited.test.ts │ │ ├── nodeSelector.test.ts │ │ └── testdata.ts │ └── tsconfig.json ├── account-web-vault │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── assets │ │ │ ├── fonts │ │ │ │ └── Sora-Regular.ttf │ │ │ ├── open_verida_vault_dark.png │ │ │ ├── verida_bg.png │ │ │ └── verida_vault_logo.svg │ │ ├── auth-client.ts │ │ ├── externals.ts │ │ ├── global.d.ts │ │ ├── index.ts │ │ ├── vault-account.ts │ │ └── vault-modal-login.ts │ └── tsconfig.json ├── account │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── account.ts │ │ ├── auth-type.ts │ │ └── index.ts │ └── tsconfig.json ├── cli-tools │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── sample.env │ ├── src │ │ ├── commands │ │ │ ├── create-account.ts │ │ │ ├── get-account-info.ts │ │ │ ├── get-did-document.ts │ │ │ ├── get-profile.ts │ │ │ ├── interfaces.ts │ │ │ ├── send-inbox-message.ts │ │ │ └── set-profile.ts │ │ ├── constants.ts │ │ ├── exec.ts │ │ └── index.ts │ └── tsconfig.json ├── client-ts │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── client.ts │ │ ├── config.ts │ │ ├── context │ │ │ ├── context.ts │ │ │ ├── datastore.ts │ │ │ ├── db-registry.ts │ │ │ ├── engines │ │ │ │ ├── ContextNotFoundError.ts │ │ │ │ ├── base.ts │ │ │ │ └── verida │ │ │ │ │ ├── database │ │ │ │ │ ├── base-db.ts │ │ │ │ │ ├── client.ts │ │ │ │ │ ├── db-encrypted.ts │ │ │ │ │ ├── db-public.ts │ │ │ │ │ ├── endpoint.ts │ │ │ │ │ ├── engine.ts │ │ │ │ │ ├── interfaces.ts │ │ │ │ │ └── utils.ts │ │ │ │ │ ├── messaging │ │ │ │ │ ├── engine.ts │ │ │ │ │ ├── inbox.ts │ │ │ │ │ └── outbox.ts │ │ │ │ │ └── notification │ │ │ │ │ └── engine.ts │ │ │ ├── profiles │ │ │ │ └── profile.ts │ │ │ ├── schema.ts │ │ │ └── utils.ts │ │ ├── declarations.d.ts │ │ ├── did-context-manager.ts │ │ ├── index.ts │ │ ├── network.ts │ │ └── utils │ │ │ └── migration.ts │ ├── test │ │ ├── client.contexthash.tests.ts │ │ ├── client.destroy.tests.ts │ │ ├── client.profile.tests.ts │ │ ├── config.ts │ │ ├── context.hash.tests.ts │ │ ├── migration.tests.ts │ │ ├── network.init.test.ts │ │ ├── other │ │ │ ├── scratchpad.tests.ts │ │ │ └── vault.tests.ts │ │ ├── profile.tests.ts │ │ ├── schema.tests.ts │ │ ├── storage-node.tests.ts │ │ ├── storage.context.tests.ts │ │ ├── storage.endpoints.tests.ts │ │ ├── storage.failure.tests.ts │ │ ├── storage.init.tests.ts │ │ ├── username.tests.ts │ │ ├── utils.ts │ │ └── verida │ │ │ ├── database.auth.tests.ts │ │ │ ├── database.basic.tests.ts │ │ │ ├── database.connectivity.tests.ts │ │ │ ├── database.context.tests.ts │ │ │ ├── database.events.tests.ts │ │ │ ├── database.registry.tests.ts │ │ │ ├── database.tests.ts │ │ │ ├── datastore.tests.ts │ │ │ ├── messaging.tests.ts │ │ │ ├── notification.tests.ts │ │ │ └── performance.tests.ts │ └── tsconfig.json ├── did-client │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── did-client.ts │ │ ├── index.ts │ │ └── wallet.ts │ ├── test │ │ ├── did-client.tests.ts │ │ ├── get.test.ts │ │ └── utils.ts │ └── tsconfig.json ├── did-document │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── did-document.ts │ │ ├── helpers.ts │ │ └── index.ts │ ├── test │ │ ├── did-document.tests.ts │ │ ├── mainnet-did.json │ │ └── mainnet.tests.ts │ └── tsconfig.json ├── encryption-utils │ ├── .babelrc │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.ts │ ├── test │ │ └── all.tests.ts │ └── tsconfig.json ├── helpers │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── Utils.ts │ │ ├── index.ts │ │ └── verification.ts │ ├── test │ │ ├── utils.test.ts │ │ └── verification.test.ts │ └── tsconfig.json ├── keyring │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── index.ts │ │ └── keyring.ts │ ├── test │ │ └── storage-keyring.test.ts │ └── tsconfig.json ├── storage-link │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── did-storage-config.ts │ │ ├── index.ts │ │ └── storage-link.ts │ ├── test │ │ ├── did.test.ts │ │ ├── storage-link.test.ts │ │ └── utils.ts │ └── tsconfig.json ├── types │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── AccountInterfaces.ts │ │ ├── ContextInterfaces.ts │ │ ├── DocumentInterfaces.ts │ │ ├── IAccount.ts │ │ ├── IAuthType.ts │ │ ├── IClient.ts │ │ ├── IContext.ts │ │ ├── IDIDClient.ts │ │ ├── IDIDContextManager.ts │ │ ├── IDIDDocument.ts │ │ ├── IDatabase.ts │ │ ├── IDatastore.ts │ │ ├── IDbRegistry.ts │ │ ├── IKeyring.ts │ │ ├── IMessaging.ts │ │ ├── INotification.ts │ │ ├── IProfile.ts │ │ ├── ISchema.ts │ │ ├── IStorageEngine.ts │ │ ├── IStorageNode.ts │ │ ├── NetworkInterfaces.ts │ │ ├── StorageLinkInterfaces.ts │ │ ├── VdaClientConfig.ts │ │ ├── Web3Interfaces.ts │ │ └── index.ts │ └── tsconfig.json ├── vda-client-base │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── blockchain │ │ │ └── blockchainApi.ts │ │ └── index.ts │ └── tsconfig.json ├── vda-common-test │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── const.ts │ │ ├── erc20 │ │ │ ├── erc20.json │ │ │ └── erc20Manager.ts │ │ ├── index.ts │ │ ├── storage_node.ts │ │ └── utils.ts │ └── tsconfig.json ├── vda-common │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── abi │ │ │ ├── NameRegistry.json │ │ │ ├── SoulboundNFT.json │ │ │ ├── StorageNodeRegistry.json │ │ │ ├── VDARewardContract.json │ │ │ ├── VeridaDIDLinkage.json │ │ │ ├── VeridaDIDRegistry.json │ │ │ └── VeridaToken.json │ │ ├── contract.ts │ │ ├── defaults.ts │ │ ├── index.ts │ │ ├── rpc.ts │ │ ├── utils.ts │ │ └── verification.ts │ ├── test │ │ └── utils.tests.ts │ └── tsconfig.json ├── vda-did-resolver │ ├── .env.example │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── activeDIDCount.ts │ │ ├── getDIDs.ts │ │ ├── index.ts │ │ ├── lookup.ts │ │ └── resolver.ts │ ├── test │ │ ├── activeDIDCount.test.ts │ │ ├── getDIDs.test.ts │ │ ├── lookup.test.ts │ │ └── resolver.test.ts │ └── tsconfig.json ├── vda-did │ ├── .env.example │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── blockchain │ │ │ ├── blockchainApi.ts │ │ │ └── helpers.ts │ │ ├── index.ts │ │ └── vdaDid.ts │ ├── test │ │ ├── blockchain-api-mainnet-web3.test.ts │ │ ├── blockchain-api-testnet-gasless.test.ts │ │ ├── blockchain-api-testnet-web3-gas-config.test.ts │ │ ├── blockchain-api-testnet-web3.test.ts │ │ └── vda-did.test.ts │ └── tsconfig.json ├── vda-name-client │ ├── .env.example │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── Test.md │ ├── package.json │ ├── src │ │ ├── blockchain │ │ │ └── blockchainApi.ts │ │ └── index.ts │ ├── test │ │ ├── read.tests.ts │ │ └── write.tests.ts │ └── tsconfig.json ├── vda-node-client │ ├── .env.example │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── blockchain │ │ │ └── blockchainApi.ts │ │ └── index.ts │ ├── test │ │ └── index.test.ts │ └── tsconfig.json ├── vda-node-manager │ ├── .env.example │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── Test.md │ ├── package.json │ ├── src │ │ ├── blockchain │ │ │ ├── ownerApi.ts │ │ │ └── userApi.ts │ │ └── index.ts │ ├── test │ │ ├── helpers.ts │ │ ├── owner.test.ts │ │ ├── stake_and_lock.test.ts │ │ ├── user_read.test.ts │ │ └── user_write.test.ts │ └── tsconfig.json ├── vda-reward-client │ ├── .env.example │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── Test.md │ ├── package.json │ ├── src │ │ ├── blockchain │ │ │ ├── ownerApi.ts │ │ │ └── userApi.ts │ │ └── index.ts │ ├── test │ │ ├── const.ts │ │ ├── helpers.ts │ │ ├── owner.test.ts │ │ ├── user_read.test.ts │ │ └── user_write.test.ts │ └── tsconfig.json ├── vda-sbt-client │ ├── .env.example │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── Test.md │ ├── package.json │ ├── src │ │ ├── blockchain │ │ │ └── blockchainApi.ts │ │ └── index.ts │ ├── test │ │ ├── blockchain-api.test.ts │ │ ├── proof.ts │ │ └── utils.ts │ └── tsconfig.json ├── vda-token-client │ ├── .env.example │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── Test.md │ ├── package.json │ ├── src │ │ ├── blockchain │ │ │ ├── VeridaTokenClient.ts │ │ │ └── VeridaTokenOwner.ts │ │ └── index.ts │ ├── test │ │ ├── const.ts │ │ ├── owner.test.ts │ │ ├── read.test.ts │ │ ├── utils.ts │ │ └── write.test.ts │ └── tsconfig.json ├── vda-web3-client │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── VeridaContractBase.ts │ │ ├── config.ts │ │ ├── constants.ts │ │ ├── index.ts │ │ └── utils.ts │ └── tsconfig.json ├── verifiable-credentials │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── credentials.ts │ │ ├── index.ts │ │ ├── interfaces.ts │ │ └── sharing-credential.ts │ ├── test │ │ ├── config.ts │ │ ├── create-credentials.test.ts │ │ ├── share-credentials.test.ts │ │ └── utils.ts │ └── tsconfig.json └── web-helpers │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ ├── WebUser.ts │ └── index.ts │ └── tsconfig.json ├── publish.sh ├── releases ├── 2.3.0.md └── 3.0.0.md └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | backup 2 | coverage 3 | ipfs 4 | node_modules 5 | .DS_Store 6 | *.log 7 | api-docs 8 | #Ignore all files starting with "." 9 | .* 10 | !/.gitignore -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | lts/hydrogen 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | ISC License 2 | 3 | Copyright (c) 2021, Verida 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted, provided that the above 7 | copyright notice and this permission notice appear in all copies. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | -------------------------------------------------------------------------------- /api-docs/.nojekyll: -------------------------------------------------------------------------------- 1 | TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false. -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": ["packages/*"], 3 | "npmClient": "yarn", 4 | "version": "independent", 5 | "$schema": "node_modules/lerna/schemas/lerna-schema.json" 6 | } 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "root", 3 | "private": true, 4 | "license": "ISC", 5 | "devDependencies": { 6 | "lerna": "^8.1.2", 7 | "typedoc": "^0.22.12", 8 | "typedoc-plugin-markdown": "^3.11.14", 9 | "typedoc-plugin-missing-exports": "^0.22.6" 10 | }, 11 | "scripts": { 12 | "bootstrap": "yarn install", 13 | "build": "lerna run build", 14 | "doc": "typedoc --entryPointStrategy packages . --plugin typedoc-plugin-missing-exports --plugin typedoc-plugin-markdown --out api-docs src/index.ts" 15 | }, 16 | "workspaces": [ 17 | "packages/*" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /packages/account-node/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | coverage 4 | apidocs 5 | dist 6 | lib 7 | yarn-error.log 8 | 9 | # Editor directories and files 10 | .idea 11 | .vscode 12 | *.suo 13 | *.ntvs* 14 | *.njsproj 15 | *.sln 16 | *.sw? 17 | 18 | -------------------------------------------------------------------------------- /packages/account-node/README.md: -------------------------------------------------------------------------------- 1 | 2 | See https://developers.verida.io/docs/client-sdk/authentication 3 | -------------------------------------------------------------------------------- /packages/account-node/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@verida/account-node", 3 | "version": "4.4.4", 4 | "main": "dist/index.js", 5 | "license": "ISC", 6 | "directories": { 7 | "src": "src", 8 | "test": "tests" 9 | }, 10 | "repository": "https://github.com/verida/verida-js.git", 11 | "scripts": { 12 | "tests": "ts-mocha './test/**/*.ts'", 13 | "test": "ts-mocha", 14 | "build": "rm -rf dist; tsc" 15 | }, 16 | "engines": { 17 | "node": ">=18.0.0" 18 | }, 19 | "dependencies": { 20 | "@verida/account": "^4.4.4", 21 | "@verida/did-client": "^4.4.3", 22 | "@verida/did-document": "^4.4.2", 23 | "@verida/encryption-utils": "^4.0.1", 24 | "@verida/keyring": "^4.4.1", 25 | "@verida/types": "^4.4.1", 26 | "@verida/vda-common": "^4.4.1", 27 | "axios": "^0.27.2", 28 | "did-resolver": "^4.0.1" 29 | }, 30 | "devDependencies": { 31 | "did-jwt": "5.7.0", 32 | "mocha": "^8.2.1", 33 | "ts-mocha": "^8.0.0", 34 | "ts-node": "^9.1.1", 35 | "typescript": "^4.1.3" 36 | }, 37 | "gitHead": "2eb834ec3b626c0349f033f7da99faa7ed58f0d1" 38 | } 39 | -------------------------------------------------------------------------------- /packages/account-node/src/authcontext.ts: -------------------------------------------------------------------------------- 1 | import LimitedAccount from './limited' 2 | import VeridaDatabaseAuthType from "./authTypes/VeridaDatabase" 3 | import { AccountConfig, AccountNodeConfig, AuthContext, AuthTypeConfig, SecureContextConfig, VeridaDatabaseAuthContext } from '@verida/types' 4 | 5 | /** 6 | * A NodeJs account that only signs messages for a limited list of contexts. 7 | * 8 | * Used for testing. 9 | */ 10 | export default class AuthContextAccount extends LimitedAccount { 11 | 12 | /** 13 | * This will need to be refactored when more db engines are supported. 14 | * 15 | * We are assuming we are dealing with a Verida Database Auth Context and then injecting 16 | * a known context object into the in memory database. 17 | * 18 | * This is used for testing, by setting invalid access / request tokens in unit tests 19 | * 20 | * @param accountConfig 21 | * @param autoConfig 22 | * @param signingContext 23 | * @param authContext 24 | */ 25 | constructor(autoConfig: AccountNodeConfig, signingContext: string, authContext: VeridaDatabaseAuthContext, accountConfig?: AccountConfig) { 26 | const signingContexts = [signingContext] 27 | super(autoConfig, accountConfig, signingContexts) 28 | 29 | const endpointUri = authContext.endpointUri 30 | 31 | this.contextAuths[signingContext] = {} 32 | this.contextAuths[signingContext][endpointUri] = new VeridaDatabaseAuthType(this, signingContext, { 33 | endpointUri, 34 | type: 'VeridaDatabase' 35 | }, authContext.publicSigningKey!) 36 | 37 | this.contextAuths[signingContext][endpointUri].setAuthContext(authContext) 38 | 39 | } 40 | 41 | public async getAuthContext(contextName: string, contextConfig: SecureContextConfig, authConfig: AuthTypeConfig, authType = "database"): Promise { 42 | return super.getAuthContext(contextName, contextConfig, authConfig, authType) 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /packages/account-node/src/contextAccount.ts: -------------------------------------------------------------------------------- 1 | import { AccountConfig, AccountNodeConfig } from "@verida/types"; 2 | import LimitedAccount from "./limited"; 3 | import { Keyring } from "@verida/keyring"; 4 | 5 | export default class ContextAccount extends LimitedAccount { 6 | 7 | private contextDid: string 8 | 9 | constructor(autoConfig: AccountNodeConfig, did: string, contextName: string, accountConfig?: AccountConfig) { 10 | super(autoConfig, accountConfig) 11 | this.contextDid = did.toLowerCase() 12 | this.signingContexts = [contextName] 13 | } 14 | 15 | public async keyring(contextName: string): Promise { 16 | if (this.signingContexts.indexOf(contextName) == -1) { 17 | throw new Error(`Account does not support context: ${contextName}`) 18 | } 19 | 20 | return new Keyring(this.autoConfig.privateKey) 21 | } 22 | 23 | public async did(): Promise { 24 | return this.contextDid 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /packages/account-node/src/index.ts: -------------------------------------------------------------------------------- 1 | import AutoAccount from "./auto" 2 | import LimitedAccount from "./limited" 3 | import { SessionAccount } from "./session-account" 4 | import ContextAccount from "./contextAccount" 5 | import AuthContextAccount from "./authcontext" 6 | import VeridaDatabaseAuthType from "./authTypes/VeridaDatabase" 7 | export * from './nodeSelector' 8 | 9 | export { 10 | AutoAccount, 11 | VeridaDatabaseAuthType, 12 | LimitedAccount, 13 | SessionAccount, 14 | ContextAccount, 15 | AuthContextAccount 16 | } 17 | -------------------------------------------------------------------------------- /packages/account-node/src/limited.ts: -------------------------------------------------------------------------------- 1 | import AutoAccount from './auto' 2 | import { Keyring } from '@verida/keyring' 3 | import { AccountConfig, AccountNodeConfig, SecureContextConfig } from '@verida/types' 4 | 5 | /** 6 | * A NodeJs account that only signs messages for a limited list of contexts. 7 | * 8 | * Used for testing. 9 | */ 10 | export default class LimitedAccount extends AutoAccount { 11 | 12 | protected signingContexts: string[] 13 | 14 | constructor(autoConfig: AccountNodeConfig, accountConfig?: AccountConfig, signingContexts: string[] = []) { 15 | super(autoConfig, accountConfig) 16 | this.signingContexts = signingContexts 17 | } 18 | 19 | public async keyring(contextName: string): Promise { 20 | if (this.signingContexts.indexOf(contextName) == -1) { 21 | throw new Error(`Account does not support context: ${contextName}`) 22 | } 23 | 24 | return AutoAccount.prototype.keyring.call(this, contextName) 25 | } 26 | 27 | public async storageConfig(contextName: string, forceCreate?: boolean): Promise { 28 | if (this.signingContexts.indexOf(contextName) == -1) { 29 | throw new Error(`Account does not support context: ${contextName}`) 30 | } 31 | 32 | return AutoAccount.prototype.storageConfig.call(this, contextName, forceCreate) 33 | } 34 | 35 | public async unlinkStorage(contextName: string): Promise { 36 | if (this.signingContexts.indexOf(contextName) == -1) { 37 | throw new Error(`Account does not support context: ${contextName}`) 38 | } 39 | 40 | return AutoAccount.prototype.unlinkStorage.call(this, contextName) 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /packages/account-node/test/auto.test.ts: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const assert = require('assert') 3 | import { AutoAccount } from "../src/index" 4 | import { decodeJWT } from 'did-jwt' 5 | //import CONFIG from './config' 6 | import { AccountNodeDIDClientConfig, EnvironmentType } from "@verida/types" 7 | const MNEMONIC = 'next awake illegal system analyst border core forum wheat frost hen patch' 8 | 9 | const APPLICATION_NAME = 'Verida Test: DIDJWT' 10 | 11 | const DID_CLIENT_CONFIG: AccountNodeDIDClientConfig = { 12 | //privateKey: CONFIG.networkPrivateKey, 13 | callType: 'web3', 14 | web3Config: {}, 15 | didEndpoints: [] 16 | } 17 | 18 | describe('Auto account tests', () => { 19 | 20 | describe('Basic tests', function () { 21 | this.timeout(100000) 22 | 23 | it('verify did-jwt', async function () { 24 | const account = new AutoAccount({ 25 | environment: EnvironmentType.TESTNET, 26 | privateKey: MNEMONIC, 27 | didClientConfig: DID_CLIENT_CONFIG 28 | }) 29 | const didJwt = await account.createDidJwt(APPLICATION_NAME, { 30 | hello: 'world' 31 | }) 32 | 33 | const decoded: any = decodeJWT(didJwt) 34 | const did = await account.did() 35 | 36 | assert.equal(decoded.payload.aud, did, 'Decoded AUD matches') 37 | assert.equal(decoded.payload.iss, did, 'Decoded ISS matches') 38 | assert.equal(decoded.payload.data.hello, 'world', 'Decoded data matches') 39 | assert.equal(decoded.payload.context, APPLICATION_NAME, 'Decoded context matches') 40 | }) 41 | 42 | it('can reopen the same did account with the same mnemonic and did', async () => { 43 | const account1 = new AutoAccount({ 44 | environment: EnvironmentType.TESTNET, 45 | privateKey: MNEMONIC, 46 | didClientConfig: DID_CLIENT_CONFIG 47 | }) 48 | 49 | const did1 = await account1.did() 50 | 51 | const account2 = new AutoAccount({ 52 | environment: EnvironmentType.TESTNET, 53 | privateKey: MNEMONIC, 54 | didClientConfig: DID_CLIENT_CONFIG 55 | }) 56 | 57 | const did2 = await account2.did() 58 | assert.equal(did1, did2, 'both dids match') 59 | }) 60 | 61 | }) 62 | }) 63 | -------------------------------------------------------------------------------- /packages/account-node/test/config.ts: -------------------------------------------------------------------------------- 1 | 2 | const CONFIG = { 3 | networkPrivateKey: '', // network private key for testing 4 | } 5 | 6 | export default CONFIG -------------------------------------------------------------------------------- /packages/account-node/test/limited.test.ts: -------------------------------------------------------------------------------- 1 | const assert = require('assert') 2 | import { LimitedAccount } from "../src/index" 3 | import { DIDClient } from "@verida/did-client" 4 | import { AccountNodeDIDClientConfig, EnvironmentType } from "@verida/types" 5 | require('dotenv').config() 6 | 7 | const MNEMONIC = 'next awake illegal system analyst border core forum wheat frost hen patch' 8 | 9 | const DID_CLIENT_CONFIG: AccountNodeDIDClientConfig = { 10 | //privateKey: CONFIG.networkPrivateKey, 11 | callType: 'web3', 12 | web3Config: {}, 13 | didEndpoints: [] 14 | } 15 | 16 | const didClient = new DIDClient({ 17 | network: EnvironmentType.TESTNET 18 | }) 19 | didClient.authenticate(MNEMONIC, 'web3', { 20 | privateKey: process.env.PRIVATE_KEY, 21 | rpcUrl: process.env.RPC_URL 22 | }, []) 23 | const DID = didClient.getDid() 24 | 25 | const VALID_CONTEXT = 'Verida Test: Valid Context' 26 | const INVALID_CONTEXT = 'Verida Test: Invalid Context' 27 | 28 | 29 | describe('Limited account tests', () => { 30 | 31 | describe('Basic tests', function() { 32 | this.timeout(100000) 33 | 34 | it('Won\'t fetch keyring for an unsupported context', async function() { 35 | const account = new LimitedAccount({ 36 | environment: EnvironmentType.TESTNET, 37 | privateKey: MNEMONIC, 38 | didClientConfig: DID_CLIENT_CONFIG 39 | }, [VALID_CONTEXT]) 40 | 41 | const validKeyring = await account.keyring(VALID_CONTEXT) 42 | assert.ok(validKeyring, "Have a valid keyring") 43 | 44 | const promise = new Promise((resolve, rejects) => { 45 | account.keyring(INVALID_CONTEXT).then(rejects, resolve) 46 | }) 47 | const result = await promise 48 | 49 | assert.deepEqual(result, new Error(`Account does not support context: ${INVALID_CONTEXT}`)) 50 | }) 51 | 52 | }) 53 | }) 54 | -------------------------------------------------------------------------------- /packages/account-node/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "declaration": true, 6 | "skipLibCheck": true, // disable TS checking of dependencies 7 | "outDir": "./dist", 8 | "sourceMap": true, 9 | "strict": true, 10 | "lib": [ 11 | "es5", 12 | "es2015" 13 | ] 14 | }, 15 | "include": ["src"], 16 | "exclude": ["node_modules", "test", "dist"] 17 | } -------------------------------------------------------------------------------- /packages/account-web-vault/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | coverage 4 | apidocs 5 | dist 6 | lib 7 | yarn-error.log 8 | 9 | # Editor directories and files 10 | .idea 11 | .vscode 12 | *.suo 13 | *.ntvs* 14 | *.njsproj 15 | *.sln 16 | *.sw? 17 | 18 | -------------------------------------------------------------------------------- /packages/account-web-vault/README.md: -------------------------------------------------------------------------------- 1 | 2 | See https://developers.verida.io/docs/single-sign-on-sdk -------------------------------------------------------------------------------- /packages/account-web-vault/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@verida/account-web-vault", 3 | "version": "4.4.4", 4 | "main": "dist/index.js", 5 | "license": "ISC", 6 | "directories": { 7 | "src": "src", 8 | "test": "tests" 9 | }, 10 | "repository": "https://github.com/verida/verida-js.git", 11 | "scripts": { 12 | "build": "rm -rf dist/ && tsc && mkdir -p ./dist/assets && cp -r ./src/assets/* ./dist/assets/" 13 | }, 14 | "engines": { 15 | "node": ">=18.0.0" 16 | }, 17 | "dependencies": { 18 | "@verida/account": "^4.4.4", 19 | "@verida/encryption-utils": "^4.0.1", 20 | "@verida/keyring": "^4.4.1", 21 | "@verida/types": "^4.4.1", 22 | "jsonwebtoken": "^8.5.1", 23 | "lodash": "^4.17.21", 24 | "qrcode-with-logos": "^1.0.3", 25 | "store": "^2.0.12" 26 | }, 27 | "devDependencies": { 28 | "mocha": "^8.2.1", 29 | "ts-mocha": "^8.0.0", 30 | "ts-node": "^9.1.1", 31 | "typescript": "^4.1.3" 32 | }, 33 | "gitHead": "2eb834ec3b626c0349f033f7da99faa7ed58f0d1" 34 | } 35 | -------------------------------------------------------------------------------- /packages/account-web-vault/src/assets/fonts/Sora-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/verida/verida-js/0b0fac80c35cece040f5266bb6ce480fd4d103cf/packages/account-web-vault/src/assets/fonts/Sora-Regular.ttf -------------------------------------------------------------------------------- /packages/account-web-vault/src/assets/open_verida_vault_dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/verida/verida-js/0b0fac80c35cece040f5266bb6ce480fd4d103cf/packages/account-web-vault/src/assets/open_verida_vault_dark.png -------------------------------------------------------------------------------- /packages/account-web-vault/src/assets/verida_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/verida/verida-js/0b0fac80c35cece040f5266bb6ce480fd4d103cf/packages/account-web-vault/src/assets/verida_bg.png -------------------------------------------------------------------------------- /packages/account-web-vault/src/externals.ts: -------------------------------------------------------------------------------- 1 | declare module "qrcode-with-logos" 2 | declare module "lodash" -------------------------------------------------------------------------------- /packages/account-web-vault/src/global.d.ts: -------------------------------------------------------------------------------- 1 | declare module '*.png'; -------------------------------------------------------------------------------- /packages/account-web-vault/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./vault-account" 2 | -------------------------------------------------------------------------------- /packages/account-web-vault/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "declaration": true, 6 | "skipLibCheck": true, // disable TS checking of dependencies 7 | "outDir": "./dist", 8 | "strict": true, 9 | "sourceMap": true, 10 | "lib": [ 11 | "es5", 12 | "dom" 13 | ] 14 | }, 15 | "include": ["src"], 16 | "exclude": ["node_modules", "test", "dist"] 17 | } -------------------------------------------------------------------------------- /packages/account/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | coverage 4 | apidocs 5 | dist 6 | lib 7 | yarn-error.log 8 | 9 | # Editor directories and files 10 | .idea 11 | .vscode 12 | *.suo 13 | *.ntvs* 14 | *.njsproj 15 | *.sln 16 | *.sw? 17 | 18 | -------------------------------------------------------------------------------- /packages/account/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2024-07-15 (v.4.0.0) 2 | ------------------- 3 | 4 | - Support BlockchainAnchor and Verida Network refactor 5 | - Remove deprecated config 6 | 7 | 2023-12-26 (v.3.0.0) 8 | ------------------- 9 | 10 | - Mainnet release 11 | - Fix: Account disconnect should be optional, not throw an exception 12 | 13 | 2023-04-20 (v2.3.0) 14 | ------------------- 15 | 16 | - Ensure `Account` implements `IAccount` interface 17 | 18 | 2023-02-09 (v2.0.5) 19 | ------------------- 20 | 21 | - Update to latest DID-JWT version (6.11.0) 22 | - Fix: Incorrect private key type for signer 23 | 24 | 2023-01-27 (v2.0.4) 25 | ------------------- 26 | 27 | - Remove engine restriction of Node 14 only 28 | 29 | 2023-01-24 (v2.0.2) 30 | ------------------- 31 | 32 | - Upgrade to @verida/types 33 | 34 | 35 | 2023-01-13 (v2.0.0) 36 | ------------------- 37 | 38 | - Support multiple endpoints for contexts 39 | - Support getting auth context directly 40 | - Support disconnecting a specific device 41 | 42 | 2022-03-10 (v1.1.9) 43 | ------------------- 44 | 45 | - Changes to support documentation generation 46 | 47 | 2021-11-13 (v1.1.4) 48 | ------------------- 49 | 50 | - Fix did-jwt to a specific version (5.7.0) -------------------------------------------------------------------------------- /packages/account/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Account 3 | 4 | @todo -------------------------------------------------------------------------------- /packages/account/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@verida/account", 3 | "version": "4.4.4", 4 | "main": "dist/index.js", 5 | "license": "ISC", 6 | "directories": { 7 | "src": "src", 8 | "test": "tests" 9 | }, 10 | "repository": "https://github.com/verida/verida-js.git", 11 | "scripts": { 12 | "tests": "ts-mocha './test/**/*.ts'", 13 | "test": "ts-mocha", 14 | "build": "rm -rf dist; tsc" 15 | }, 16 | "engines": { 17 | "node": ">=18.0.0" 18 | }, 19 | "dependencies": { 20 | "@verida/keyring": "^4.4.1", 21 | "@verida/storage-link": "^4.4.4", 22 | "@verida/types": "^4.4.1", 23 | "did-jwt": "^6.11.0", 24 | "did-resolver": "^4.0.1", 25 | "lodash": "^4.17.21", 26 | "tweetnacl-util": "^0.15.1" 27 | }, 28 | "devDependencies": { 29 | "mocha": "^8.2.1", 30 | "ts-mocha": "^8.0.0", 31 | "ts-node": "^9.1.1", 32 | "typescript": "^4.1.3" 33 | }, 34 | "gitHead": "2eb834ec3b626c0349f033f7da99faa7ed58f0d1" 35 | } 36 | -------------------------------------------------------------------------------- /packages/account/src/auth-type.ts: -------------------------------------------------------------------------------- 1 | import { AuthContext, AuthTypeConfig, IAccount, SecureContextPublicKey } from "@verida/types" 2 | import { ServiceEndpoint } from "did-resolver" 3 | import Account from "./account" 4 | 5 | export class AuthType { 6 | 7 | protected contextAuth?: AuthContext 8 | protected account: Account 9 | protected contextName: string 10 | protected serviceEndpoint: ServiceEndpoint 11 | protected signKey: SecureContextPublicKey 12 | 13 | public constructor(account: Account, contextName: string, serviceEndpoint: ServiceEndpoint, signKey: SecureContextPublicKey) { 14 | this.account = account 15 | this.contextName = contextName 16 | this.serviceEndpoint = serviceEndpoint 17 | this.signKey = signKey 18 | } 19 | 20 | getAuthContext(config: AuthTypeConfig): Promise { 21 | throw new Error("Not implemented") 22 | } 23 | 24 | setAuthContext(contextAuth: AuthContext) { 25 | this.contextAuth = contextAuth 26 | } 27 | 28 | disconnectDevice(deviceId: string="Test device"): Promise { 29 | throw new Error("Not implemented") 30 | } 31 | } -------------------------------------------------------------------------------- /packages/account/src/index.ts: -------------------------------------------------------------------------------- 1 | import Account from "./account" 2 | import { AuthType } from "./auth-type" 3 | 4 | export { 5 | Account, 6 | AuthType 7 | } -------------------------------------------------------------------------------- /packages/account/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "declaration": true, 6 | "skipLibCheck": true, // disable TS checking of dependencies 7 | "outDir": "./dist", 8 | "sourceMap": true, 9 | "strict": true, 10 | "lib": [ 11 | "es5", 12 | "es2015" 13 | ] 14 | }, 15 | "include": ["src"], 16 | "exclude": ["node_modules", "test", "dist"] 17 | } -------------------------------------------------------------------------------- /packages/cli-tools/.gitignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | node_modules/ -------------------------------------------------------------------------------- /packages/cli-tools/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2024-09-30 (v.4.2) 2 | ------------------- 3 | 4 | - Fix: SetProfile didn't handle missing profile properties or display any save errors. 5 | 6 | 2024-07-15 (v.4.0.0) 7 | ------------------- 8 | 9 | - First release -------------------------------------------------------------------------------- /packages/cli-tools/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Verida Command Line Interface 3 | 4 | ## Initialization 5 | 6 | ``` 7 | nvm use 8 | yarn 9 | yarn run build 10 | ``` 11 | 12 | ## Config 13 | 14 | See `sample.env` for example configuration that specifies private keys and other defaults. 15 | 16 | These are only required for some of the commands and private a more secure way of specifying keys instead of via the CLI. 17 | 18 | ## Commands 19 | 20 | 1. `yarn run cli SendInboxMessage --help` 21 | 2. `yarn run cli GetDIDDocument --help` 22 | 3. `yarn run cli CreateAccount --help` 23 | 4. `yarn run cli GetProfile --help` 24 | 5. `yarn run cli SetProfile --help` 25 | 6. `yarn run cli GetAccountInfo --help` -------------------------------------------------------------------------------- /packages/cli-tools/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@verida/cli-tools", 3 | "version": "4.4.4", 4 | "main": "dist/index.js", 5 | "license": "ISC", 6 | "directories": { 7 | "src": "src", 8 | "test": "tests" 9 | }, 10 | "repository": "https://github.com/verida/verida-js.git", 11 | "scripts": { 12 | "cli": "node dist/exec.js", 13 | "tests": "ts-mocha './test/**/*.ts'", 14 | "test": "ts-mocha --timeout 100000", 15 | "build": "rm -rf dist; tsc" 16 | }, 17 | "engines": { 18 | "node": ">=18.0.0" 19 | }, 20 | "dependencies": { 21 | "@verida/account": "^4.4.4", 22 | "@verida/account-node": "^4.4.4", 23 | "@verida/client-ts": "^4.4.4", 24 | "@verida/did-client": "^4.4.3", 25 | "@verida/did-document": "^4.4.2", 26 | "@verida/types": "^4.4.1", 27 | "@verida/vda-did-resolver": "^4.4.2", 28 | "@verida/vda-name-client": "^4.4.1", 29 | "command-line-interface": "^5.0.0", 30 | "did-resolver": "^4.1.0", 31 | "dotenv": "^16.4.5", 32 | "ethers": "^6.13.1" 33 | }, 34 | "devDependencies": { 35 | "@types/crypto-pouch": "^4.0.1", 36 | "@types/mocha": "^9.1.1", 37 | "@types/pouchdb": "^6.4.0", 38 | "mocha": "^8.2.1", 39 | "ts-mocha": "^8.0.0", 40 | "ts-node": "^9.1.1", 41 | "typescript": "^4.1.3" 42 | }, 43 | "gitHead": "" 44 | } 45 | -------------------------------------------------------------------------------- /packages/cli-tools/sample.env: -------------------------------------------------------------------------------- 1 | # Verida Private Key (used for sending inbox messages) 2 | privateVeridaKey="" 3 | # Blockchain Private Key (used for creating non-existent DIDs) 4 | privateBlockchainKey="" 5 | defaultContextName="Verida: CLI" -------------------------------------------------------------------------------- /packages/cli-tools/src/commands/get-account-info.ts: -------------------------------------------------------------------------------- 1 | import { Command } from 'command-line-interface'; 2 | import { GetAccountInfoOptions } from './interfaces'; 3 | import { AutoAccount } from '@verida/account-node'; 4 | import { Network } from '@verida/types'; 5 | import { Wallet } from '@verida/did-client'; 6 | import { DefaultNetworkBlockchainAnchors } from '@verida/vda-common'; 7 | import { NETWORK_STRINGS } from '../constants'; 8 | require('dotenv').config() 9 | 10 | export const GetAccountInfo: Command = { 11 | name: 'GetAccountInfo', 12 | description: 'Get the DID, Private key and Public key for a Verida Account.', 13 | optionDefinitions: [ 14 | { 15 | name: 'privateKey', 16 | description: 'Verida network private key (or seed phrase) of the sender', 17 | type: 'string', 18 | defaultValue: process.env.privateVeridaKey, 19 | alias: 'k' 20 | }, 21 | { 22 | name: 'network', 23 | description: 'Verida network (testnet, mainnet)', 24 | type: 'string', 25 | alias: 'n', 26 | defaultValue: 'myrtle', 27 | validate(val: string) { 28 | if (NETWORK_STRINGS.indexOf(val) === -1) { 29 | return false 30 | } 31 | } 32 | }, 33 | ], 34 | async handle ({ options }) { 35 | const network = options.network 36 | // Initialize Account 37 | const account = new AutoAccount({ 38 | privateKey: options.privateKey, 39 | network, 40 | didClientConfig: { 41 | callType: 'web3', 42 | web3Config: { 43 | // Set a dummy private key as we shouldn't need to create a DID automatically 44 | // The sending DID should already exist 45 | privateKey: process.env.privateBlockchainKey 46 | } 47 | } 48 | }) 49 | 50 | const did = await account.did() 51 | console.log(`DID: ${did}`) 52 | 53 | const blockchain = DefaultNetworkBlockchainAnchors[network] 54 | const wallet = new Wallet(options.privateKey, blockchain.toString()) 55 | console.log(`Wallet private key: ${wallet.privateKey}`) 56 | console.log(`Wallet public key: ${wallet.publicKey}`) 57 | } 58 | }; -------------------------------------------------------------------------------- /packages/cli-tools/src/commands/get-did-document.ts: -------------------------------------------------------------------------------- 1 | import { Command } from 'command-line-interface'; 2 | import { GetDIDDocumentOptions } from './interfaces'; 3 | import { getResolver } from '@verida/vda-did-resolver' 4 | import { Resolver } from 'did-resolver' 5 | import { DIDDocument } from '@verida/did-document' 6 | import { VeridaDocInterface } from '@verida/types' 7 | 8 | export const GetDIDDocument: Command = { 9 | name: 'GetDIDDocument', 10 | description: 'Get the DID Document for a Verida DID', 11 | optionDefinitions: [ 12 | { 13 | name: 'did', 14 | description: 'DID that should receive the inbox message', 15 | type: 'string', 16 | alias: 'd', 17 | }, 18 | ], 19 | 20 | async handle ({ options }) { 21 | const vdaDidResolver = getResolver() 22 | const didResolver = new Resolver(vdaDidResolver) 23 | const response = await didResolver.resolve(options.did) 24 | const didDocument = new DIDDocument( response.didDocument) 25 | 26 | // Output with pretty JSON formatting 27 | console.log(JSON.stringify(didDocument, null, 2)) 28 | } 29 | }; -------------------------------------------------------------------------------- /packages/cli-tools/src/commands/get-profile.ts: -------------------------------------------------------------------------------- 1 | import { Command } from 'command-line-interface'; 2 | import { GetProfileOptions } from './interfaces'; 3 | import { Network } from '@verida/types'; 4 | import { Client } from '@verida/client-ts'; 5 | require('dotenv').config() 6 | 7 | export const GetProfile: Command = { 8 | name: 'GetProfile', 9 | description: 'Get the public profile of a Verida Account', 10 | optionDefinitions: [ 11 | { 12 | name: 'did', 13 | description: 'Verida DID', 14 | type: 'string', 15 | alias: 'd' 16 | }, 17 | { 18 | name: 'contextName', 19 | type: 'string', 20 | defaultValue: 'Verida: Vault', 21 | alias: 'c' 22 | }, 23 | { 24 | name: 'profileName', 25 | type: 'string', 26 | defaultValue: 'basicProfile', 27 | alias: 'p' 28 | }, 29 | { 30 | name: 'fallbackContext', 31 | type: 'string', 32 | alias: 'f' 33 | }, 34 | { 35 | name: 'ignoreCache', 36 | type: 'boolean', 37 | defaultValue: false, 38 | alias: 'i' 39 | }, 40 | { 41 | name: 'networkFallback', 42 | type: 'boolean', 43 | defaultValue: false, 44 | alias: 'n' 45 | } 46 | ], 47 | async handle ({ options }) { 48 | let network: Network 49 | if (options.did.match('mainnet') || options.did.match('polpos')) { 50 | network = Network.MYRTLE 51 | } else { 52 | network = Network.BANKSIA 53 | } 54 | 55 | const client = new Client({ 56 | network, 57 | didClientConfig: { 58 | network 59 | }, 60 | }) 61 | 62 | const profile = await client.getPublicProfile( 63 | options.did, 64 | options.contextName, 65 | options.profileName, 66 | options.fallbackContext, 67 | options.ignoreCache, 68 | options.networkFallback 69 | ) 70 | console.log(`Profile located:`) 71 | console.log(profile) 72 | } 73 | }; -------------------------------------------------------------------------------- /packages/cli-tools/src/commands/interfaces.ts: -------------------------------------------------------------------------------- 1 | 2 | export interface SendInboxMessageOptions { 3 | did: string 4 | message: string 5 | network: string 6 | privateKey: string 7 | subject: string 8 | 9 | sendContext: string 10 | receiveContext: string 11 | } 12 | 13 | export interface GetDIDDocumentOptions { 14 | did: string 15 | } 16 | 17 | export interface GetAccountInfoOptions { 18 | network: string 19 | privateKey: string 20 | } 21 | 22 | export interface CreateAccountOptions { 23 | network: string 24 | saveDID: boolean 25 | } 26 | 27 | export interface GetProfileOptions { 28 | did: string 29 | contextName: string 30 | profileName: string 31 | fallbackContext: string 32 | ignoreCache: boolean 33 | networkFallback: boolean 34 | } 35 | 36 | export interface SetProfileOptions { 37 | privateKey: string 38 | contextName: string 39 | network: string 40 | storageNodes: string 41 | name: string 42 | description: string 43 | country: string 44 | } -------------------------------------------------------------------------------- /packages/cli-tools/src/constants.ts: -------------------------------------------------------------------------------- 1 | 2 | export const NETWORK_STRINGS = ['myrtle', 'banksia', 'devnet'] -------------------------------------------------------------------------------- /packages/cli-tools/src/exec.ts: -------------------------------------------------------------------------------- 1 | import { runCli } from 'command-line-interface' 2 | import { SendInboxMessage } from './commands/send-inbox-message' 3 | import { GetDIDDocument } from './commands/get-did-document' 4 | import { GetAccountInfo } from './commands/get-account-info' 5 | import { CreateAccount } from './commands/create-account' 6 | import { GetProfile } from './commands/get-profile' 7 | import { SetProfile } from './commands/set-profile' 8 | 9 | // eslint-disable-next-line @typescript-eslint/no-floating-promises 10 | (async (): Promise => { 11 | try { 12 | 13 | const RootCommand = { 14 | name: 'cli', 15 | description: 'Verida Command Line Interface', 16 | optionDefinitions: [], 17 | // @ts-ignore 18 | handle ({ getUsage, ancestors }) { 19 | console.log(getUsage( 20 | { commandPath: [ ...ancestors ] } 21 | )); 22 | }, 23 | subcommands: { 24 | GetDIDDocument, 25 | SendInboxMessage, 26 | GetAccountInfo, 27 | CreateAccount, 28 | GetProfile, 29 | SetProfile 30 | }, 31 | handlers: { 32 | // @ts-ignore 33 | commandUnknown ({ unknownCommandName, recommendedCommandName, ancestors }) { 34 | console.log('!!') 35 | console.log(unknownCommandName, recommendedCommandName, ancestors) 36 | }, 37 | } 38 | } 39 | 40 | await runCli({ rootCommand: RootCommand, argv: process.argv }); 41 | } catch (ex: unknown) { 42 | // eslint-disable-next-line no-console 43 | console.error({ ex }); 44 | } 45 | })() -------------------------------------------------------------------------------- /packages/cli-tools/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './commands/interfaces' -------------------------------------------------------------------------------- /packages/cli-tools/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "declaration": true, 6 | "skipLibCheck": true, // disable TS checking of dependencies 7 | "outDir": "./dist", 8 | "sourceMap": true, 9 | "strict": true, 10 | "lib": [ 11 | "es5", 12 | "es2015" 13 | ] 14 | }, 15 | "include": ["src"], 16 | "exclude": ["node_modules", "test", "dist"] 17 | } -------------------------------------------------------------------------------- /packages/client-ts/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | coverage 4 | api-docs 5 | dist 6 | lib 7 | yarn-error.log 8 | 9 | # Editor directories and files 10 | .idea 11 | .vscode 12 | *.suo 13 | *.ntvs* 14 | *.njsproj 15 | *.sln 16 | *.sw? 17 | 18 | /v*/ 19 | /test/config.local.ts -------------------------------------------------------------------------------- /packages/client-ts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@verida/client-ts", 3 | "version": "4.4.4", 4 | "main": "dist/index.js", 5 | "license": "ISC", 6 | "directories": { 7 | "src": "src", 8 | "test": "tests" 9 | }, 10 | "repository": "https://github.com/verida/verida-js.git", 11 | "scripts": { 12 | "tests": "ts-mocha './test/**/*.ts'", 13 | "test": "ts-mocha --timeout 100000", 14 | "build": "rm -rf dist; tsc" 15 | }, 16 | "engines": { 17 | "node": ">=18.0.0" 18 | }, 19 | "dependencies": { 20 | "@verida/account": "^4.4.4", 21 | "@verida/did-client": "^4.4.3", 22 | "@verida/did-document": "^4.4.2", 23 | "@verida/encryption-utils": "^4.0.1", 24 | "@verida/keyring": "^4.4.1", 25 | "@verida/storage-link": "^4.4.4", 26 | "@verida/types": "^4.4.1", 27 | "@verida/vda-common": "^4.4.1", 28 | "@verida/vda-name-client": "^4.4.1", 29 | "ajv": "^8.6.3", 30 | "ajv-formats": "^2.1.1", 31 | "axios": "^0.21.2", 32 | "bs58": "^4.0.1", 33 | "crypto-pouch": "git+https://github.com/tahpot/crypto-pouch.git#feature/support-key-import", 34 | "did-jwt": "5.7.0", 35 | "did-resolver": "^4.0.1", 36 | "json-schema-ref-parser": "^9.0.9", 37 | "json-schema-resolve-allof": "^1.5.0", 38 | "lodash": "^4.17.21", 39 | "pouchdb": "^9.0.0", 40 | "pouchdb-find": "^9.0.0", 41 | "uuid": "^8.3.2" 42 | }, 43 | "devDependencies": { 44 | "@types/crypto-pouch": "^4.0.1", 45 | "@types/mocha": "^9.1.1", 46 | "@types/pouchdb": "^6.4.0", 47 | "@types/uuid": "^8.3.4", 48 | "@verida/account-node": "^4.4.4", 49 | "dependency-cruiser": "^11.3.0", 50 | "mocha": "^8.2.1", 51 | "ts-mocha": "^8.0.0", 52 | "ts-node": "^9.1.1", 53 | "typescript": "^4.1.3" 54 | }, 55 | "gitHead": "2eb834ec3b626c0349f033f7da99faa7ed58f0d1" 56 | } 57 | -------------------------------------------------------------------------------- /packages/client-ts/src/config.ts: -------------------------------------------------------------------------------- 1 | import { DefaultClientConfig, Network } from "@verida/types" 2 | 3 | const config: DefaultClientConfig = { 4 | network: Network.BANKSIA, 5 | environments: { 6 | "local": { 7 | schemaPaths: { 8 | '/': 'https://schemas.verida.io/', 9 | 'https://schemas.verida.io/': 'https://schemas.testnet.verida.io/' 10 | //'https://schemas.verida.io/': 'http://localhost:5010/' 11 | } 12 | }, 13 | "banksia": { 14 | schemaPaths: { 15 | '/': 'https://schemas.verida.io/', 16 | 'https://schemas.verida.io/': 'https://schemas.testnet.verida.io/' 17 | }, 18 | readOnlyDataApiUri: 'https://data.verida.network' 19 | }, 20 | "myrtle": { 21 | schemaPaths: { 22 | '/': 'https://schemas.verida.io/' 23 | }, 24 | readOnlyDataApiUri: 'https://data.verida.network' 25 | }, 26 | }, 27 | vaultAppName: "Verida: Vault" 28 | } 29 | 30 | export default config 31 | -------------------------------------------------------------------------------- /packages/client-ts/src/context/engines/ContextNotFoundError.ts: -------------------------------------------------------------------------------- 1 | 2 | export default class ContextNotFoundError extends Error { 3 | constructor(message: string) { 4 | super(message) 5 | this.name = "ContextNotFoundError" 6 | } 7 | } -------------------------------------------------------------------------------- /packages/client-ts/src/context/engines/verida/database/db-public.ts: -------------------------------------------------------------------------------- 1 | import { DatabaseDeleteConfig, DbRegistryEntry } from "@verida/types"; 2 | import BaseDb from "./base-db"; 3 | 4 | /** 5 | * @category 6 | * Modules 7 | */ 8 | class PublicDatabase extends BaseDb { 9 | 10 | public async info(): Promise { 11 | await this.init(); 12 | 13 | const info = { 14 | type: "VeridaDatabase", 15 | privacy: "public", 16 | did: this.did, 17 | endpoint: this.endpoint.toString(), 18 | permissions: this.permissions!, 19 | storageContext: this.storageContext, 20 | databaseName: this.databaseName, 21 | databaseHash: this.databaseHash, 22 | }; 23 | 24 | return info; 25 | } 26 | 27 | public async registryEntry(): Promise { 28 | await this.init(); 29 | 30 | return { 31 | dbHash: this.databaseHash, 32 | dbName: this.databaseName, 33 | endpointType: "VeridaDatabase", 34 | did: this.did, 35 | contextName: this.storageContext, 36 | permissions: this.permissions!, 37 | endpoint: this.endpoint.toString() 38 | }; 39 | } 40 | 41 | public async destroy(options: DatabaseDeleteConfig = { 42 | localOnly: false 43 | }): Promise { 44 | if (!this.isOwner && !options.localOnly) { 45 | throw new Error(`Unable to update users for a database you don't own`) 46 | } 47 | 48 | if (options.localOnly) { 49 | return 50 | } 51 | 52 | await this.engine.deleteDatabase(this.databaseName) 53 | await this.close() 54 | } 55 | } 56 | 57 | export default PublicDatabase; 58 | -------------------------------------------------------------------------------- /packages/client-ts/src/context/engines/verida/database/interfaces.ts: -------------------------------------------------------------------------------- 1 | import { DatabasePermissionsConfig, IContext } from "@verida/types"; 2 | import Endpoint from "./endpoint"; 3 | 4 | /** 5 | * Interface for VeridaDatabaseConfig 6 | */ 7 | export interface VeridaDatabaseConfig { 8 | databaseName: string; 9 | did: string; 10 | storageContext: string; 11 | 12 | permissions?: DatabasePermissionsConfig; 13 | 14 | signData?: boolean; 15 | signContext: IContext; 16 | 17 | readOnly?: boolean; 18 | isOwner?: boolean; 19 | verifyEncryptionKey?: boolean; 20 | encryptionKey?: Buffer; 21 | 22 | saveDatabase: boolean; 23 | 24 | endpoint: Endpoint; 25 | 26 | plugins?: any[] 27 | } -------------------------------------------------------------------------------- /packages/client-ts/src/context/engines/verida/database/utils.ts: -------------------------------------------------------------------------------- 1 | import EncryptionUtils from '@verida/encryption-utils' 2 | 3 | /** 4 | * @category 5 | * Modules 6 | */ 7 | class Utils { 8 | static sleep(ms: number) { 9 | return new Promise((resolve) => setTimeout(resolve, ms)); 10 | } 11 | 12 | // DID + context name + DB Name + readPerm + writePerm 13 | static buildDatabaseHash(databaseName: string, contextName: string, did: string) { 14 | let text = [ 15 | did.toLowerCase(), 16 | contextName, 17 | databaseName, 18 | ].join("/"); 19 | 20 | const hash = EncryptionUtils.hash(text).substring(2); 21 | 22 | // Database name in CouchDB must start with a letter, so prepend a `v` 23 | return "v" + hash; 24 | } 25 | 26 | /** 27 | * Build an MD5 hash from an array 28 | * 29 | * @param {array} parts Array of components to build the hash 30 | */ 31 | /*static md5FromArray(parts: string[]) { 32 | let text = parts.join("/") 33 | return crypto.createHash('md5').update(text).digest("hex") 34 | }*/ 35 | } 36 | 37 | export default Utils; 38 | -------------------------------------------------------------------------------- /packages/client-ts/src/context/utils.ts: -------------------------------------------------------------------------------- 1 | import _ from "lodash"; 2 | import { DIDDocument } from "@verida/did-document"; 3 | import { Context } from ".."; 4 | import Schema from "./schema"; 5 | 6 | export interface RecordSignatureOptions { 7 | signContext: Context, 8 | } 9 | 10 | /** 11 | * Generates a signature for the given record 12 | */ 13 | export class RecordSignature { 14 | 15 | /** 16 | * Computes and returns the signature 17 | * 18 | * @param data Source of data required to generate the Signature 19 | * @param options required parameter 20 | */ 21 | public static async generateSignature(data: any, options: RecordSignatureOptions): Promise { 22 | const signContext = options.signContext; 23 | const signContextName = signContext.getContextName() 24 | const account = signContext.getAccount(); 25 | const signDid = await account.did(); 26 | const keyring = await account.keyring(signContextName); 27 | 28 | if (!data.signatures) { 29 | data.signatures = {}; 30 | } 31 | 32 | const signContextHash = DIDDocument.generateContextHash( 33 | signDid, 34 | signContextName 35 | ); 36 | const signKey = `${signDid}?context=${signContextHash}`; 37 | 38 | let _data = _.merge({}, data); 39 | 40 | // Don't include signatures or revision in the signature 41 | // Revision won't be generated until after the record is saved, so can't include in sig 42 | delete _data["signatures"]; 43 | delete _data["_rev"]; 44 | 45 | if (_data['schema']) { 46 | _data['schema'] = Schema.getVersionlessSchemaName(_data['schema']) 47 | } 48 | 49 | const sig = await keyring.sign(_data) 50 | 51 | // Create empty signature object if this DID hasn't signed, or if this DID has an old signature format (string, not object) 52 | if (!data.signatures[signKey.toLowerCase()] || typeof(data.signatures[signKey.toLowerCase()]) === 'string') { 53 | data.signatures[signKey.toLowerCase()] = {} 54 | } 55 | 56 | data.signatures[signKey.toLowerCase()]['secp256k1'] = sig; 57 | return data; 58 | } 59 | } 60 | 61 | export function getRandomInt(min: number, max: number) { 62 | min = Math.ceil(min); 63 | max = Math.floor(max); 64 | return Math.floor(Math.random() * (max - min) + min); // The maximum is exclusive and the minimum is inclusive 65 | } -------------------------------------------------------------------------------- /packages/client-ts/src/declarations.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'crypto-pouch' 2 | declare module 'pouchdb' 3 | declare module 'pouchdb-find' 4 | declare module 'uuid' -------------------------------------------------------------------------------- /packages/client-ts/src/index.ts: -------------------------------------------------------------------------------- 1 | import Client from './client' 2 | import Network from './network' 3 | import Context from './context/context' 4 | import { migrateContext, migrateDatabase } from './utils/migration' 5 | 6 | export { 7 | Client, 8 | Context, 9 | Network, 10 | migrateContext, 11 | migrateDatabase 12 | } -------------------------------------------------------------------------------- /packages/client-ts/src/network.ts: -------------------------------------------------------------------------------- 1 | import { BlockchainAnchor, ClientConfig, NetworkConnectionConfig, Network as VeridaNetwork } from "@verida/types"; 2 | import { Context } from "."; 3 | import Client from "./client"; 4 | import { decodeUri, fetchVeridaUri, explodeVeridaUri } from '@verida/helpers' 5 | 6 | /** 7 | * @category 8 | * Modules 9 | */ 10 | class Network { 11 | 12 | protected rpcUrls: Record = {} 13 | 14 | public setRpcUrls(rpcUrls: Record) { 15 | this.rpcUrls = rpcUrls 16 | } 17 | 18 | /** 19 | * Opens a new application context to provide encrypted storage and messaging to an application. 20 | * 21 | * This is a quicker alternative to generating a `client` connection to the Verida network 22 | * and then opening a context. 23 | * 24 | * @param config NetworkConnectionConfig Configuration 25 | * @returns {Context | undefined} If the user logs in a valid `Context` object is returned. If an unexpected error occurs or the user cancels the login attempt then nothing is returned. 26 | */ 27 | public async connect( 28 | config: NetworkConnectionConfig 29 | ): Promise { 30 | const client = new Client(config.client ? config.client : {}); 31 | await client.connect(config.account); 32 | 33 | try { 34 | const context = await client.openContext( 35 | config.context.name, 36 | config.context.forceCreate 37 | ); 38 | return context; 39 | } catch (err) { 40 | // User may have cancelled the login attempt 41 | return; 42 | } 43 | } 44 | 45 | public async getRecord(veridaUri: string, encoded: boolean = false) { 46 | if (encoded) { 47 | veridaUri = decodeUri(veridaUri) 48 | } 49 | 50 | const urlParts = explodeVeridaUri(veridaUri) 51 | const clientConfig: ClientConfig = { 52 | network: urlParts.network 53 | } 54 | 55 | // Set custom RPC URL if required 56 | for (const blockchain of Object.keys(this.rpcUrls)) { 57 | if (urlParts.did.match(blockchain)) { 58 | clientConfig.didClientConfig = { 59 | rpcUrl: this.rpcUrls[blockchain], 60 | blockchain: blockchain 61 | } 62 | break 63 | } 64 | } 65 | 66 | const client = new Client(clientConfig) 67 | const record = await fetchVeridaUri(veridaUri, client) 68 | return record 69 | } 70 | } 71 | 72 | export default new Network() 73 | -------------------------------------------------------------------------------- /packages/client-ts/test/client.contexthash.tests.ts: -------------------------------------------------------------------------------- 1 | const assert = require('assert') 2 | 3 | import { Client } from '../src/index' 4 | import { AutoAccount } from '@verida/account-node' 5 | import { StorageLink } from '@verida/storage-link' 6 | import { DIDDocument } from '@verida/did-document' 7 | import CONFIG from './config' 8 | import { EnvironmentType, IDatabase } from '@verida/types' 9 | 10 | const CONTEXT_NAME = 'Verida Storage Node Test: Test Application 1' 11 | 12 | const PRIVATE_KEY = '' 13 | 14 | let client, account, did 15 | 16 | /** 17 | * Test a single (or collection) of storage nodes 18 | */ 19 | describe.skip('Storage context hash tests', function() { 20 | 21 | this.beforeAll(async function() { 22 | client = new Client({ 23 | network: CONFIG.NETWORK, 24 | didClientConfig: { 25 | network: CONFIG.NETWORK, 26 | } 27 | }) 28 | 29 | account = new AutoAccount({ 30 | privateKey: PRIVATE_KEY, 31 | network: CONFIG.NETWORK, 32 | didClientConfig: CONFIG.DID_CLIENT_CONFIG 33 | }) 34 | 35 | await client.connect(account) 36 | did = await account.did() 37 | }) 38 | 39 | describe('Perform tests', () =>{ 40 | it('can fetch correct context name', async function () { 41 | const contextHash = DIDDocument.generateContextHash(did, CONTEXT_NAME); 42 | const contextName = await client.getContextNameFromHash(contextHash) 43 | assert.equal(contextName, CONTEXT_NAME, 'Context name matches expected value') 44 | }) 45 | 46 | it(`can't fetch incorrect context name`, async function () { 47 | const contextHash = '0xinvalidvalue'; 48 | 49 | try { 50 | await client.getContextNameFromHash(contextHash) 51 | assert.fail('Should have failed') 52 | } catch (err) { 53 | assert.equal(err.message, `Unable to locate service associated with context hash ${contextHash}`) 54 | } 55 | }) 56 | }) 57 | }) -------------------------------------------------------------------------------- /packages/client-ts/test/network.init.test.ts: -------------------------------------------------------------------------------- 1 | const assert = require('assert') 2 | 3 | import { Client } from '../src/index' 4 | import CONFIG from "./config" 5 | 6 | /** 7 | * 8 | */ 9 | describe('Network initialization tests', () => { 10 | describe('Initialize network connection', function() { 11 | 12 | it('can create a network instance', async function() { 13 | const network = new Client({ 14 | network: CONFIG.NETWORK 15 | }) 16 | assert.ok(network, 'Have a network instance') 17 | }) 18 | }) 19 | 20 | }) -------------------------------------------------------------------------------- /packages/client-ts/test/other/scratchpad.tests.ts: -------------------------------------------------------------------------------- 1 | const assert = require('assert') 2 | 3 | import { Client } from '../../src/index' 4 | import { AutoAccount } from '@verida/account-node' 5 | import CONFIG from '../config' 6 | import { Wallet } from 'ethers' 7 | import { Network } from '@verida/types' 8 | 9 | const NETWORK = Network.DEVNET 10 | const CONTEXT_NAME = 'Verida: Vault' 11 | const DB_NAME = '' 12 | 13 | const seedPhrase = `` 14 | 15 | /** 16 | * 17 | */ 18 | describe.skip('Verida basic database tests', () => { 19 | let context, did, account 20 | 21 | const network = new Client({ 22 | network: NETWORK, 23 | didClientConfig: { 24 | network: NETWORK, 25 | } 26 | }) 27 | 28 | describe('Open network connection', function() { 29 | this.timeout(600000) 30 | 31 | it('can connect and load DID', async function() { 32 | // Initialize account 1 33 | account = new AutoAccount({ 34 | privateKey: seedPhrase, 35 | network: NETWORK, 36 | didClientConfig: CONFIG.DID_CLIENT_CONFIG 37 | }) 38 | did = await account.did() 39 | console.log(did) 40 | await network.connect(account) 41 | }) 42 | 43 | it('can load DID doc', async function() { 44 | const didDoc = (await network.didClient.get(did)).export() 45 | console.log(didDoc) 46 | console.log(didDoc.service) 47 | }) 48 | 49 | it('can output all contexts', async function() { 50 | }) 51 | 52 | it('can output all databases for context', async function() { 53 | context = await network.openContext(CONTEXT_NAME, false) 54 | 55 | const database = await context.openDatabase('storage_database') 56 | const data = await database.getMany() 57 | for (let i in data) { 58 | console.log(data[i].dbName, data[i].dbHash, data[i].endpoint) 59 | } 60 | }) 61 | 62 | this.afterAll(async () => { 63 | if (context) { 64 | await context.close({ 65 | clearLocal: true 66 | }) 67 | } 68 | }) 69 | }) 70 | }) -------------------------------------------------------------------------------- /packages/client-ts/test/other/vault.tests.ts: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const assert = require('assert') 3 | 4 | import { Client } from '../../src/index' 5 | import { AutoAccount } from '@verida/account-node' 6 | import CONFIG from '../config' 7 | 8 | const VERIDA_CONTEXT_NAME = "Verida: Vault" 9 | 10 | /** 11 | * 12 | */ 13 | describe.skip('Basic vault tests', () => { 14 | 15 | describe('Test connecting', function() { 16 | this.timeout(60000) 17 | 18 | it('can open vault context', async function() { 19 | const client = new Client({ 20 | network: CONFIG.NETWORK, 21 | didClientConfig: { 22 | rpcUrl: CONFIG.DID_CLIENT_CONFIG.rpcUrl 23 | } 24 | }) 25 | 26 | const account = new AutoAccount( { 27 | privateKey: CONFIG.VDA_PRIVATE_KEY, 28 | network: CONFIG.NETWORK, 29 | didClientConfig: CONFIG.DID_CLIENT_CONFIG 30 | }) 31 | await client.connect(account) 32 | const context = client.openContext(VERIDA_CONTEXT_NAME, true) 33 | assert.ok(context, "Have a valid context") 34 | }) 35 | 36 | 37 | }) 38 | }) -------------------------------------------------------------------------------- /packages/client-ts/test/utils.ts: -------------------------------------------------------------------------------- 1 | import { Client } from '../src' 2 | 3 | export const assertIsValidDbResponse = function(assert: any, data: any) { 4 | assert.ok(data, 'Data returned') 5 | assert.ok(data.length && data.length > 0, 'Array returned with at least one row') 6 | // @todo: add seom helpful utilities to ensure resopnse is what is expected 7 | // assert.ok(data[0].hello == 'world', 'First result has expected value') 8 | } 9 | 10 | 11 | export const assertIsValidSignature = async function(assert: any, client: Client, did: string, data: any) { 12 | const validSignatures = await client.getValidDataSignatures(data, did) 13 | assert.ok(validSignatures.includes(did.toLowerCase()), 'DID is included in list of valid signatures') 14 | } 15 | 16 | export function sleep(ms) { 17 | return new Promise((resolve) => { 18 | setTimeout(resolve, ms); 19 | }); 20 | } -------------------------------------------------------------------------------- /packages/client-ts/test/verida/database.events.tests.ts: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const assert = require('assert') 3 | 4 | import { Client } from '../../src/index' 5 | import { AutoAccount } from '@verida/account-node' 6 | import CONFIG from '../config' 7 | 8 | const DB_NAME_OWNER = 'OwnerTestDb_1' 9 | 10 | /** 11 | * 12 | */ 13 | describe('Verida database tests', () => { 14 | let context, did1 15 | 16 | const network = new Client({ 17 | network: CONFIG.NETWORK, 18 | didClientConfig: { 19 | rpcUrl: CONFIG.DID_CLIENT_CONFIG.rpcUrl 20 | } 21 | }) 22 | 23 | describe('Manage databases for the authenticated user', function() { 24 | this.timeout(200000) 25 | 26 | it('can open a database with owner/owner permissions', async function() { 27 | // Initialize account 1 28 | const account1 = new AutoAccount({ 29 | privateKey: CONFIG.VDA_PRIVATE_KEY, 30 | network: CONFIG.NETWORK, 31 | didClientConfig: CONFIG.DID_CLIENT_CONFIG 32 | }) 33 | did1 = await account1.did() 34 | await network.connect(account1) 35 | context = await network.openContext(CONFIG.CONTEXT_NAME, true) 36 | const database = await context.openDatabase(DB_NAME_OWNER) 37 | 38 | const promise: Promise = new Promise((resolve, rejects) => { 39 | database.changes(function(info) { 40 | assert.ok(info, 'Info is supplied') 41 | resolve() 42 | }) 43 | 44 | database.save({'hello': 'world'}) 45 | }) 46 | }) 47 | 48 | this.afterAll(async () => { 49 | await context.close({ 50 | clearLocal: true 51 | }) 52 | }) 53 | }) 54 | 55 | }) -------------------------------------------------------------------------------- /packages/client-ts/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "declaration": true, 6 | "skipLibCheck": true, // disable TS checking of dependencies 7 | "outDir": "./dist", 8 | "sourceMap": true, 9 | "strict": true, 10 | "lib": [ 11 | "es5", 12 | "es2015" 13 | ], 14 | "allowSyntheticDefaultImports": true, 15 | "esModuleInterop": true 16 | }, 17 | "include": ["src"], 18 | "exclude": ["node_modules", "test", "dist"] 19 | } -------------------------------------------------------------------------------- /packages/did-client/.gitignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | node_modules/ -------------------------------------------------------------------------------- /packages/did-client/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2025-04-03 (v.4.4.3) 2 | ------------------- 3 | 4 | - Fix: Allow signer in web3config without private key 5 | 6 | 2024-07-15 (v.4.0.0) 7 | ------------------- 8 | 9 | - Support BlockchainAnchor and Verida Network refactor 10 | 11 | 2023-12-26 (v.3.0.0) 12 | ------------------- 13 | 14 | - Mainnet release 15 | - Feature: Make `web3config` auto-populate `RPC_URL` and other defaults based on Verida environment 16 | - Feature: Support easy method to destroy a DID 17 | 18 | 2023-04-20 (v2.3.0) 19 | ------------------- 20 | 21 | - Make `VeridaDIDDocument` and `@did-document/DIDDocument` usage clearer 22 | - Fix: Update tests to use updated devnet nodes 23 | 24 | 2023-03-27 (v2.2.1) 25 | ------------------- 26 | 27 | - Fix tests 28 | 29 | 2022-03-01 (v2.1.3) 30 | ------------------- 31 | 32 | - Support fetching RPC_URL for connected network 33 | 34 | 2023-02-09 (v2.0.5) 35 | ------------------- 36 | 37 | - Handle resolver now returning `didDocument` instead of `didDocument.doc` 38 | 39 | 2023-01-27 (v2.0.4) 40 | ------------------- 41 | 42 | - Remove engine restriction of Node 14 only 43 | 44 | 2023-01-24 (v2.0.2) 45 | ------------------- 46 | 47 | - Upgrade to @verida/types 48 | 49 | 2023-01-13 (v2.0.0) 50 | ------------------- 51 | 52 | - Support blockchain based DID lookup 53 | - Support blockchain read/write via native web3 or via Verida meta transaction server (via `@verida/web3-client`) 54 | - Support URL based DID document retrieval 55 | - Support multiple service endpoints 56 | 57 | 2022-03-10 (v0.1.8) 58 | ------------------- 59 | 60 | - Changes to support documentation generation 61 | 62 | 2022-02-27 (v0.1.7) 63 | ------------------- 64 | 65 | - Fix: Strip trailing slash if it exists on an endpointUrl -------------------------------------------------------------------------------- /packages/did-client/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/verida/verida-js/0b0fac80c35cece040f5266bb6ce480fd4d103cf/packages/did-client/README.md -------------------------------------------------------------------------------- /packages/did-client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@verida/did-client", 3 | "version": "4.4.3", 4 | "main": "dist/index.js", 5 | "license": "ISC", 6 | "directories": { 7 | "src": "src", 8 | "test": "tests" 9 | }, 10 | "repository": "https://github.com/verida/verida-js.git", 11 | "scripts": { 12 | "tests": "ts-mocha --timeout 500000 './test/**/*.ts'", 13 | "test": "ts-mocha --timeout 500000", 14 | "build": "rm -rf dist; tsc" 15 | }, 16 | "engines": { 17 | "node": ">=18.0.0" 18 | }, 19 | "dependencies": { 20 | "@verida/did-document": "^4.4.2", 21 | "@verida/types": "^4.4.1", 22 | "@verida/vda-common": "^4.4.1", 23 | "@verida/vda-did-resolver": "^4.4.2", 24 | "@verida/web3": "^4.4.1", 25 | "axios": "^0.23.0", 26 | "deepcopy": "^2.1.0", 27 | "did-resolver": "^4.0.1", 28 | "ethers": "^5.5.1" 29 | }, 30 | "devDependencies": { 31 | "dotenv": "^16.0.1", 32 | "mocha": "^8.2.1", 33 | "ts-mocha": "^8.0.0", 34 | "ts-node": "^9.1.1", 35 | "typescript": "^4.1.3" 36 | }, 37 | "gitHead": "2eb834ec3b626c0349f033f7da99faa7ed58f0d1" 38 | } 39 | -------------------------------------------------------------------------------- /packages/did-client/src/index.ts: -------------------------------------------------------------------------------- 1 | import { DIDClient } from "./did-client" 2 | import Wallet from "./wallet" 3 | 4 | export { 5 | DIDClient, 6 | Wallet 7 | } -------------------------------------------------------------------------------- /packages/did-client/src/wallet.ts: -------------------------------------------------------------------------------- 1 | import { utils, Wallet as EthersWallet } from "ethers" 2 | 3 | export default class Wallet { 4 | 5 | /* @ts-ignore */ 6 | private _did: string 7 | /* @ts-ignore */ 8 | private _publicKey: string 9 | /* @ts-ignore */ 10 | private _privateKey: string 11 | 12 | private _network: string 13 | 14 | public constructor(privateKey: string, network: string) { 15 | this._network = network 16 | this.load(privateKey) 17 | } 18 | 19 | public static createRandom(network: string = 'polpos') { 20 | const wallet = EthersWallet.createRandom() 21 | return new Wallet(wallet.privateKey, network) 22 | } 23 | 24 | private load(privateKey: string) { 25 | let wallet 26 | if (privateKey.substr(0,2) == "0x") { 27 | wallet = new EthersWallet(privateKey) 28 | } else { 29 | wallet = EthersWallet.fromMnemonic(privateKey) 30 | } 31 | 32 | this._did = `did:vda:${this._network}:${wallet.address}` 33 | this._privateKey = wallet.privateKey 34 | this._publicKey = wallet.publicKey 35 | } 36 | 37 | public get did(): string { 38 | return this._did 39 | } 40 | 41 | public get privateKey(): string { 42 | return this._privateKey 43 | } 44 | 45 | public get publicKey(): string { 46 | return this._publicKey 47 | } 48 | 49 | public get privateKeyBuffer(): Uint8Array { 50 | return Buffer.from(this._privateKey.substr(2), 'hex') 51 | } 52 | 53 | public get publicKeyBuffer(): Uint8Array { 54 | return Buffer.from(this._publicKey.substr(2), 'hex') 55 | } 56 | 57 | public get privateKeyBase58(): string { 58 | return utils.base58.encode(this._privateKey) 59 | } 60 | 61 | public get publicKeyBase58(): string { 62 | return utils.base58.encode(this._publicKey) 63 | } 64 | 65 | } -------------------------------------------------------------------------------- /packages/did-client/test/get.test.ts: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const assert = require('assert') 3 | import { DIDClient } from '@verida/did-client' 4 | import { BlockchainAnchor } from '@verida/types' 5 | const util = require('util') 6 | 7 | let didClient 8 | 9 | const DID = 'did:vda:polamoy:0x60e32de832d22ce242dbe0c64ffdc079f86c2b1f'.toLowerCase() 10 | 11 | /** 12 | * 13 | */ 14 | describe('DID GET document tests', () => { 15 | 16 | before(async () => { 17 | didClient = new DIDClient({ 18 | blockchain: BlockchainAnchor.POLAMOY 19 | }) 20 | }) 21 | 22 | describe('Document get', function() { 23 | it('can fetch an existing document', async function() { 24 | const doc = await didClient.get(DID) 25 | assert.ok(doc) 26 | assert.equal(doc.id, DID, 'Retreived document has matching DID') 27 | console.log(util.inspect(doc, {depth: 4})) 28 | }) 29 | }) 30 | 31 | }) 32 | -------------------------------------------------------------------------------- /packages/did-client/test/utils.ts: -------------------------------------------------------------------------------- 1 | import { DIDClient } from "../src/index" 2 | // import { Wallet } from '@ethersproject/wallet' 3 | import { Wallet } from "ethers" 4 | import { DIDClientConfig } from "@verida/types" 5 | 6 | require('dotenv').config() 7 | 8 | if (process.env.PRIVATE_KEY === undefined) { 9 | throw new Error('PRIVATE_KEY not defined in env') 10 | } 11 | const privateKey : string = process.env.PRIVATE_KEY! 12 | 13 | const rpcUrl = process.env[`RPC_URL`] 14 | if (rpcUrl === undefined) { 15 | throw new Error('RPC url is not defined in env') 16 | } 17 | console.log('RPC URL :', rpcUrl) 18 | 19 | export async function getDIDClient(veridaAccount: Wallet, didEndpoints: string[]) { 20 | const config: DIDClientConfig = { 21 | network: 'testnet', 22 | rpcUrl: rpcUrl! 23 | } 24 | 25 | const didClient = new DIDClient(config) 26 | 27 | // Configure authenticate to talk directly to the blockchain 28 | didClient.authenticate( 29 | veridaAccount.privateKey, // Verida DID private key 30 | 'web3', 31 | { 32 | privateKey, // MATIC private key that will submit transaction 33 | }, 34 | didEndpoints 35 | ) 36 | 37 | // Configure authenticate to use meta transaction server 38 | /*didClient.authenticate( 39 | veridaAccount.privateKey, // Verida DID private key 40 | 'gasless', 41 | { 42 | serverConfig: { 43 | headers: { 44 | 'context-name' : 'Verida Test' 45 | } 46 | }, 47 | postConfig: { 48 | headers: { 49 | 'user-agent': 'Verida-Vault' 50 | } 51 | }, 52 | endpointUrl: 'https://meta-tx-server1.tn.verida.tech' 53 | }, 54 | ['http://localhost:5000/did/'] 55 | ) 56 | */ 57 | 58 | return didClient 59 | } -------------------------------------------------------------------------------- /packages/did-client/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "declaration": true, 6 | "skipLibCheck": true, // disable TS checking of dependencies 7 | "outDir": "./dist", 8 | "sourceMap": true, 9 | "strict": true, 10 | "lib": [ 11 | "es5", 12 | "es2015" 13 | ] 14 | }, 15 | "include": ["src"], 16 | "exclude": ["node_modules", "test", "dist"] 17 | } -------------------------------------------------------------------------------- /packages/did-document/.gitignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | node_modules/ -------------------------------------------------------------------------------- /packages/did-document/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2024-01-16 (v4.4.1) 2 | ------------------- 3 | 4 | - Fix: Verification of context signature to correctly handle legacy mainnet DIDs 5 | 6 | 2024-07-15 (v.4.0.0) 7 | ------------------- 8 | 9 | - Support BlockchainAnchor and Verida Network refactor 10 | 11 | 2023-12-26 (v.3.0.0) 12 | ------------------- 13 | 14 | - Mainnet release 15 | - Add `devnet` as a known network 16 | 17 | 2023-02-16 (v2.1.1) 18 | ------------------- 19 | 20 | - Fix: Remove unecessary ethers dependency 21 | 22 | 2023-02-15 (v2.1.0) 23 | ------------------- 24 | 25 | - Fix: Gracefully handle signature verification where there are no signatures 26 | 27 | 2023-01-27 (v2.0.4) 28 | ------------------- 29 | 30 | - Remove engine restriction of Node 14 only 31 | 32 | 2023-01-24 (v2.0.2) 33 | ------------------- 34 | 35 | - Upgrade to @verida/types 36 | 37 | 2023-01-13 (v2.0.0) 38 | ------------------- 39 | 40 | - Support `verificationMethod` containing a proof the signing key is controlled by the DID Document `controller` to enable on-chain / off-chain verifications for a given context 41 | - Support helper method to locate context proof 42 | 43 | 2022-03-10 (v1.0.5) 44 | ------------------- 45 | 46 | - Changes to support documentation generation 47 | 48 | 2022-01-24 (1.0.4) 49 | ------------------- 50 | 51 | - Update @verida/did-document updated README.md -------------------------------------------------------------------------------- /packages/did-document/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@verida/did-document", 3 | "version": "4.4.2", 4 | "main": "dist/index.js", 5 | "license": "ISC", 6 | "directories": { 7 | "src": "src", 8 | "test": "tests" 9 | }, 10 | "repository": "https://github.com/verida/verida-js.git", 11 | "scripts": { 12 | "tests": "ts-mocha './test/**/*.ts'", 13 | "test": "ts-mocha", 14 | "build": "rm -rf dist; tsc" 15 | }, 16 | "engines": { 17 | "node": ">=18.0.0" 18 | }, 19 | "dependencies": { 20 | "@ethersproject/address": "^5.7.0", 21 | "@ethersproject/bignumber": "^5.7.0", 22 | "@ethersproject/transactions": "^5.7.0", 23 | "@verida/encryption-utils": "^4.0.1", 24 | "@verida/keyring": "^4.4.1", 25 | "@verida/types": "^4.4.1", 26 | "@verida/vda-common": "^4.4.1", 27 | "did-resolver": "^4.0.1", 28 | "lodash": "^4.17.21" 29 | }, 30 | "devDependencies": { 31 | "mocha": "^8.2.1", 32 | "ts-mocha": "^8.0.0", 33 | "ts-node": "^9.1.1", 34 | "typescript": "^4.1.3" 35 | }, 36 | "gitHead": "2eb834ec3b626c0349f033f7da99faa7ed58f0d1" 37 | } 38 | -------------------------------------------------------------------------------- /packages/did-document/src/helpers.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable prettier/prettier */ 2 | export function strip0x(input: string): string { 3 | return input.startsWith('0x') ? input.slice(2) : input 4 | } -------------------------------------------------------------------------------- /packages/did-document/src/index.ts: -------------------------------------------------------------------------------- 1 | import DIDDocument from "./did-document" 2 | 3 | export { 4 | DIDDocument 5 | } -------------------------------------------------------------------------------- /packages/did-document/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "declaration": true, 6 | "skipLibCheck": true, // disable TS checking of dependencies 7 | "outDir": "./dist", 8 | "strict": true, 9 | "sourceMap": true, 10 | "lib": [ 11 | "es5", 12 | "es2015" 13 | ] 14 | }, 15 | "include": ["src"], 16 | "exclude": ["node_modules", "test", "dist"] 17 | } -------------------------------------------------------------------------------- /packages/encryption-utils/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-env" 4 | ] 5 | } -------------------------------------------------------------------------------- /packages/encryption-utils/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | coverage 4 | apidocs 5 | dist 6 | lib 7 | yarn-error.log 8 | 9 | # Editor directories and files 10 | .idea 11 | .vscode 12 | *.suo 13 | *.ntvs* 14 | *.njsproj 15 | *.sln 16 | *.sw? 17 | 18 | -------------------------------------------------------------------------------- /packages/encryption-utils/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2024-07-15 (v.4.0.0) 2 | ------------------- 3 | 4 | - Support BlockchainAnchor and Verida Network refactor 5 | 6 | 2023-12-26 (v.3.0.0) 7 | ------------------- 8 | 9 | - Mainnet release 10 | - Fix JSON.sortify being global for the javascript runtime environment 11 | 12 | 2023-03-27 (v2.2.1) 13 | ------------------- 14 | 15 | - Fix tests 16 | 17 | 2022-03-01 (v2.1.3) 18 | ------------------- 19 | 20 | - Fix: Signing and verifying of data didn't correctly hash some raw data types 21 | 22 | 2023-01-27 (v2.0.4) 23 | ------------------- 24 | 25 | - Remove engine restriction of Node 14 only 26 | 27 | 2023-01-13 (v2.0.0) 28 | ------------------- 29 | 30 | - Improve support for JSON data so it can be verified on-chain 31 | 32 | 2022-03-10 (v1.1.3) 33 | ------------------- 34 | 35 | - Changes to support documentation generation 36 | 37 | 2020-09-13 (v0.2.0) 38 | ----------------------- 39 | 40 | - Add `sharedKey()` to support asym encrypt / decrypt 41 | - Add `randomKeyPair()` to support generating a new asym keypair 42 | - Add encode / decode Base64 helper methods 43 | - Update build process -------------------------------------------------------------------------------- /packages/encryption-utils/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/verida/verida-js/0b0fac80c35cece040f5266bb6ce480fd4d103cf/packages/encryption-utils/README.md -------------------------------------------------------------------------------- /packages/encryption-utils/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@verida/encryption-utils", 3 | "version": "4.0.1", 4 | "main": "dist/index.js", 5 | "license": "ISC", 6 | "directories": { 7 | "src": "src", 8 | "test": "tests" 9 | }, 10 | "repository": "https://github.com/verida/verida-js.git", 11 | "scripts": { 12 | "tests": "ts-mocha './test/**/*.ts'", 13 | "test": "ts-mocha './test/**/*.ts'", 14 | "build": "tsc" 15 | }, 16 | "engines": { 17 | "node": ">=18.0.0" 18 | }, 19 | "dependencies": { 20 | "ethers": "^5.5.1", 21 | "json.sortify": "^2.2.2", 22 | "tweetnacl": "^1.0.3", 23 | "tweetnacl-util": "^0.15.1" 24 | }, 25 | "devDependencies": { 26 | "mocha": "^8.2.1", 27 | "ts-mocha": "^8.0.0", 28 | "ts-node": "^9.1.1", 29 | "typescript": "^4.1.3" 30 | }, 31 | "gitHead": "2eb834ec3b626c0349f033f7da99faa7ed58f0d1" 32 | } 33 | -------------------------------------------------------------------------------- /packages/encryption-utils/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "declaration": true, 6 | "skipLibCheck": true, // disable TS checking of dependencies 7 | "outDir": "./dist", 8 | "strict": true, 9 | "sourceMap": true, 10 | "lib": [ 11 | "es5", 12 | "es2015" 13 | ] 14 | }, 15 | "include": ["src"], 16 | "exclude": ["node_modules", "test", "dist"] 17 | } -------------------------------------------------------------------------------- /packages/helpers/.gitignore: -------------------------------------------------------------------------------- 1 | #Ignore all files starting with "." 2 | .* 3 | !/.gitignore 4 | 5 | # node_modules in all sub directories 6 | **node_modules 7 | 8 | # build 9 | dist/ 10 | lib/ -------------------------------------------------------------------------------- /packages/helpers/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2024-07-15 (v.4.0.0) 2 | ------------------- 3 | 4 | - Support BlockchainAnchor and Verida Network refactor 5 | 6 | 2023-12-26 (v.3.0.0) 7 | ------------------- 8 | 9 | - Mainnet release 10 | - Support `verifyDidControlsDomain()` helper 11 | 12 | 2023-04-20 (v2.3.0) 13 | ------------------- 14 | 15 | - Fix: `wrapUri` didn't have `https` for default `wrapperUri` 16 | 17 | 2023-03-10 (v2.2.0) 18 | ------------------- 19 | 20 | - Support `wrapUri()` method 21 | - Fix: ExplodeVeridaUri regex breaking when there are no query params 22 | - Add explode DID helper method 23 | - Support deep attributes in Verida URIs 24 | - Add unit tests 25 | - Support `deepAttributes` in `buildVeridaUri()` 26 | - Unwrap `deepAttributes` in `fetchVeridaUri()` before attempting to decrypt 27 | 28 | 2023-02-16 (v2.1.1) 29 | ------------------- 30 | 31 | - First release -------------------------------------------------------------------------------- /packages/helpers/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Helpers 3 | 4 | Helper libraries for using the Verida network -------------------------------------------------------------------------------- /packages/helpers/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@verida/helpers", 3 | "version": "4.4.1", 4 | "main": "dist/index.js", 5 | "license": "ISC", 6 | "directories": { 7 | "src": "src", 8 | "test": "tests" 9 | }, 10 | "repository": "https://github.com/verida/verida-js.git", 11 | "scripts": { 12 | "build": "rm -rf dist/ && tsc", 13 | "tests": "ts-mocha './test/**/*.ts'", 14 | "test": "ts-mocha" 15 | }, 16 | "engines": { 17 | "node": ">=18.0.0" 18 | }, 19 | "dependencies": { 20 | "@verida/encryption-utils": "^4.0.1", 21 | "@verida/types": "^4.4.1", 22 | "axios": "^1.6.2", 23 | "bs58": "^5.0.0", 24 | "url": "^0.11.0" 25 | }, 26 | "devDependencies": { 27 | "mocha": "^8.2.1", 28 | "ts-mocha": "^8.0.0", 29 | "ts-node": "^9.1.1", 30 | "typescript": "^4.1.3" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/helpers/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./Utils" 2 | export * from "./verification" -------------------------------------------------------------------------------- /packages/helpers/src/verification.ts: -------------------------------------------------------------------------------- 1 | import Axios from 'axios' 2 | 3 | /** 4 | * Uses `/.well-known/did.json` standard 5 | * 6 | * @see https://w3c-ccg.github.io/did-method-web/ 7 | * @see https://team.verida.network/.well-known/did.json 8 | * 9 | * @param did DID that is expected to control the domain name 10 | * @param domain Domain (ie: team.verida.network) that is expected to be controlled by the DID. If protocol is specified (ie: `https`) it will automatically be stripped. HTTPS is forced. 11 | */ 12 | export async function verifyDidControlsDomain(did: string, domain: string): Promise { 13 | // Strip out protocol if specified 14 | domain = domain.replace(/^https?:\/\//, '') 15 | // Remove any trailing '/' 16 | domain = domain.replace(/\/$/,'') 17 | // Force SSL 18 | const didJsonUrl = `https://${domain}/.well-known/did.json` 19 | try { 20 | const response = await Axios.get(didJsonUrl) 21 | const didJson = response.data 22 | if (didJson.id !== `did:web:${domain}`) { 23 | return false 24 | } 25 | 26 | const match = didJson.verificationMethod!.find((entry: any) => { 27 | return ( 28 | // Verify authentication and entry ID match the domain 29 | entry.id.match(`did:web:${domain}`) && 30 | didJson.authentication.find((authEntry: any) => authEntry == entry.id) && 31 | // Verify the entry matches the DID 32 | entry.controller.toLowerCase().match(`${did.toLowerCase()}`) 33 | ) 34 | }) 35 | 36 | return match != undefined 37 | } catch (err) { 38 | return false 39 | } 40 | } -------------------------------------------------------------------------------- /packages/helpers/test/verification.test.ts: -------------------------------------------------------------------------------- 1 | const assert = require('assert') 2 | import { verifyDidControlsDomain } from '../src/index' 3 | 4 | const DID = 'did:vda:testnet:0x0Ece1EefE84d77951d6697558cba50774854b9E6' 5 | const DOMAIN = 'team.verida.network' 6 | const URI = 'http://team.verida.network' 7 | 8 | describe('Verification tests', () => { 9 | 10 | describe(`Verify domain ${DOMAIN}`, function() { 11 | it('can verify domain without slash', async () => { 12 | const result = await verifyDidControlsDomain(DID, DOMAIN) 13 | assert(result, 'Domain without slash verifies correctly ') 14 | }) 15 | 16 | it('can verify domain with slash', async () => { 17 | const result = await verifyDidControlsDomain(DID, `${DOMAIN}/`) 18 | assert(result, 'Domain with slash verifies correctly ') 19 | }) 20 | 21 | it('can verify domain from URI', async () => { 22 | const result = await verifyDidControlsDomain(DID, URI) 23 | assert(result, 'URI verifies correctly ') 24 | }) 25 | 26 | it('can verify with lower case DID', async () => { 27 | const result = await verifyDidControlsDomain(DID.toLowerCase(), DOMAIN) 28 | assert(result, 'Lower case DID verifies correctly ') 29 | }) 30 | 31 | }) 32 | }) -------------------------------------------------------------------------------- /packages/helpers/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "declaration": true, 6 | "skipLibCheck": true, // disable TS checking of dependencies 7 | "outDir": "./dist", 8 | "strict": true, 9 | "sourceMap": true, 10 | "lib": [ 11 | "es5", 12 | "dom" 13 | ] 14 | }, 15 | "include": ["src"], 16 | "exclude": ["node_modules", "test", "dist"] 17 | } -------------------------------------------------------------------------------- /packages/keyring/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | coverage 4 | apidocs 5 | dist 6 | lib 7 | yarn-error.log 8 | 9 | # Editor directories and files 10 | .idea 11 | .vscode 12 | *.suo 13 | *.ntvs* 14 | *.njsproj 15 | *.sln 16 | *.sw? 17 | 18 | -------------------------------------------------------------------------------- /packages/keyring/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2024-07-15 (v.4.0.0) 2 | ------------------- 3 | 4 | - Support BlockchainAnchor and Verida Network refactor 5 | 6 | 2023-12-26 (v.3.0.0) 7 | ------------------- 8 | 9 | - Mainnet release 10 | - Update to latest protocol dependencies 11 | 12 | 2023-03-10 (v2.2.0) 13 | ------------------- 14 | 15 | - Add hex versions of signing keys to `getKeys()` 16 | 17 | 2023-01-27 (v2.0.4) 18 | ------------------- 19 | 20 | - Remove engine restriction of Node 14 only 21 | 22 | 2023-01-24 (v2.0.2) 23 | ------------------- 24 | 25 | - Upgrade to @verida/types 26 | 27 | 2023-01-13 (v2.0.0) 28 | ------------------- 29 | 30 | - Support generating address representations of public keys 31 | 32 | 2022-03-10 (v1.1.3) 33 | ------------------- 34 | 35 | - Changes to support documentation generation -------------------------------------------------------------------------------- /packages/keyring/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Storage Keyring 3 | 4 | @todo -------------------------------------------------------------------------------- /packages/keyring/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@verida/keyring", 3 | "version": "4.4.1", 4 | "main": "dist/index.js", 5 | "license": "ISC", 6 | "directories": { 7 | "src": "src", 8 | "test": "tests" 9 | }, 10 | "repository": "https://github.com/verida/verida-js.git", 11 | "scripts": { 12 | "test": "ts-mocha './test/**/*.ts'", 13 | "build": "rm -rf dist; tsc" 14 | }, 15 | "engines": { 16 | "node": ">=18.0.0" 17 | }, 18 | "dependencies": { 19 | "@verida/encryption-utils": "^4.0.1", 20 | "@verida/types": "^4.4.1", 21 | "ethers": "^5.5.1", 22 | "tweetnacl": "^1.0.3", 23 | "uuid": "^8.3.2" 24 | }, 25 | "devDependencies": { 26 | "mocha": "^8.2.1", 27 | "ts-mocha": "^8.0.0", 28 | "ts-node": "^9.1.1", 29 | "typescript": "^4.1.3" 30 | }, 31 | "gitHead": "2eb834ec3b626c0349f033f7da99faa7ed58f0d1" 32 | } 33 | -------------------------------------------------------------------------------- /packages/keyring/src/index.ts: -------------------------------------------------------------------------------- 1 | import Keyring from './keyring' 2 | 3 | export { 4 | Keyring 5 | } -------------------------------------------------------------------------------- /packages/keyring/test/storage-keyring.test.ts: -------------------------------------------------------------------------------- 1 | // @todo: Migrate from datastore keyring test 2 | 3 | var assert = require("assert"); 4 | import { box } from "tweetnacl"; 5 | 6 | import Keyring from "../src/keyring"; 7 | 8 | describe("Keyring", function() { 9 | var keyring 10 | 11 | this.beforeAll(function() { 12 | const seedUint8 = new Uint8Array([37, 111, 93, 122, 134, 74, 12, 201, 10, 204, 68, 90, 213, 69, 150, 82, 163, 69, 157, 239, 64, 194, 140, 31, 144, 79, 225, 141, 74, 52, 70, 90]) 13 | const seed = '0x' + Buffer.from(seedUint8).toString('hex') 14 | keyring = new Keyring(seed) 15 | }); 16 | 17 | describe("Signing", function() { 18 | it("should generate a verified signature", async function() { 19 | let data = { 20 | "Margaret": "Hamilton" 21 | }; 22 | 23 | const sig = await keyring.sign(data) 24 | 25 | const verified = await keyring.verifySig(data, sig) 26 | 27 | assert(verified,true); 28 | }); 29 | }); 30 | 31 | describe("Symmetric encryption", function() { 32 | it("should symmetrically encrypt and decrypt", async function() { 33 | const data = { 34 | "Stephanie": "Shirley" 35 | }; 36 | 37 | const encryptedMessage = await keyring.symEncrypt(data); 38 | const decryptedMessage = await keyring.symDecrypt(encryptedMessage); 39 | 40 | assert.deepEqual(data, decryptedMessage); 41 | }); 42 | }); 43 | 44 | describe("Asymmetric encryption", function() { 45 | it("should assymetrically encrypt and decrypt a message with shared key", async function() { 46 | const data = { 47 | "Joan": "Clarke" 48 | }; 49 | 50 | // create a test key pair for a third party 51 | const otherKeyPair = box.keyPair(); 52 | 53 | // encrypt the data 54 | const sharedKeyStart = await keyring.buildSharedKeyStart(otherKeyPair.secretKey); 55 | const encrypted = await keyring.asymEncrypt(data, sharedKeyStart); 56 | 57 | // decrypt the data 58 | const sharedKeyEnd = await keyring.buildSharedKeyEnd(otherKeyPair.publicKey); 59 | const decrypted = await keyring.asymDecrypt(encrypted, sharedKeyEnd); 60 | 61 | assert.deepEqual(data, decrypted); 62 | }); 63 | }); 64 | }); -------------------------------------------------------------------------------- /packages/keyring/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "declaration": true, 6 | "skipLibCheck": true, // disable TS checking of dependencies 7 | "outDir": "./dist", 8 | "strict": true, 9 | "sourceMap": true, 10 | "lib": [ 11 | "es5", 12 | "es2015" 13 | ], 14 | "esModuleInterop": true 15 | }, 16 | "include": ["src"], 17 | "exclude": ["node_modules", "test", "dist"] 18 | } -------------------------------------------------------------------------------- /packages/storage-link/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | coverage 4 | apidocs 5 | dist 6 | lib 7 | yarn-error.log 8 | 9 | # Editor directories and files 10 | .idea 11 | .vscode 12 | *.suo 13 | *.ntvs* 14 | *.njsproj 15 | *.sln 16 | *.sw? 17 | 18 | -------------------------------------------------------------------------------- /packages/storage-link/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2024-07-15 (v.4.4.3) 2 | ------------------- 3 | 4 | - Fix: Mismatch of legacy DID in `StorageLink.getLinks()` 5 | 6 | 2024-07-15 (v.4.0.0) 7 | ------------------- 8 | 9 | - Support BlockchainAnchor and Verida Network refactor 10 | 11 | 2023-12-26 (v.3.0.0) 12 | ------------------- 13 | 14 | - Mainnet release 15 | - Update to latest protocol dependencies 16 | 17 | 2023-03-27 (v2.2.1) 18 | ------------------- 19 | 20 | - Fix tests 21 | 22 | 2023-01-27 (v2.0.4) 23 | ------------------- 24 | 25 | - Remove engine restriction of Node 14 only 26 | 27 | 2023-01-24 (v2.0.2) 28 | ------------------- 29 | 30 | - Upgrade to @verida/types 31 | 32 | 2023-01-13 (v2.0.0) 33 | ------------------- 34 | 35 | - Support blockchain enabled Verida DID Method 36 | - Support multiple endpoints per context 37 | 38 | 2022-03-10 (v1.1.8) 39 | ------------------- 40 | 41 | - Changes to support documentation generation 42 | 43 | 2022-02-27 (v1.1.7) 44 | ------------------- 45 | 46 | - Fix: Strip trailing slash if it exists on an endpointUrl -------------------------------------------------------------------------------- /packages/storage-link/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Storage Link 3 | 4 | Helper package that links Verida DID's to secure storage on the Verida network -------------------------------------------------------------------------------- /packages/storage-link/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@verida/storage-link", 3 | "version": "4.4.4", 4 | "main": "dist/index.js", 5 | "license": "ISC", 6 | "directories": { 7 | "src": "src", 8 | "test": "tests" 9 | }, 10 | "repository": "https://github.com/verida/verida-js.git", 11 | "scripts": { 12 | "tests": "ts-mocha './test/**/*.ts'", 13 | "test": "ts-mocha", 14 | "build": "rm -rf dist; tsc" 15 | }, 16 | "engines": { 17 | "node": ">=18.0.0" 18 | }, 19 | "dependencies": { 20 | "@verida/did-client": "^4.4.3", 21 | "@verida/did-document": "^4.4.2", 22 | "@verida/encryption-utils": "^4.0.1", 23 | "@verida/keyring": "^4.4.1", 24 | "did-resolver": "^4.0.0", 25 | "url-parse": "^1.5.3" 26 | }, 27 | "devDependencies": { 28 | "mocha": "^8.2.1", 29 | "ts-mocha": "^8.0.0", 30 | "ts-node": "^9.1.1", 31 | "typescript": "^4.1.3" 32 | }, 33 | "gitHead": "2eb834ec3b626c0349f033f7da99faa7ed58f0d1" 34 | } 35 | -------------------------------------------------------------------------------- /packages/storage-link/src/did-storage-config.ts: -------------------------------------------------------------------------------- 1 | import { SecureContextConfig, SecureContextServices } from "@verida/types" 2 | 3 | export default class DIDStorageConfig { 4 | 5 | /** 6 | * Generate a storage link for an existing DID 7 | * 8 | * @todo: Update `account` to specify `AccountInterface` (once moved into its own package) 9 | * 10 | * @param did 11 | * @param contextName 12 | */ 13 | static async generate(account: any, contextName: string, servicesConfig: SecureContextServices): Promise { 14 | const keyring = await account.keyring(contextName) 15 | const publicKeys = await keyring.publicKeys() 16 | 17 | const config: SecureContextConfig = { 18 | id: contextName, 19 | publicKeys: { 20 | asymKey: { 21 | type: 'Curve25519EncryptionPublicKey', 22 | publicKeyHex: publicKeys.asymPublicKeyHex 23 | }, 24 | signKey: { 25 | type: 'EcdsaSecp256k1VerificationKey2019', 26 | publicKeyHex: publicKeys.signPublicKeyHex 27 | } 28 | }, 29 | services: servicesConfig, 30 | isLegacyDid: false 31 | } 32 | 33 | return config 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /packages/storage-link/src/index.ts: -------------------------------------------------------------------------------- 1 | import StorageLink from './storage-link' 2 | import DIDStorageConfig from './did-storage-config' 3 | 4 | export { 5 | StorageLink, 6 | DIDStorageConfig 7 | } -------------------------------------------------------------------------------- /packages/storage-link/test/did.test.ts: -------------------------------------------------------------------------------- 1 | const assert = require('assert') 2 | import { StorageLink } from '../src/index' 3 | import { DIDClient } from '@verida/did-client' 4 | import { CONTEXT_NAME } from './utils' 5 | import { BlockchainAnchor, Network } from '@verida/types' 6 | require('dotenv').config() 7 | 8 | const NETWORK = Network.BANKSIA 9 | const BLOCKCHAIN = BlockchainAnchor.POLAMOY 10 | 11 | const MNEMONIC = "pumpkin salad also husband east armor online simple chair perfect used heavy" 12 | const didClient = new DIDClient({ 13 | blockchain: BLOCKCHAIN 14 | }) 15 | didClient.authenticate(MNEMONIC, 'web3', { 16 | privateKey: process.env.PRIVATE_KEY, 17 | rpcUrl: process.env.RPC_URL 18 | }, []) 19 | const DID = didClient.getDid() 20 | 21 | describe('Test storage links for a DID', () => { 22 | 23 | describe('Get links for an existing DID', function() { 24 | this.timeout(20000) 25 | 26 | it('can fetch all storage links', async function() { 27 | const storageLinks = await StorageLink.getLinks(NETWORK, didClient, DID) 28 | console.log(storageLinks) 29 | 30 | assert.ok(storageLinks, 'Got storage links') 31 | }) 32 | 33 | it('can fetch known storage link', async function() { 34 | const storageLink = await StorageLink.getLink(NETWORK, didClient, DID, CONTEXT_NAME) 35 | 36 | assert.ok(storageLink, 'Got storage link for the vault') 37 | }) 38 | 39 | it('service endpoints specify the correct network', async function() { 40 | const didDoc = await didClient.get(DID) 41 | const document = didDoc.export() 42 | 43 | document.service?.forEach((item: any) => { 44 | console.log(item.id.match(NETWORK.toString())) 45 | assert.ok(item.id.match(NETWORK.toString()), `Service endpoint specifies the correct network (${NETWORK.toString()})`) 46 | }) 47 | }) 48 | }) 49 | }) -------------------------------------------------------------------------------- /packages/storage-link/test/utils.ts: -------------------------------------------------------------------------------- 1 | import { DIDClient } from '@verida/did-client' 2 | 3 | import { Wallet } from "ethers" 4 | import { JsonRpcProvider } from '@ethersproject/providers' 5 | import { DIDClientConfig, BlockchainAnchor } from '@verida/types' 6 | 7 | require('dotenv').config() 8 | 9 | if (process.env.PRIVATE_KEY === undefined) { 10 | throw new Error('PRIVATE_KEY not defined in env') 11 | } 12 | const privateKey : string = process.env.PRIVATE_KEY! 13 | 14 | const rpcUrl = process.env[`RPC_URL`] 15 | if (rpcUrl === undefined) { 16 | throw new Error('RPC url is not defined in env') 17 | } 18 | console.log('RPC URL :', rpcUrl) 19 | 20 | const provider = new JsonRpcProvider(rpcUrl); 21 | const txSigner = new Wallet(privateKey, provider) 22 | 23 | export async function getDIDClient(veridaAccount: Wallet) { 24 | const config: DIDClientConfig = { 25 | blockchain: BlockchainAnchor.POLAMOY, 26 | rpcUrl 27 | } 28 | 29 | const didClient = new DIDClient(config) 30 | 31 | didClient.authenticate( 32 | veridaAccount.privateKey, 33 | 'web3', 34 | { 35 | privateKey 36 | }, 37 | ['https://node1-euw6.gcp.devnet.verida.tech/did/'] 38 | ) 39 | 40 | return didClient 41 | } 42 | 43 | export const CONTEXT_NAME = 'Test App' -------------------------------------------------------------------------------- /packages/storage-link/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "declaration": true, 6 | "skipLibCheck": true, // disable TS checking of dependencies 7 | "outDir": "./dist", 8 | "strict": true, 9 | "sourceMap": true, 10 | "lib": [ 11 | "es5", 12 | "es2015" 13 | ], 14 | "esModuleInterop": true 15 | }, 16 | "include": ["src"], 17 | "exclude": ["node_modules", "test", "dist"] 18 | } -------------------------------------------------------------------------------- /packages/types/.gitignore: -------------------------------------------------------------------------------- 1 | #Ignore all files starting with "." 2 | .* 3 | !/.gitignore 4 | 5 | # node_modules in all sub directories 6 | **node_modules 7 | 8 | # build 9 | dist/ 10 | lib/ 11 | build/ 12 | -------------------------------------------------------------------------------- /packages/types/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2024-07-15 (v.4.0.0) 2 | ------------------- 3 | - Removed `web3` parameter in `Web3SelfTransactionConfig` 4 | - Support BlockchainAnchor and Verida Network refactor 5 | 6 | 2023-12-26 (v.3.0.0) 7 | ------------------- 8 | 9 | - Mainnet release 10 | - Added types for `StorageNode` 11 | - Feature: Added EIP1559 gas configuration to `Web3Interface` 12 | - Make optional database params, actually optional with typescript 13 | 14 | 2023-04-20 (v2.3.0) 15 | ------------------- 16 | 17 | - Minor fixes to interfaces, making more method properties optional to match implementations 18 | - Add `devnet` network 19 | 20 | 2023-03-10 (v2.2.0) 21 | ------------------- 22 | 23 | - Update FetchUriParams to support `recordId` and `deepAttributes` 24 | 25 | 2022-03-01 (v2.1.3) 26 | ------------------- 27 | 28 | - Add `getRpcUrl()` to `IDIDClient` 29 | - Support `signer` on `VdaDidConfigurationOptions` 30 | 31 | 2023-02-16 (v2.1.1) 32 | ------------------- 33 | 34 | - Fix: Add `errors` property to schema interface 35 | 36 | 2023-02-09 (v2.0.5) 37 | ------------------- 38 | 39 | - Fix: Add missing dependencies 40 | 41 | 2023-01-27 (v2.0.4) 42 | ------------------- 43 | 44 | - Remove engine restriction of Node 14 only 45 | 46 | 2023-01-24 (v2.0.2) 47 | ------------------- 48 | 49 | - First release -------------------------------------------------------------------------------- /packages/types/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Verida protocol types 3 | 4 | ``` 5 | yarn add @types/verida 6 | ``` -------------------------------------------------------------------------------- /packages/types/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@verida/types", 3 | "version": "4.4.1", 4 | "description": "Typescript definitions for interfaces used in Verida", 5 | "main": "dist/index.js", 6 | "types": "dist/index.d.ts", 7 | "exports": { 8 | ".": "./dist/index.js" 9 | }, 10 | "files": [ 11 | "dist" 12 | ], 13 | "license": "ISC", 14 | "directories": { 15 | "src": "src", 16 | "test": "tests" 17 | }, 18 | "engines": { 19 | "node": ">=18.0.0" 20 | }, 21 | "repository": "https://github.com/verida/verida-js", 22 | "scripts": { 23 | "build": "rm -rf dist && tsc" 24 | }, 25 | "dependencies": { 26 | "@ethersproject/abstract-signer": "^5.7.0", 27 | "@ethersproject/bignumber": "^5.7.0", 28 | "@ethersproject/providers": "^5.7.2", 29 | "@types/node": "^18.15.11", 30 | "@types/pouchdb-core": "^7.0.11", 31 | "did-resolver": "^4.0.1", 32 | "tweetnacl": "^1.0.3" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/types/src/DocumentInterfaces.ts: -------------------------------------------------------------------------------- 1 | 2 | import { DIDDocument as DocInterface, ServiceEndpoint } from 'did-resolver' 3 | 4 | export interface SecureContextEndpoint { 5 | type: string; 6 | endpointUri: ServiceEndpoint[]; 7 | config?: object; 8 | } 9 | 10 | export interface SecureContextEndpoints { 11 | database: SecureContextEndpoint, 12 | messaging: SecureContextEndpoint, 13 | storage?: SecureContextEndpoint, 14 | notification?: SecureContextEndpoint, 15 | } 16 | 17 | export enum SecureContextEndpointType { 18 | DATABASE = 'database', 19 | MESSAGING = 'messaging', 20 | STORAGE = 'storage', 21 | NOTIFICATION = 'notification' 22 | } 23 | 24 | export interface DIDDocumentComparisonResult { 25 | controller?: string | string[]; 26 | add: DocInterface; 27 | remove: DocInterface; 28 | } 29 | 30 | export enum VerificationMethodTypes { 31 | EcdsaSecp256k1VerificationKey2019 = "EcdsaSecp256k1VerificationKey2019", 32 | EcdsaSecp256k1RecoveryMethod2020 = "EcdsaSecp256k1RecoveryMethod2020", 33 | Ed25519VerificationKey2018 = "Ed25519VerificationKey2018", 34 | RSAVerificationKey2018 = "RSAVerificationKey2018", 35 | X25519KeyAgreementKey2019 = "X25519KeyAgreementKey2019", 36 | } 37 | 38 | export interface ProofInterface { 39 | type: string 40 | verificationMethod: string 41 | proofPurpose: string 42 | proofValue: string 43 | } 44 | 45 | /* Replace service with our custom one that supports array of serviceEndpoint */ 46 | export interface VeridaDocInterface extends DocInterface { 47 | versionId: number 48 | created?: string 49 | updated?: string 50 | deactivated?: string 51 | proof?: ProofInterface 52 | } -------------------------------------------------------------------------------- /packages/types/src/IAccount.ts: -------------------------------------------------------------------------------- 1 | import { AccountConfig, AuthContext, AuthTypeConfig } from './AccountInterfaces' 2 | import { IDIDClient } from './IDIDClient' 3 | import { IKeyring } from './IKeyring' 4 | import { SecureContextConfig } from './StorageLinkInterfaces' 5 | 6 | export interface IAccount { 7 | 8 | keyring(contextName: string): Promise 9 | 10 | sign(input: string): Promise 11 | 12 | did(): Promise 13 | 14 | linkStorage(storageConfig: SecureContextConfig): Promise 15 | 16 | unlinkStorage(contextName: string): Promise 17 | 18 | storageConfig(contextName: string, forceCreate: boolean): Promise 19 | 20 | linkStorageContextService(contextName: string, endpointType: string, serverType: string, endpointUris: string[]): Promise 21 | 22 | setAccountConfig(accountConfig: AccountConfig): void 23 | 24 | createDidJwt(contextName: string, data: object, config: any): Promise 25 | 26 | disconnect(contextName?: string): Promise 27 | 28 | getAuthContext(contextName: string, contextConfig: SecureContextConfig, authConfig?: AuthTypeConfig, authType?: string): Promise 29 | 30 | disconnectDevice(contextName: string, deviceId: string): Promise 31 | } -------------------------------------------------------------------------------- /packages/types/src/IAuthType.ts: -------------------------------------------------------------------------------- 1 | import { AuthContext, AuthTypeConfig } from "./AccountInterfaces" 2 | 3 | export interface IAuthType { 4 | getAuthContext(config: AuthTypeConfig): Promise 5 | 6 | setAuthContext(contextAuth: AuthContext): void 7 | 8 | disconnectDevice(deviceId: string): Promise 9 | } -------------------------------------------------------------------------------- /packages/types/src/IClient.ts: -------------------------------------------------------------------------------- 1 | import { IAccount } from "./IAccount"; 2 | import { IContext } from "./IContext"; 3 | import { IProfile } from "./IProfile"; 4 | import { ISchema } from "./ISchema"; 5 | import { Network } from "./NetworkInterfaces"; 6 | import { SecureContextConfig } from "./StorageLinkInterfaces"; 7 | 8 | export interface IClient { 9 | connect(account: IAccount): Promise 10 | 11 | isConnected(): void 12 | 13 | getNetwork(): Network 14 | 15 | openContext( 16 | contextName: string, 17 | forceCreate: boolean 18 | ): Promise 19 | 20 | openExternalContext(contextName: string, did: string): Promise 21 | 22 | getContextConfig( 23 | did: string, 24 | contextName: string 25 | ): Promise 26 | 27 | openPublicProfile( 28 | did: string, 29 | contextName: string, 30 | profileName: string, 31 | fallbackContext: string | null 32 | ): Promise 33 | 34 | getValidDataSignatures( 35 | data: any, 36 | did?: string 37 | ): Promise 38 | 39 | getSchema(schemaUri: string): Promise 40 | } -------------------------------------------------------------------------------- /packages/types/src/IContext.ts: -------------------------------------------------------------------------------- 1 | import { AuthContext, AuthTypeConfig } from "./AccountInterfaces"; 2 | import { ContextCloseOptions, ContextEngineType, ContextInfo, DatabaseOpenConfig, DatastoreOpenConfig, MessagesConfig } from "./ContextInterfaces"; 3 | import { IStorageEngine } from "./IStorageEngine"; 4 | import { IClient } from "./IClient"; 5 | import { IDatabase } from "./IDatabase"; 6 | import { IDatastore } from "./IDatastore"; 7 | import { IDIDContextManager } from "./IDIDContextManager"; 8 | import { SecureContextConfig } from "./StorageLinkInterfaces"; 9 | import { IAccount } from "./IAccount"; 10 | import { IProfile } from "./IProfile"; 11 | import { IMessaging } from "./IMessaging"; 12 | import { INotification } from "./INotification"; 13 | import { IDbRegistry } from "./IDbRegistry"; 14 | 15 | export interface IContext { 16 | getContextConfig( 17 | did?: string, 18 | forceCreate?: boolean, 19 | customContextName?: string 20 | ): Promise 21 | 22 | getContextName(): string 23 | 24 | getAccount(): IAccount 25 | 26 | getDidContextManager(): IDIDContextManager 27 | 28 | getClient(): IClient 29 | 30 | disconnect(): Promise 31 | 32 | getDatabaseEngine( 33 | did: string, 34 | createContext?: boolean 35 | ): Promise 36 | 37 | getMessaging(messageConfig: MessagesConfig): Promise 38 | 39 | getNotification(did: string, contextName: string): Promise 40 | 41 | openProfile( 42 | profileName?: string, 43 | did?: string 44 | ): Promise 45 | 46 | openDatabase( 47 | databaseName: string, 48 | config?: DatabaseOpenConfig 49 | ): Promise 50 | 51 | 52 | openExternalDatabase( 53 | databaseName: string, 54 | did: string, 55 | config?: DatabaseOpenConfig 56 | ): Promise 57 | 58 | 59 | openDatastore( 60 | schemaUri: string, 61 | config?: DatastoreOpenConfig 62 | ): Promise 63 | 64 | 65 | openExternalDatastore( 66 | schemaUri: string, 67 | did: string, 68 | options?: DatastoreOpenConfig 69 | ): Promise 70 | 71 | getDbRegistry(): IDbRegistry 72 | 73 | info(): Promise 74 | 75 | getAuthContext(authConfig?: AuthTypeConfig, authType?: string): Promise 76 | 77 | addEndpoint(engineType: ContextEngineType, endpointUri: string): void 78 | 79 | close(options?: ContextCloseOptions): Promise 80 | 81 | clearDatabaseCache(did: string, databaseName: string): Promise 82 | 83 | } 84 | -------------------------------------------------------------------------------- /packages/types/src/IDIDClient.ts: -------------------------------------------------------------------------------- 1 | import { IDIDDocument } from "./IDIDDocument"; 2 | import { Web3CallType, Web3MetaTransactionConfig, Web3SelfTransactionConfigPart, VdaDidEndpointResponses } from "./Web3Interfaces"; 3 | 4 | 5 | export interface IDIDClient { 6 | authenticate( 7 | veridaPrivateKey: string, 8 | callType: Web3CallType, 9 | web3Config: Web3SelfTransactionConfigPart | Web3MetaTransactionConfig, 10 | defaultEndpoints: string[] 11 | ): void 12 | 13 | authenticated(): boolean 14 | 15 | getDid(): string | undefined 16 | 17 | getPublicKey(): string | undefined 18 | 19 | save(document: IDIDDocument): Promise 20 | 21 | getLastEndpointErrors(): VdaDidEndpointResponses 22 | 23 | get(did: string): Promise 24 | 25 | getRpcUrl(): string 26 | } -------------------------------------------------------------------------------- /packages/types/src/IDIDContextManager.ts: -------------------------------------------------------------------------------- 1 | import { SecureContextEndpoint } from "./DocumentInterfaces"; 2 | import { IAccount } from "./IAccount"; 3 | import { IDIDClient } from "./IDIDClient"; 4 | import { SecureContextConfig } from "./StorageLinkInterfaces"; 5 | 6 | export interface IDIDContextManager { 7 | setAccount(account: IAccount): void 8 | 9 | getContextDatabaseServer( 10 | did: string, 11 | contextName: string, 12 | forceCreate: boolean 13 | ): Promise 14 | 15 | getContextStorageServer( 16 | did: string, 17 | contextName: string, 18 | forceCreate: boolean 19 | ): Promise 20 | 21 | getContextMessageServer( 22 | did: string, 23 | contextName: string, 24 | forceCreate: boolean 25 | ): Promise 26 | 27 | getDIDContextHashConfig(did: string, contextHash: string): Promise 28 | 29 | getDIDContextConfig( 30 | did: string, 31 | contextName: string, 32 | forceCreate?: boolean 33 | ): Promise 34 | } 35 | 36 | -------------------------------------------------------------------------------- /packages/types/src/IDIDDocument.ts: -------------------------------------------------------------------------------- 1 | import { ServiceEndpoint, Service } from 'did-resolver' 2 | import { SecureContextEndpoints, SecureContextEndpointType, VeridaDocInterface } from "./DocumentInterfaces" 3 | import { IKeyring } from './IKeyring' 4 | import { Network } from './NetworkInterfaces' 5 | 6 | export interface IDIDDocument { 7 | get id(): string 8 | 9 | getErrors(): string[] 10 | 11 | addContext(network: Network, contextName: string, keyring: IKeyring, privateKey: string, endpoints: SecureContextEndpoints): Promise 12 | 13 | removeContext(contextName: string, network?: Network): boolean 14 | 15 | setAttributes(attributes: Record): void 16 | 17 | import(doc: VeridaDocInterface): void 18 | 19 | export(): VeridaDocInterface 20 | 21 | addContextService(network: Network, contextHash: string, endpointType: SecureContextEndpointType, serviceType: string, endpointUris: ServiceEndpoint[]): void 22 | 23 | addContextSignKey(network: Network, contextHash: string, publicKeyHex: string, proof: string): void 24 | 25 | addContextAsymKey(network: Network, contextHash: string, publicKeyHex: string): void 26 | 27 | verifySig(data: any, signature: string): boolean 28 | 29 | verifyContextSignature(data: any, network: Network, contextName: string, signature: string, contextIsHash: boolean): boolean 30 | 31 | locateServiceEndpoint(contextName: string, endpointType: SecureContextEndpointType, network?: Network): Service | undefined 32 | 33 | locateContextProof(contextName: string, network: Network): string | undefined 34 | 35 | signProof(privateKey: Uint8Array | string): void 36 | 37 | verifyProof(): boolean 38 | 39 | buildTimestamp(date: Date): string 40 | } -------------------------------------------------------------------------------- /packages/types/src/IDatabase.ts: -------------------------------------------------------------------------------- 1 | import { DatabaseCloseOptions, DatabaseDeleteConfig, DbRegistryEntry, EndpointUsage } from "./ContextInterfaces" 2 | 3 | /** 4 | * Interface for any database returned from a storage engine 5 | */ 6 | export interface IDatabase { 7 | save(data: any, options?: any): Promise 8 | 9 | getMany(filter?: any, options?: any): Promise 10 | 11 | get(docId: any, options?: any): Promise 12 | 13 | delete(doc: any, options?: any): Promise 14 | 15 | deleteAll(): Promise 16 | 17 | changes(cb: Function, options?: any): Promise 18 | 19 | updateUsers(readList: string[], writeList: string[]): Promise 20 | 21 | getDb(): Promise 22 | 23 | info(): Promise 24 | 25 | registryEntry(): Promise 26 | 27 | close(options?: DatabaseCloseOptions): Promise 28 | 29 | destroy(options?: DatabaseDeleteConfig): Promise 30 | 31 | usage(): Promise 32 | } -------------------------------------------------------------------------------- /packages/types/src/IDatastore.ts: -------------------------------------------------------------------------------- 1 | import { DatabaseCloseOptions, DatastoreOpenConfig } from "./ContextInterfaces" 2 | import { IContext } from "./IContext" 3 | import { IDatabase } from "./IDatabase" 4 | import { ISchema } from "./ISchema" 5 | 6 | export interface IDatastore { 7 | errors: any 8 | 9 | save(data: any, options: any): Promise 10 | 11 | getMany( 12 | customFilter?: any, 13 | options?: any 14 | ): Promise 15 | 16 | getOne( 17 | customFilter?: any, 18 | options?: any 19 | ): Promise 20 | 21 | get(key: string, options: any): Promise 22 | 23 | delete(docId: string): Promise 24 | 25 | deleteAll(): Promise 26 | 27 | getDb(): Promise 28 | 29 | changes(cb: any, options: any): Promise 30 | 31 | ensureIndexes(indexes: any): Promise 32 | 33 | updateUsers( 34 | readList: string[], 35 | writeList: string[] 36 | ): Promise 37 | 38 | close(options?: DatabaseCloseOptions): Promise 39 | 40 | getSchema(): ISchema 41 | } -------------------------------------------------------------------------------- /packages/types/src/IDbRegistry.ts: -------------------------------------------------------------------------------- 1 | import { IContext } from "./IContext" 2 | import { IDatabase } from "./IDatabase" 3 | 4 | export interface IDbRegistry { 5 | saveDb(database: IDatabase, checkPermissions: boolean): Promise 6 | 7 | removeDb(databaseName: string, did: string, contextName: string): Promise 8 | 9 | getMany(filter: any, options: any): Promise 10 | 11 | get( 12 | dbName: string, 13 | did: string, 14 | contextName: string 15 | ): Promise 16 | 17 | init(): Promise 18 | } -------------------------------------------------------------------------------- /packages/types/src/IKeyring.ts: -------------------------------------------------------------------------------- 1 | 2 | export interface IKeyring { 3 | getKeys(): Promise 4 | 5 | _init(): Promise 6 | 7 | publicKeys(): Promise 8 | 9 | sign(data: any): Promise 10 | 11 | verifySig(data: string, sig: string): Promise 12 | 13 | symEncrypt(data: string): Promise 14 | 15 | symDecrypt(data: string): Promise 16 | 17 | asymEncrypt(data: string, secretOrSharedKey: Uint8Array): Promise 18 | 19 | asymDecrypt(messageWithNonce: string, secretOrSharedKey: Uint8Array): Promise 20 | 21 | buildSharedKeyStart(privateKey: Uint8Array): Promise 22 | 23 | buildSharedKeyEnd(publicKey: Uint8Array): Promise 24 | 25 | getSeed(): string 26 | 27 | getStorageContextKey(databaseName: string): Promise 28 | } 29 | 30 | export interface KeyringPublicKeys { 31 | asymPublicKey: Uint8Array 32 | asymPublicKeyHex: string 33 | asymPublicKeyBase58: string 34 | signPublicKey: Uint8Array 35 | signPublicKeyHex: string 36 | signPublicKeyBase58: string 37 | } 38 | 39 | export enum KeyringKeyType { 40 | SIGN = 'sign', 41 | ASYM = 'asym', 42 | SYM = 'sym' 43 | } -------------------------------------------------------------------------------- /packages/types/src/IMessaging.ts: -------------------------------------------------------------------------------- 1 | import { EventEmitter } from 'events' 2 | import { MessageSendConfig } from "./ContextInterfaces"; 3 | import { IAccount } from "./IAccount"; 4 | 5 | /** 6 | * Interface Messaging 7 | */ 8 | export interface IMessaging { 9 | init(): Promise 10 | 11 | /** 12 | * Send a message to another DID on the network. 13 | * 14 | * @todo: Link to documentation 15 | * 16 | * @param did string DID to receive the message 17 | * @param type string Type of inbox message (See https://github.com/verida/schemas/tree/master/schemas/inbox/type). ie: `dataSend` 18 | * @param data object Data to send. Structure of data will depend on the inbox message type. 19 | * @param message string A human readable message that will be displayed to the user upon receipt of the message. Similar to an email subject. 20 | * @param config object Optional configuration. 21 | */ 22 | send( 23 | did: string, 24 | type: string, 25 | data: object, 26 | message: string, 27 | config: MessageSendConfig 28 | ): Promise; 29 | 30 | /** 31 | * Register a callback to fire when a new message is received from another DID or application. 32 | * 33 | * Usage: 34 | * 35 | * ``` 36 | * // configure the listener 37 | * const callback = (msg) => { console.log(msg) } 38 | * const emitter = messaging.onMessage(callback) 39 | * ``` 40 | * 41 | * @return {Promise} Returns an event emitter 42 | */ 43 | onMessage(callback: any): Promise; 44 | 45 | /** 46 | * Unregister a callback to fire when a new message is received 47 | * 48 | * @param callback 49 | */ 50 | offMessage(callback: any): Promise; 51 | 52 | /** 53 | * Get messages from this inbox. 54 | * 55 | * @param filter object An optional datastore filter 56 | * @param options object An optional list of datastore options 57 | */ 58 | getMessages(filter?: object, options?: any): Promise; 59 | 60 | /** 61 | * Get the underlying inbox instance specific for the message storage type. 62 | * 63 | * @returns any Currently returns a `Datastore` instance. 64 | */ 65 | getInbox(): Promise; 66 | 67 | /** 68 | * Connect an account to this messaging instance. 69 | * 70 | * Used internally. 71 | * 72 | * @param account Account 73 | */ 74 | connectAccount(account: IAccount): Promise; 75 | } 76 | -------------------------------------------------------------------------------- /packages/types/src/INotification.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Interface for notifications 3 | */ 4 | export interface INotification { 5 | 6 | /** 7 | * Initialize notifications for the connected user 8 | * 9 | * (ie; connect to a notification server) 10 | */ 11 | init(): Promise 12 | 13 | /** 14 | * Ping a notification server to fetch new messages 15 | * TODO: Change this 16 | */ 17 | ping(recipientContextName :string, didToNotify: any): Promise 18 | 19 | getErrors(): string[] 20 | 21 | } -------------------------------------------------------------------------------- /packages/types/src/IProfile.ts: -------------------------------------------------------------------------------- 1 | import { IDatastore } from "./IDatastore"; 2 | 3 | export interface ProfileDocument { 4 | _id: string; 5 | [key: string]: string; 6 | } 7 | 8 | export interface IProfile { 9 | get( 10 | key: string, 11 | options?: any, 12 | extended?: boolean 13 | ): Promise 14 | 15 | delete(key: string): Promise 16 | 17 | getMany(filter: any, options: any): Promise 18 | 19 | set(key: string, value: any): Promise 20 | 21 | setMany(data: any): Promise 22 | 23 | listen(callback: any): Promise 24 | 25 | getDs(): Promise 26 | 27 | getErrors(): Promise 28 | } 29 | -------------------------------------------------------------------------------- /packages/types/src/ISchema.ts: -------------------------------------------------------------------------------- 1 | 2 | export interface ISchema { 3 | errors: string[] 4 | 5 | getSpecification(): Promise 6 | 7 | validate(data: any): Promise 8 | 9 | getSchemaJson(): Promise 10 | 11 | getAppearance(): Promise 12 | } -------------------------------------------------------------------------------- /packages/types/src/IStorageEngine.ts: -------------------------------------------------------------------------------- 1 | import { ContextDatabaseInfo, DatabaseDeleteConfig, DatabaseOpenConfig, DatastoreOpenConfig } from "./ContextInterfaces" 2 | import { IAccount } from "./IAccount" 3 | import { IContext } from "./IContext" 4 | import { IDatabase } from "./IDatabase" 5 | import { IDatastore } from "./IDatastore" 6 | import { IDbRegistry } from "./IDbRegistry" 7 | import { IKeyring } from "./IKeyring" 8 | import { SecureContextConfig } from "./StorageLinkInterfaces" 9 | 10 | /** 11 | * @emits EndpointUnavailable 12 | */ 13 | export interface IStorageEngine { 14 | getKeyring(): IKeyring 15 | 16 | getContextConfig(): SecureContextConfig 17 | 18 | getAccount(): IAccount 19 | 20 | connectAccount(account: IAccount): Promise 21 | 22 | getDbRegistry(): IDbRegistry 23 | 24 | openDatabase( 25 | databaseName: string, 26 | config: DatabaseOpenConfig 27 | ): Promise 28 | 29 | openDatastore( 30 | schemaName: string, 31 | config: DatastoreOpenConfig 32 | ): Promise 33 | 34 | deleteDatabase( 35 | databaseName: string, 36 | config?: DatabaseDeleteConfig 37 | ): Promise 38 | 39 | logout(): void 40 | 41 | addEndpoint(context: IContext, uri: string): Promise 42 | 43 | info(): Promise 44 | } -------------------------------------------------------------------------------- /packages/types/src/IStorageNode.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Status of StoargeNode and DataCentre 4 | * Used in `vda-node-manager` and `vda-node-client` packages 5 | */ 6 | export enum EnumStatus { 7 | removed = 0, 8 | removing, 9 | active 10 | } -------------------------------------------------------------------------------- /packages/types/src/StorageLinkInterfaces.ts: -------------------------------------------------------------------------------- 1 | import { SecureContextEndpoint } from "./DocumentInterfaces" 2 | 3 | export interface SecureContextPublicKey { 4 | type: string, 5 | publicKeyHex: string 6 | } 7 | 8 | export interface SecureStorageContextPublicKeys { 9 | asymKey: SecureContextPublicKey, 10 | signKey: SecureContextPublicKey, 11 | } 12 | 13 | export interface SecureContextServices { 14 | databaseServer: SecureContextEndpoint, 15 | messageServer: SecureContextEndpoint, 16 | storageServer?: SecureContextEndpoint, 17 | notificationServer?: SecureContextEndpoint 18 | } 19 | 20 | export interface SecureContextConfig { 21 | id: string, 22 | publicKeys: SecureStorageContextPublicKeys, 23 | services: SecureContextServices 24 | isLegacyDid: boolean 25 | } -------------------------------------------------------------------------------- /packages/types/src/VdaClientConfig.ts: -------------------------------------------------------------------------------- 1 | import { BlockchainAnchor } from "./NetworkInterfaces"; 2 | import { Web3CallType, Web3SelfTransactionConfig, Web3MetaTransactionConfig } from "./Web3Interfaces"; 3 | /** 4 | * Interface for vda-xxx-client instance creation. 5 | * @param blockchainAnchor : Verida supported chain. ex : "polpos", "polamoy" {@link BlockchainAnchor} 6 | * In self transactio mode, this value should be the same as the `blockchainAnchor` of the @{@link Web3SelfTransactionConfig} 7 | * @param did: DID 8 | * @param signKey: private key of DID. Used to generate signature in transactions to chains 9 | * @param callType : VDA-DID run mode. Values from vda-did-resolver 10 | * @param web3Options: Web3 configuration depending on call type. Values from vda-did-resolver 11 | */ 12 | export interface VdaClientConfig { 13 | blockchainAnchor: BlockchainAnchor 14 | did?: string 15 | signKey?: string 16 | callType?: Web3CallType 17 | web3Options?: Web3SelfTransactionConfig | Web3MetaTransactionConfig 18 | } -------------------------------------------------------------------------------- /packages/types/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './NetworkInterfaces' 2 | export * from './AccountInterfaces' 3 | export * from './ContextInterfaces' 4 | export * from './DocumentInterfaces' 5 | export * from './IAccount' 6 | export * from './IClient' 7 | export * from './IContext' 8 | export * from './IDatabase' 9 | export * from './IDatastore' 10 | export * from './IDIDClient' 11 | export * from './IDIDContextManager' 12 | export * from './IDIDDocument' 13 | export * from './ISchema' 14 | export * from './IKeyring' 15 | export * from './IMessaging' 16 | export * from './INotification' 17 | export * from './IProfile' 18 | export * from './IStorageEngine' 19 | export * from './StorageLinkInterfaces' 20 | export * from './Web3Interfaces' 21 | export * from './IAuthType' 22 | export * from './IDbRegistry' 23 | export * from './VdaClientConfig' 24 | export * from './IStorageNode' -------------------------------------------------------------------------------- /packages/types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "declaration": true, 6 | "skipLibCheck": true, 7 | "outDir": "./dist", 8 | "sourceMap": true, 9 | "strict": true, 10 | "esModuleInterop": true 11 | }, 12 | "include": ["src"], 13 | "exclude": ["node_modules", "test", "dist"], 14 | } -------------------------------------------------------------------------------- /packages/vda-client-base/.gitignore: -------------------------------------------------------------------------------- 1 | #Ignore all files starting with "." 2 | .* 3 | !/.gitignore 4 | 5 | # node_modules in all sub directories 6 | **node_modules 7 | 8 | # build 9 | dist/ 10 | lib/ 11 | build/ -------------------------------------------------------------------------------- /packages/vda-client-base/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2024-07-15 (v.4.0.0) 2 | ------------------- 3 | 4 | - Initial release -------------------------------------------------------------------------------- /packages/vda-client-base/README.md: -------------------------------------------------------------------------------- 1 | 2 | # VDA Client Base 3 | 4 | Base class for other `vda-xxx-client` packages. 5 | This library contains the common part of the `vda-xxx-client` packages. 6 | 7 | 8 | ## Installation 9 | 10 | ``` 11 | yarn add @verida/vda-client-base 12 | ``` -------------------------------------------------------------------------------- /packages/vda-client-base/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@verida/vda-client-base", 3 | "version": "4.4.1", 4 | "description": "Base class of all `vda-xxx-client` classes", 5 | "main": "build/src/index.js", 6 | "types": "build/src/index.d.ts", 7 | "files": [ 8 | "build/src" 9 | ], 10 | "directories": { 11 | "src": "src" 12 | }, 13 | "license": "Apache-2.0", 14 | "keywords": [], 15 | "scripts": { 16 | "lint": "gts lint", 17 | "clean": "gts clean", 18 | "compile": "rm -rf build && tsc", 19 | "build": "rm -rf build && tsc", 20 | "fix": "gts fix", 21 | "prepare": "npm run compile" 22 | }, 23 | "dependencies": { 24 | "@ethersproject/providers": "^5.7.2", 25 | "@verida/helpers": "^4.4.1", 26 | "@verida/types": "^4.4.1", 27 | "@verida/web3": "^4.4.1", 28 | "axios": "^0.27.2", 29 | "ethers": "^5.7.0" 30 | }, 31 | "devDependencies": { 32 | "gts": "^3.1.0", 33 | "mocha": "^10.1.0", 34 | "ts-mocha": "^10.0.0", 35 | "ts-node": "^10.7.0", 36 | "typescript": "^4.6.4" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /packages/vda-client-base/src/blockchain/blockchainApi.ts: -------------------------------------------------------------------------------- 1 | import { 2 | getVeridaContract, 3 | VeridaContract 4 | } from "@verida/web3" 5 | import { Web3SelfTransactionConfig, VdaClientConfig, BlockchainAnchor, TContractNames } from '@verida/types' 6 | import { ethers, Contract } from "ethers"; 7 | import { getContractInfoForBlockchainAnchor, getDefaultRpcUrl } from "@verida/vda-common"; 8 | import { JsonRpcProvider } from '@ethersproject/providers'; 9 | import { explodeDID } from '@verida/helpers' 10 | 11 | export class VeridaClientBase { 12 | 13 | protected config: VdaClientConfig 14 | protected blockchainAnchor: BlockchainAnchor; 15 | protected didAddress?: string 16 | 17 | protected vdaWeb3Client? : VeridaContract 18 | 19 | protected readOnly: boolean 20 | protected contract?: ethers.Contract 21 | 22 | public constructor(config: VdaClientConfig, contractName: TContractNames) { 23 | if (!config.callType) { 24 | config.callType = 'web3' 25 | } 26 | 27 | this.config = config 28 | this.readOnly = true 29 | if (!config.web3Options) { 30 | config.web3Options = {} 31 | } 32 | 33 | this.blockchainAnchor = config.blockchainAnchor; 34 | 35 | if (config.callType == 'web3' && !(config.web3Options).rpcUrl) { 36 | ( config.web3Options).rpcUrl = getDefaultRpcUrl(this.blockchainAnchor)! 37 | } 38 | 39 | const contractInfo = getContractInfoForBlockchainAnchor(this.blockchainAnchor, contractName); 40 | 41 | if (config.did) { 42 | this.readOnly = false 43 | const { address } = explodeDID(config.did) 44 | this.didAddress = address;//.toLowerCase() 45 | 46 | this.vdaWeb3Client = getVeridaContract( 47 | config.callType, 48 | {...contractInfo, 49 | ...config.web3Options, 50 | blockchainAnchor: this.blockchainAnchor}) 51 | } else { 52 | let rpcUrl = (config.web3Options).rpcUrl 53 | if (!rpcUrl) { 54 | rpcUrl = getDefaultRpcUrl(this.blockchainAnchor)! 55 | } 56 | 57 | const provider = new JsonRpcProvider(rpcUrl) 58 | 59 | this.contract = new Contract(contractInfo.address, contractInfo.abi.abi, provider) 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /packages/vda-client-base/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './blockchain/blockchainApi' -------------------------------------------------------------------------------- /packages/vda-client-base/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "rootDir": ".", 6 | "outDir": "build", 7 | "sourceMap": true, 8 | "strict": true, 9 | "declaration": true, 10 | "esModuleInterop": true, 11 | "skipLibCheck": true 12 | }, 13 | "include": [ 14 | "src/**/*.ts", 15 | ], 16 | "exclude": ["node_modules", "test", "build"], 17 | "lib": [ 18 | "es5", 19 | "es2015" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /packages/vda-common-test/.gitignore: -------------------------------------------------------------------------------- 1 | #Ignore all files starting with "." 2 | .* 3 | !/.gitignore 4 | 5 | # node_modules in all sub directories 6 | **node_modules 7 | 8 | # build 9 | dist/ 10 | lib/ -------------------------------------------------------------------------------- /packages/vda-common-test/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2024-07-15 (v.4.0.0) 2 | ------------------- 3 | 4 | - Support BlockchainAnchor and Verida Network refactor 5 | - Updated DID constants following the DID format changed in `vda-common` 6 | - Added `owner()` function to `ERC20Manager` 7 | 8 | 9 | 2024-03-15 (v3.0.1) 10 | ------------------- 11 | - Added variables for locking test in the `StorageNodeRegistry` contract 12 | 13 | 2024-03-15 (v3.0.1) 14 | ------------------- 15 | - Update variable names for `StorageNode` 16 | - Update constants for `StorageNode` 17 | - Update type of `nonce` from `number` to `BigNumberish` 18 | - Add `ERC20` contract manager api 19 | 20 | 2023-12-26 (v.3.0.0) 21 | ------------------- 22 | - Update type of `nonce` from `number` to `BigNumberish` 23 | - Add `ERC20` contract manager api 24 | 25 | 26 | 2023-04-20 (v2.3.0) 27 | ------------------- 28 | - Mainnet release 29 | - Initial implementation -------------------------------------------------------------------------------- /packages/vda-common-test/README.md: -------------------------------------------------------------------------------- 1 | 2 | # VDA Common Test 3 | This package provide common **constant**s and **function**s for test. 4 | 5 | ## Package structure 6 | The codes here are used in the test codes only. 7 | - const.ts : Defined all constants for test 8 | - proof.ts : Provide functions related signature for interacting with Verida contracts 9 | - utils.ts : Provide utility functions -------------------------------------------------------------------------------- /packages/vda-common-test/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@verida/vda-common-test", 3 | "version": "4.0.1", 4 | "description": "Common utils & contract addresses for Verida", 5 | "main": "dist/index.js", 6 | "author": "Alex J", 7 | "license": "MIT", 8 | "directories": { 9 | "src": "src", 10 | "test": "tests" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/verida/verida-js.git" 15 | }, 16 | "scripts": { 17 | "copy-files": "copyfiles -u 1 src/**/*.json dist/", 18 | "tests": "ts-mocha './test/**/*.ts'", 19 | "test": "ts-mocha --timeout 100000", 20 | "build": "rm -rf dist && tsc && yarn copy-files" 21 | }, 22 | "devDependencies": { 23 | "dotenv": "^16.0.3", 24 | "typescript": "^5.0.4" 25 | }, 26 | "dependencies": { 27 | "@ethersproject/providers": "5.7.2", 28 | "ethers": "^5.7.2", 29 | "mocha": "^10.2.0", 30 | "ts-mocha": "^10.0.0" 31 | }, 32 | "bugs": { 33 | "url": "https://github.com/verida/verida-js/issues" 34 | }, 35 | "homepage": "https://github.com/verida/verida-js#readme", 36 | "files": [ 37 | "lib" 38 | ], 39 | "publishConfig": { 40 | "access": "public" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /packages/vda-common-test/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './const' 2 | export * from './utils' 3 | export * from './erc20/erc20Manager' 4 | export * from './storage_node' -------------------------------------------------------------------------------- /packages/vda-common-test/src/utils.ts: -------------------------------------------------------------------------------- 1 | require('dotenv').config(); 2 | 3 | export function sleep(ms: number) { 4 | return new Promise((resolve) => { 5 | setTimeout(resolve, ms); 6 | }); 7 | } 8 | 9 | export function getBlockchainAPIConfiguration(privateKey: string) { 10 | const args = process.argv.slice(2); 11 | // console.log("ARGS : ", args); 12 | const testMode : 'gasless' | 'web3' = args.length > 0 && args.includes('gasless') ? 'gasless' : 'web3'; 13 | // args.length > 0 && args[0] === 'direct' ? args[0] : 'gasless'; 14 | // console.log('Test mode : ', testMode); 15 | 16 | let configuration = { 17 | callType: testMode, 18 | web3Options: { 19 | } 20 | } 21 | 22 | if (testMode === 'web3') { 23 | const rpcURL = process.env.RPC_URL; 24 | if (!rpcURL) { 25 | throw new Error('No RPC_URL in the env file'); 26 | } 27 | 28 | configuration["web3Options"] = { 29 | // signer?: Signer; 30 | privateKey, 31 | // provider?: Provider; 32 | rpcUrl: rpcURL, 33 | logPerformance: true 34 | // web3?: any; 35 | } 36 | } else { 37 | const PORT = process.env.SERVER_PORT ? process.env.SERVER_PORT : 5021; 38 | const SERVER_URL = `http://localhost:${PORT}`; 39 | 40 | configuration["web3Options"] = { 41 | serverConfig: { 42 | headers: { 43 | 'context-name': 'Verida Test', 44 | }, 45 | }, 46 | postConfig: { 47 | headers: { 48 | 'user-agent': 'Verida-Vault', 49 | }, 50 | }, 51 | endpointUrl: SERVER_URL, 52 | } 53 | } 54 | 55 | return configuration; 56 | } -------------------------------------------------------------------------------- /packages/vda-common-test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig to read more about this file */ 4 | 5 | /* Projects */ 6 | 7 | /* Language and Environment */ 8 | "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ 9 | 10 | /* Modules */ 11 | "module": "commonjs", /* Specify what module code is generated. */ 12 | 13 | /* JavaScript Support */ 14 | // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ 15 | // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ 16 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ 17 | 18 | /* Emit */ 19 | "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ 20 | "sourceMap": true, /* Create source map files for emitted JavaScript files. */ 21 | "outDir": "./dist", /* Specify an output folder for all emitted files. */ 22 | 23 | /* Interop Constraints */ 24 | // "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ 25 | // // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ 26 | // "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ 27 | 28 | /* Type Checking */ 29 | "strict": true, /* Enable all strict type-checking options. */ 30 | 31 | /* Completeness */ 32 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ 33 | "skipLibCheck": true, /* Skip type checking all .d.ts files. */ 34 | "lib": [ 35 | "es5", 36 | "es2015" 37 | ] 38 | }, 39 | "include": ["src"], 40 | "exclude": ["node_modules", "test", "dist"] 41 | } 42 | -------------------------------------------------------------------------------- /packages/vda-common/.gitignore: -------------------------------------------------------------------------------- 1 | #Ignore all files starting with "." 2 | .* 3 | !/.gitignore 4 | 5 | # node_modules in all sub directories 6 | **node_modules 7 | 8 | # build 9 | dist/ 10 | lib/ -------------------------------------------------------------------------------- /packages/vda-common/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ? 2 | ------------------- 3 | 4 | - npx lerna publish --dist-tag next 5 | 6 | 2024-07-15 (v.4.0.0) 7 | ------------------- 8 | 9 | - Support BlockchainAnchor and Verida Network refactor 10 | 11 | 12 | 2024-03-22 (v3.0.2) 13 | ------------------- 14 | 15 | - Update the abi & address of `StorageNodeRegistry` contract (locking feature added) 16 | - Replaced the testenet RPC_URL from `Mumbai` to `Amoy` 17 | 18 | 19 | 2024-03-22 (v3.0.2) 20 | ------------------- 21 | 22 | - Update the abi & address of `StorageNodeRegistry` contract 23 | 24 | 2024-03-15 (v3.0.1) 25 | ------------------- 26 | 27 | - Update RPC URL's to Polygon Foundation supported nodes 28 | 29 | 2023-12-26 (v.3.0.0) 30 | ------------------- 31 | 32 | - Mainnet release 33 | - Feature: Add gas station config for all networks 34 | 35 | 2023-04-27 (v2.3.4) 36 | ------------------- 37 | 38 | - Update contract names 39 | 40 | 2023-04-27 (v2.3.3) 41 | ------------------- 42 | 43 | - Fix incorrect contract names 44 | - Fix missing dependencies 45 | 46 | 2023-04-24 (v2.3.1) 47 | ------------------- 48 | 49 | - Fix Downgrade to ethers due to build issues 50 | 51 | 2023-04-20 (v2.3.0) 52 | ------------------- 53 | 54 | - Initial implementation -------------------------------------------------------------------------------- /packages/vda-common/README.md: -------------------------------------------------------------------------------- 1 | 2 | # VDA Common 3 | This package provide common **constant**s and **function**s for other libraries. 4 | 5 | ## Package structure 6 | - "/abi" : Includes all ABI files of verida contracts 7 | - contract.ts : Provide functions related verida contracts 8 | - rpc.ts : Provide functions related RPC urls to interact with blockchains. 9 | - util.ts : Provide utility functions -------------------------------------------------------------------------------- /packages/vda-common/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@verida/vda-common", 3 | "version": "4.4.1", 4 | "description": "Common utils & contract addresses for Verida", 5 | "main": "dist/index.js", 6 | "author": "Alex J", 7 | "license": "MIT", 8 | "directories": { 9 | "src": "src", 10 | "test": "tests" 11 | }, 12 | "repository": "https://github.com/verida/verida-js.git", 13 | "scripts": { 14 | "tests": "ts-mocha './test/**/*.ts'", 15 | "copy-files": "copyfiles -u 1 src/**/*.json dist/", 16 | "test": "ts-mocha --timeout 100000", 17 | "build": "rm -rf dist && tsc && yarn copy-files" 18 | }, 19 | "devDependencies": { 20 | "dotenv": "^16.0.3", 21 | "mocha": "^10.2.0", 22 | "ts-mocha": "^10.0.0", 23 | "ts-node": "^10.9.1", 24 | "typescript": "^5.0.4" 25 | }, 26 | "dependencies": { 27 | "@verida/encryption-utils": "^4.0.1", 28 | "@verida/types": "^4.4.1", 29 | "copyfiles": "^2.4.1", 30 | "ethers": "5.7.2" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/vda-common/src/defaults.ts: -------------------------------------------------------------------------------- 1 | import { BlockchainAnchor, Network } from "@verida/types" 2 | import { RPC_URLS } from "./rpc" 3 | 4 | export const DefaultNetworkBlockchainAnchors: Record = { 5 | [Network.LOCAL]: BlockchainAnchor.POLAMOY, 6 | [Network.DEVNET]: BlockchainAnchor.POLAMOY, 7 | [Network.BANKSIA]: BlockchainAnchor.POLAMOY, 8 | [Network.MYRTLE]: BlockchainAnchor.POLPOS 9 | } 10 | 11 | export function getWeb3ConfigDefaults(chainName: string) { 12 | switch (chainName) { 13 | case 'devnet': 14 | case 'polamoy': 15 | case 'testnet': 16 | return { 17 | rpcUrl: RPC_URLS[chainName], 18 | eip1559Mode: 'fast', 19 | eip1559gasStationUrl: 'https://gasstation-testnet.polygon.technology/amoy' 20 | } 21 | case 'mainnet': 22 | case 'polpos': 23 | return { 24 | rpcUrl: RPC_URLS[chainName], 25 | eip1559Mode: 'fast', 26 | eip1559gasStationUrl: 'https://gasstation.polygon.technology/v2' 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /packages/vda-common/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './contract' 2 | export * from './rpc' 3 | export * from './utils' 4 | export * from './defaults' 5 | export * from './verification' -------------------------------------------------------------------------------- /packages/vda-common/src/rpc.ts: -------------------------------------------------------------------------------- 1 | /* Default RPC URLs to the Polygon blockchains. These default endpoints are public and free but potentially unstable */ 2 | export const RPC_URLS: Record = { 3 | // Ankr is the official RPC provider of the Polygon foundation 4 | // https://rpc.ankr.com/polygon is the same as https://polygon-rpc.com as also provided by Ankr 5 | mainnet: "https://rpc.ankr.com/polygon", 6 | "0x89": "https://rpc.ankr.com/polygon", 7 | testnet: "https://rpc-amoy.polygon.technology", 8 | "0x13882": "https://rpc-amoy.polygon.technology", 9 | devnet: "https://rpc-amoy.polygon.technology", 10 | polpos: "https://rpc.ankr.com/polygon", 11 | polamoy: "https://rpc-amoy.polygon.technology" 12 | }; 13 | 14 | export function getDefaultRpcUrl(chainNameOrId: any) { 15 | if (RPC_URLS[chainNameOrId]) { 16 | return RPC_URLS[chainNameOrId] 17 | } 18 | 19 | throw new Error(`Unknown chain: ${chainNameOrId}`) 20 | } 21 | -------------------------------------------------------------------------------- /packages/vda-common/src/verification.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Common functions to mange trustedSigners 3 | */ 4 | class VdaVerificationUtilsClass { 5 | protected readOnly: any; 6 | protected config: any; 7 | protected vdaWeb3Client: any; 8 | protected contract: any; 9 | 10 | /** 11 | * Add a trusted signer 12 | * @param didAddress DID address to be added 13 | */ 14 | public async addTrustedSigner(didAddress: string) { 15 | 16 | if (this.readOnly || !this.vdaWeb3Client) { 17 | throw new Error(`Unable to submit to blockchain. In read only mode.`) 18 | } 19 | 20 | const response = await this.vdaWeb3Client.addTrustedSigner(didAddress); 21 | 22 | if (response.success !== true) { 23 | throw new Error(`Failed to add a trusted signer: ${response.reason}`); 24 | } 25 | } 26 | 27 | /** 28 | * Remove a trusted signer 29 | * @param didAddress DID address to be added 30 | */ 31 | public async removeTrustedSigner( 32 | didAddress: string 33 | ) { 34 | if (this.readOnly || !this.vdaWeb3Client) { 35 | throw new Error(`Unable to submit to blockchain. In read only mode.`) 36 | } 37 | 38 | const response = await this.vdaWeb3Client!.removeTrustedSigner(didAddress); 39 | 40 | if (response.success !== true) { 41 | throw new Error(`Failed to remove a trusted signer: ${response.reason}`); 42 | } 43 | } 44 | 45 | /** 46 | * Check whether given address is a trusted signer 47 | * @param didAddress DID address to be checked 48 | * @returns true if trusted signer, otherwise false 49 | */ 50 | public async isTrustedSigner(didAddress: string) { 51 | let response; 52 | try { 53 | if (this.vdaWeb3Client) { 54 | response = await this.vdaWeb3Client.isTrustedSigner(didAddress); 55 | if (response.success !== true) { 56 | throw new Error(response.reason); 57 | } 58 | 59 | return response.data 60 | } else { 61 | response = await this.contract!.callStatic.isTrustedSigner(didAddress); 62 | 63 | return response; 64 | } 65 | } catch (err:any ) { 66 | const message = err.reason ? err.reason : err.message; 67 | throw new Error(`Failed to check trusted signer (${message})`); 68 | } 69 | } 70 | } 71 | 72 | export const VdaVerificationUtils = new VdaVerificationUtilsClass(); -------------------------------------------------------------------------------- /packages/vda-common/test/utils.tests.ts: -------------------------------------------------------------------------------- 1 | const assert = require('assert') 2 | import { interpretIdentifier } from '../src/utils'; 3 | import { BlockchainAnchor } from '@verida/types'; 4 | 5 | describe('Interpret identifier test', function() { 6 | it('Handles old DID formats', async () => { 7 | const dids = { 8 | 'did:vda:mainnet:0xCDEdd96AfA6956f0299580225C2d9a52aca8487A': { 9 | 'network': BlockchainAnchor.POLPOS, 10 | 'address': '0xCDEdd96AfA6956f0299580225C2d9a52aca8487A' 11 | }, 12 | 'did:vda:testnet:0x158672345D2486a148313c6b107857A64ff6b477': { 13 | 'network': BlockchainAnchor.POLAMOY, 14 | 'address': '0x158672345D2486a148313c6b107857A64ff6b477' 15 | } 16 | }; 17 | 18 | Object.keys(dids).forEach((did: string) => { 19 | const result = interpretIdentifier(did); 20 | assert.equal(result.network, dids[did].network, 'Network matches'); 21 | assert.equal(result.address, dids[did].address, 'Address matches') 22 | }); 23 | }); 24 | 25 | it('Handles new DID formats', async () => { 26 | const dids = { 27 | 'did:vda:polpos:0xCDEdd96AfA6956f0299580225C2d9a52aca8487A': { 28 | 'network': BlockchainAnchor.POLPOS, 29 | 'address': '0xCDEdd96AfA6956f0299580225C2d9a52aca8487A' 30 | }, 31 | 'did:vda:polamoy:0x158672345D2486a148313c6b107857A64ff6b477': { 32 | 'network': BlockchainAnchor.POLAMOY, 33 | 'address': '0x158672345D2486a148313c6b107857A64ff6b477' 34 | } 35 | }; 36 | 37 | Object.keys(dids).forEach((did: string) => { 38 | const result = interpretIdentifier(did); 39 | assert.equal(result.network, dids[did].network, 'Network matches'); 40 | assert.equal(result.address, dids[did].address, 'Address matches') 41 | }); 42 | }); 43 | }); -------------------------------------------------------------------------------- /packages/vda-common/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig to read more about this file */ 4 | 5 | /* Projects */ 6 | 7 | /* Language and Environment */ 8 | "target": "es5", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ 9 | 10 | /* Modules */ 11 | "module": "commonjs", /* Specify what module code is generated. */ 12 | 13 | /* JavaScript Support */ 14 | // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ 15 | // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ 16 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ 17 | 18 | /* Emit */ 19 | "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ 20 | "sourceMap": true, /* Create source map files for emitted JavaScript files. */ 21 | "outDir": "./dist", /* Specify an output folder for all emitted files. */ 22 | 23 | /* Interop Constraints */ 24 | "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ 25 | // // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ 26 | // "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ 27 | 28 | /* Type Checking */ 29 | "strict": true, /* Enable all strict type-checking options. */ 30 | 31 | /* Completeness */ 32 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ 33 | "skipLibCheck": true, /* Skip type checking all .d.ts files. */ 34 | "lib": [ 35 | "es5", 36 | "es2015" 37 | ] 38 | }, 39 | "include": ["src"], 40 | "exclude": ["node_modules", "test", "dist"] 41 | } 42 | -------------------------------------------------------------------------------- /packages/vda-did-resolver/.env.example: -------------------------------------------------------------------------------- 1 | ## These are used for test only. 2 | PRIVATE_KEY = "" 3 | RPC_URL="" -------------------------------------------------------------------------------- /packages/vda-did-resolver/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | coverage 4 | apidocs 5 | dist 6 | lib 7 | yarn-error.log 8 | 9 | # Editor directories and files 10 | .idea 11 | .vscode 12 | *.suo 13 | *.ntvs* 14 | *.njsproj 15 | *.sln 16 | *.sw? 17 | 18 | -------------------------------------------------------------------------------- /packages/vda-did-resolver/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2024-07-15 (v.4.0.0) 2 | ------------------- 3 | 4 | - Support BlockchainAnchor and Verida Network refactor 5 | 6 | 2023-12-26 (v.3.0.0) 7 | ------------------- 8 | 9 | - Mainnet release 10 | - `getDIDs` returns DID addresses instead of blockchain addresses 11 | - Minor typescript improvements 12 | 13 | 2023-07-11 (v2.3.6) 14 | ------------------- 15 | 16 | - Add `getDIDs` method 17 | 18 | 2023-05-12 (v2.3.5) 19 | ------------------- 20 | 21 | - Add `activeDIDCount` method 22 | 23 | 2023-04-27 (v2.3.4) 24 | ------------------- 25 | 26 | - Update contract name of ABI 27 | 28 | 2023-04-20 (v2.3.0) 29 | ------------------- 30 | 31 | - Update to latest protocol dependencies 32 | - Update tests 33 | - Update contract address (breaking change) 34 | 35 | 2023-03-27 (v2.2.1) 36 | ------------------- 37 | 38 | - Fix tests 39 | 40 | 2022-03-01 (v2.1.3) 41 | ------------------- 42 | 43 | - Support fetching default RPC_URLs 44 | - Expose `VdaDidResolver` class from package 45 | - Add usage and configuration instructions to README.md 46 | 47 | 2022-02-09 (v2.0.5) 48 | ------------------- 49 | 50 | - Fix: Resolver returned `didDocument.doc` instead of `didDocument` 51 | 52 | 2023-01-27 (v2.0.4) 53 | ------------------- 54 | 55 | - Remove engine restriction of Node 14 only 56 | 57 | 2023-01-24 (v2.0.2) 58 | ------------------- 59 | 60 | - Upgrade to @verida/types 61 | 62 | 2023-01-13 (v2.0.0) 63 | ------------------- 64 | 65 | - Initial implementation (v2.0.0 to be inline with the rest of the protocol) -------------------------------------------------------------------------------- /packages/vda-did-resolver/README.md: -------------------------------------------------------------------------------- 1 | 2 | # VDA DID Resolver 3 | 4 | Provides a simple `getResolver()` method that supports resolving Verida DID's. 5 | 6 | # Installation 7 | 8 | ``` 9 | yarn add @verida/vda-did-resolver 10 | ``` 11 | 12 | # Usage 13 | 14 | ```js 15 | import { Resolver } from 'did-resolver' 16 | import { getResolver } from '@verida/did-resolver' 17 | 18 | const vdaDidResolver = getResolver() 19 | const didResolver = new Resolver(vdaDidResolver) 20 | 21 | const did = 'did:vda:testnet:0x....' 22 | 23 | try { 24 | const response = await didResolver.resolve(did) 25 | const didDocument = response.didDocument 26 | } catch (err) { 27 | console.error(err.message) 28 | } 29 | ``` 30 | 31 | # Configuration 32 | 33 | `getResolver(Web3ResolverConfigurationOptions: {})` supports the following configuration: 34 | 35 | ```js 36 | export interface Web3ResolverConfigurationOptions { 37 | rpcUrl?: string; 38 | timeout?: number; 39 | } 40 | ``` 41 | 42 | Where: 43 | 44 | - `rpcUrl` - An optional Polygon RPC_URL to use (a default public RPC_URL is set as default) 45 | - `timeout` - An optional timeout (in milliseconds) to wait before failing HTTP requests to API endpoints hosting copies of the DID Document -------------------------------------------------------------------------------- /packages/vda-did-resolver/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@verida/vda-did-resolver", 3 | "version": "4.4.2", 4 | "main": "dist/index.js", 5 | "license": "ISC", 6 | "directories": { 7 | "src": "src", 8 | "test": "tests" 9 | }, 10 | "repository": "https://github.com/verida/verida-js.git", 11 | "scripts": { 12 | "tests": "ts-mocha './test/**/*.ts'", 13 | "test": "ts-mocha --timeout 100000", 14 | "build": "rm -rf dist && tsc" 15 | }, 16 | "engines": { 17 | "node": ">=18.0.0" 18 | }, 19 | "dependencies": { 20 | "@ethersproject/providers": "^5.7.2", 21 | "@verida/did-document": "^4.4.2", 22 | "@verida/encryption-utils": "^4.0.1", 23 | "@verida/types": "^4.4.1", 24 | "@verida/vda-common": "^4.4.1", 25 | "@verida/vda-did": "^4.4.2", 26 | "axios": "1.2.0-alpha.1", 27 | "ethers": "^5.7.2", 28 | "lodash": "^4.17.21" 29 | }, 30 | "devDependencies": { 31 | "@types/chai": "^4.3.4", 32 | "@types/mocha": "^10.0.0", 33 | "@verida/vda-common-test": "^4.0.1", 34 | "did-resolver": "^4.0.1", 35 | "mocha": "^10.1.0", 36 | "ts-mocha": "^8.0.0", 37 | "ts-node": "^10.9.1", 38 | "typescript": "^4.1.3" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /packages/vda-did-resolver/src/activeDIDCount.ts: -------------------------------------------------------------------------------- 1 | import { getContractInfoForBlockchainAnchor, getDefaultRpcUrl } from "@verida/vda-common"; 2 | 3 | import { JsonRpcProvider } from '@ethersproject/providers'; 4 | import { Contract } from 'ethers'; 5 | import { BlockchainAnchor } from "@verida/types"; 6 | 7 | /** 8 | * Call lookUp() function of DIDRegistry contract 9 | * @param didAddress DID address to lookup 10 | * @param rpcUrl URL 11 | */ 12 | export async function activeDIDCount(blockchain: BlockchainAnchor, rpcUrl: string | null = ''): Promise { 13 | rpcUrl = rpcUrl ? rpcUrl : getDefaultRpcUrl(blockchain.toString()) 14 | if (!rpcUrl) { 15 | throw new Error(`Unable to locate RPC_URL for network: ${blockchain.toString()}`) 16 | } 17 | 18 | // Simple read-only of the blockchain 19 | const contractInfo = getContractInfoForBlockchainAnchor(blockchain, "didRegistry"); 20 | const provider = new JsonRpcProvider(rpcUrl); 21 | const contract = new Contract(contractInfo.address, contractInfo.abi.abi, provider); 22 | 23 | let data; 24 | try { 25 | data = (await contract.callStatic.activeDIDCount()).toNumber(); 26 | } catch (e: any) { 27 | throw new Error('Failed to get number of active DIDs'); 28 | } 29 | 30 | return data 31 | } -------------------------------------------------------------------------------- /packages/vda-did-resolver/src/getDIDs.ts: -------------------------------------------------------------------------------- 1 | import { getContractInfoForBlockchainAnchor, getDefaultRpcUrl } from "@verida/vda-common"; 2 | 3 | import { JsonRpcProvider } from '@ethersproject/providers'; 4 | import { Contract } from 'ethers'; 5 | import { activeDIDCount } from "./activeDIDCount"; 6 | import { BlockchainAnchor } from '@verida/types' 7 | 8 | /** 9 | * Call lookUp() function of DIDRegistry contract 10 | * @param network Verida network to retreieve DIDs for 11 | * @param startIndex Index to start 12 | * @param count Total number of results to fetch 13 | */ 14 | export async function getDIDs(blockchain: BlockchainAnchor, startIndex: number=0, count: number=20, mostRecent: boolean=true, rpcUrl: string | null = ''): Promise { 15 | rpcUrl = rpcUrl ? rpcUrl : getDefaultRpcUrl(blockchain.toString()) 16 | if (!rpcUrl) { 17 | throw new Error(`Unable to locate RPC_URL for network: ${blockchain.toString()}`) 18 | } 19 | 20 | const contractInfo = getContractInfoForBlockchainAnchor(blockchain, "didRegistry"); 21 | 22 | // Simple read-only of the blockchain 23 | const provider = new JsonRpcProvider(rpcUrl); 24 | 25 | try { 26 | const contract = new Contract(contractInfo.address, contractInfo.abi.abi, provider); 27 | 28 | if (mostRecent) { 29 | // user wants most recent DIDs 30 | // we need to calculate the correct offset 31 | // Note that startIndex is indexed from the **end** of the list of DIDs 32 | // so a startIndex of 0 and count of 20 means get the 20 most recent. 33 | const activeDidCount = await activeDIDCount(blockchain) 34 | startIndex = activeDidCount - startIndex - count 35 | if (startIndex < 0) { 36 | startIndex = 0 37 | } 38 | } 39 | 40 | const data = (await contract.callStatic.getDIDs(startIndex, count)) as string[]; 41 | 42 | // map the raw string into the correct canonoical DID format 43 | return (data || []).map((did) => `did:vda:${blockchain.toString()}:${did}`) 44 | 45 | } catch (e: any) { 46 | throw new Error('Failed to get list of active DIDs'); 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /packages/vda-did-resolver/src/index.ts: -------------------------------------------------------------------------------- 1 | import { getResolver, VdaDidResolver } from './resolver' 2 | import { RPC_URLS } from '@verida/vda-common' 3 | import { activeDIDCount } from './activeDIDCount' 4 | import { getDIDs } from './getDIDs' 5 | import { lookup } from './lookup' 6 | 7 | export { 8 | getResolver, 9 | VdaDidResolver, 10 | getDIDs, 11 | RPC_URLS, 12 | activeDIDCount, 13 | lookup 14 | } -------------------------------------------------------------------------------- /packages/vda-did-resolver/src/lookup.ts: -------------------------------------------------------------------------------- 1 | import { getContractInfoForBlockchainAnchor, getDefaultRpcUrl, mapDidNetworkToBlockchainAnchor } from "@verida/vda-common"; 2 | 3 | import { JsonRpcProvider } from '@ethersproject/providers'; 4 | import { Contract } from 'ethers'; 5 | 6 | /** 7 | * Call lookUp() function of DIDRegistry contract 8 | * @param didAddress DID address to lookup 9 | * @param rpcUrl URL 10 | */ 11 | export async function lookup(didAddress: string, network: string, rpcUrl?: string) : Promise { 12 | const blockchain = mapDidNetworkToBlockchainAnchor(network) 13 | if (!blockchain) { 14 | throw new Error(`Empty contract address for network-${network}`) 15 | } 16 | 17 | if (!rpcUrl) { 18 | getDefaultRpcUrl(network) 19 | if (!rpcUrl) { 20 | throw new Error(`Unable to locate RPC_URL for network: ${blockchain.toString()}`) 21 | } 22 | } 23 | 24 | const contractInfo = getContractInfoForBlockchainAnchor(blockchain, "didRegistry"); 25 | const provider = new JsonRpcProvider(rpcUrl); 26 | const contract = new Contract(contractInfo.address, contractInfo.abi.abi, provider); 27 | 28 | let data = []; 29 | try { 30 | data = await contract.callStatic.lookup(didAddress); 31 | } catch (e: any) { 32 | throw new Error('DID not found'); 33 | } 34 | 35 | return data[1] 36 | } -------------------------------------------------------------------------------- /packages/vda-did-resolver/test/activeDIDCount.test.ts: -------------------------------------------------------------------------------- 1 | const assert = require('assert') 2 | import { BlockchainAnchor } from '@verida/types'; 3 | import { activeDIDCount } from '../src/activeDIDCount'; 4 | 5 | describe('activeDIDCount test', function() { 6 | this.timeout(20000) 7 | 8 | it('Success', async () => { 9 | // Need to register this did before 10 | const result = await activeDIDCount(BlockchainAnchor.POLAMOY); 11 | 12 | assert.equal(typeof(result), 'number', 'activeDIDCount number') 13 | console.log("Current count = ", result) 14 | }); 15 | }) -------------------------------------------------------------------------------- /packages/vda-did-resolver/test/getDIDs.test.ts: -------------------------------------------------------------------------------- 1 | const assert = require('assert') 2 | import { BlockchainAnchor } from '@verida/types'; 3 | import { getDIDs } from '../src/getDIDs'; 4 | 5 | const NETWORK = 'testnet' 6 | 7 | describe('getDIDs test', function() { 8 | this.timeout(20000) 9 | 10 | it('Get first 20 created DIDs', async () => { 11 | const result = await getDIDs(BlockchainAnchor.POLAMOY, 0, 20); 12 | 13 | assert.ok(result, 'Have a result') 14 | assert.ok(result.length, 'Have at least one result returned') 15 | }); 16 | }) -------------------------------------------------------------------------------- /packages/vda-did-resolver/test/lookup.test.ts: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | require('dotenv').config(); 3 | import { Wallet } from 'ethers'; 4 | import { lookup } from '../src/lookup'; 5 | import { BlockchainAnchor } from '@verida/types'; 6 | 7 | const did = { 8 | address: "0xB0BF030a742233448428590bf6A590C1E1582b4C", 9 | } 10 | 11 | const NETWORK = 'testnet' 12 | 13 | const rpcUrl = process.env.RPC_URL 14 | 15 | describe('Lookup test', function() { 16 | this.timeout(20000) 17 | it('Failed : Unregistered DID address', async () => { 18 | const tempDid = Wallet.createRandom(); 19 | await assert.rejects( 20 | lookup(tempDid.address, NETWORK, rpcUrl), 21 | {message: 'DID not found'} 22 | ) 23 | }); 24 | 25 | it('Success', async () => { 26 | // Need to register this did before 27 | const result = await lookup(did.address, BlockchainAnchor.POLAMOY, rpcUrl); 28 | 29 | assert.equal(typeof(result), 'object', 'DID Controller is a string') 30 | assert.ok(result.length > 0, 'Three endpoints returned') 31 | }); 32 | }) -------------------------------------------------------------------------------- /packages/vda-did-resolver/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "declaration": true, 6 | "skipLibCheck": true, // disable TS checking of dependencies 7 | "outDir": "./dist", 8 | "sourceMap": true, 9 | "strict": true, 10 | "lib": [ 11 | "es5", 12 | "es2015" 13 | ], 14 | "allowSyntheticDefaultImports": true, 15 | "resolveJsonModule": true, 16 | "esModuleInterop": true, 17 | }, 18 | "include": ["src"], 19 | "exclude": ["node_modules", "test", "dist"] 20 | } -------------------------------------------------------------------------------- /packages/vda-did/.env.example: -------------------------------------------------------------------------------- 1 | ## These are used for test only. 2 | PRIVATE_KEY = "" 3 | RPC_URL="" 4 | 5 | ## Flag for Mainnet or Testnet. Used to get gas configuration in vda-web3-client 6 | IS_PROD = true -------------------------------------------------------------------------------- /packages/vda-did/.gitignore: -------------------------------------------------------------------------------- 1 | #Ignore all files starting with "." 2 | .* 3 | !/.gitignore 4 | 5 | # node_modules in all sub directories 6 | **node_modules 7 | 8 | # build 9 | dist/ 10 | lib/ -------------------------------------------------------------------------------- /packages/vda-did/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2024-07-15 (v.4.0.0) 2 | ------------------- 3 | 4 | - Support BlockchainAnchor and Verida Network refactor 5 | - Minor updates for changes in `vda-web3-client` 6 | - Test code updated 7 | - Updated `.env.example` file 8 | 9 | 2023-12-26 (v3.0.0) 10 | ------------------- 11 | 12 | - Mainnet release 13 | - Fix: Ethers dependency was dev only 14 | - Feature: Include on-chain error message in thrown exception 15 | - Feature: Added manual gas configuration for the non-view contract functions 16 | - Feature: Update test files for testnet with various gas configurations 17 | - Feature: Added test file for mainnet test 18 | - Fix: Maximum three retries when creating a DID to prevent infinite loops 19 | 20 | 2023-04-27 (v2.3.4) 21 | ------------------- 22 | 23 | - Update contract name of ABI 24 | 25 | 2023-04-20 (v2.3.0) 26 | ------------------- 27 | 28 | - Update to latest protocol dependencies 29 | - Update tests 30 | - Update contract address (breaking change) 31 | 32 | 2023-03-27 (v2.2.1) 33 | ------------------- 34 | 35 | - Fix tests 36 | 37 | 2022-03-01 (v2.1.3) 38 | ------------------- 39 | 40 | - Add usage and configuration instructions to README.md 41 | - Fix timeout issues with tests 42 | - Support optional `signer` function instead of `signKey` 43 | 44 | 2022-02-09 (v2.0.5) 45 | ------------------- 46 | 47 | - Fix: Handle string error response from Axios 48 | - Fix: circular dependency to vda-did-resolver 49 | 50 | 2023-01-27 (v2.0.4) 51 | ------------------- 52 | 53 | - Remove engine restriction of Node 14 only 54 | 55 | 2023-01-24 (v2.0.2) 56 | ------------------- 57 | 58 | - Upgrade to @verida/types 59 | 60 | 2023-01-17 (v2.0.1) 61 | ------------------- 62 | 63 | - Fix: Update test endpoints 64 | 65 | 2023-01-13 (v2.0.0) 66 | ------------------- 67 | 68 | - Initial implementation (v2.0.0 to be inline with the rest of the protocol) -------------------------------------------------------------------------------- /packages/vda-did/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@verida/vda-did", 3 | "version": "4.4.2", 4 | "main": "dist/index.js", 5 | "license": "ISC", 6 | "directories": { 7 | "src": "src", 8 | "test": "tests" 9 | }, 10 | "repository": "https://github.com/verida/verida-js.git", 11 | "scripts": { 12 | "tests": "ts-mocha './test/**/*.ts'", 13 | "test": "ts-mocha --timeout 100000", 14 | "build": "rm -rf dist && tsc" 15 | }, 16 | "engines": { 17 | "node": ">=18.0.0" 18 | }, 19 | "dependencies": { 20 | "@verida/did-document": "^4.4.2", 21 | "@verida/types": "^4.4.1", 22 | "@verida/vda-common": "^4.4.1", 23 | "@verida/web3": "^4.4.1", 24 | "axios": "1.2.0-alpha.1", 25 | "ethers": "^5.7.2", 26 | "lodash": "^4.17.21" 27 | }, 28 | "devDependencies": { 29 | "@verida/vda-common-test": "^4.0.1", 30 | "dotenv": "^16.0.3", 31 | "mocha": "7.0.0", 32 | "ts-mocha": "^8.0.0", 33 | "ts-node": "^9.1.1", 34 | "typescript": "^4.1.3" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /packages/vda-did/src/blockchain/helpers.ts: -------------------------------------------------------------------------------- 1 | import {BigNumberish, ethers} from 'ethers'; 2 | 3 | export async function getVeridaSignWithNonce( 4 | rawMsg: string, 5 | signer: (data: any) => Promise, 6 | nonce: BigNumberish 7 | ) { 8 | rawMsg = ethers.utils.solidityPack(['bytes', 'uint256'], [rawMsg, nonce]); 9 | return signer(rawMsg) 10 | } -------------------------------------------------------------------------------- /packages/vda-did/src/index.ts: -------------------------------------------------------------------------------- 1 | import VdaDid from "./vdaDid"; 2 | 3 | export { 4 | VdaDid 5 | } -------------------------------------------------------------------------------- /packages/vda-did/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "declaration": true, 6 | "skipLibCheck": true, // disable TS checking of dependencies 7 | "outDir": "./dist", 8 | "sourceMap": true, 9 | "strict": true, 10 | "lib": [ 11 | "es5", 12 | "es2015" 13 | ] 14 | }, 15 | "include": ["src"], 16 | "exclude": ["node_modules", "test", "dist"] 17 | } -------------------------------------------------------------------------------- /packages/vda-name-client/.env.example: -------------------------------------------------------------------------------- 1 | ## These are used for test only. 2 | PRIVATE_KEY = "" 3 | RPC_URL="" -------------------------------------------------------------------------------- /packages/vda-name-client/.gitignore: -------------------------------------------------------------------------------- 1 | #Ignore all files starting with "." 2 | .* 3 | !/.gitignore 4 | 5 | # node_modules in all sub directories 6 | **node_modules 7 | 8 | # build 9 | dist/ 10 | lib/ 11 | build/ -------------------------------------------------------------------------------- /packages/vda-name-client/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2024-07-15 (v.4.0.0) 2 | ------------------- 3 | 4 | - Support BlockchainAnchor and Verida Network refactor 5 | - Make `VeridaNameClient` extends `VeridaClientBase` 6 | - Update the test code 7 | - Updated `.env.example` file 8 | - Added `Test.md` file 9 | 10 | 2023-12-26 (v3.0.0) 11 | ------------------- 12 | 13 | - Mainnet release 14 | - Update to latest protocol dependencies 15 | - Update tests 16 | - Update contract address (breaking change) 17 | 18 | 2023-03-27 (v2.2.1) 19 | ------------------- 20 | 21 | - Fix: Force did and usernames to be lower case 22 | - Split unit tests into read v read/write 23 | 24 | 2023-03-10 (v2.2.0) 25 | ------------------- 26 | 27 | - Gracefully handle full DID supplied to getUsernames() 28 | - Replace `chainNameorId` with `network` based on `EnvironmentType` 29 | - General code cleanup 30 | - Improve README to explain `read only` v `read and write` mode 31 | - Simplify configuration 32 | - Improve error messages 33 | - Support looking up usernames from the cache 34 | - Update unit tests 35 | 36 | 2022-03-01 (v2.1.3) 37 | ------------------- 38 | 39 | - Improve documentation in README.md 40 | - Simplify library usage 41 | - Support auto-detected `readOnly` mode that supports getting DIDs and Usernames, but not writing to the blockchain 42 | - Add username / DID in memory lookup cache 43 | 44 | 2023-02-09 (v2.0.5) 45 | ------------------- 46 | 47 | - Initial release -------------------------------------------------------------------------------- /packages/vda-name-client/Test.md: -------------------------------------------------------------------------------- 1 | # VDA Name Client Test 2 | 3 | Here explains the stuffs related to testing this `@verida-js/vda-name-client` package. 4 | 5 | ## Limit of names per DID 6 | The test code assumes that the `maxNamesPerDID` value in the contract is more than 2. 7 | 8 | 9 | -------------------------------------------------------------------------------- /packages/vda-name-client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@verida/vda-name-client", 3 | "version": "4.4.1", 4 | "description": "Client to manage adding and fetching names from the blockchain", 5 | "main": "build/src/index.js", 6 | "types": "build/src/index.d.ts", 7 | "files": [ 8 | "build/src" 9 | ], 10 | "directories": { 11 | "src": "src", 12 | "test": "tests" 13 | }, 14 | "license": "Apache-2.0", 15 | "keywords": [], 16 | "scripts": { 17 | "tests": "ts-mocha './test/**/*.tests.ts'", 18 | "test": "ts-mocha --timeout 200000", 19 | "lint": "gts lint", 20 | "clean": "gts clean", 21 | "compile": "rm -rf build && tsc", 22 | "build": "rm -rf build && tsc", 23 | "fix": "gts fix", 24 | "prepare": "npm run compile" 25 | }, 26 | "dependencies": { 27 | "@ethersproject/providers": "^5.7.2", 28 | "@verida/helpers": "^4.4.1", 29 | "@verida/types": "^4.4.1", 30 | "@verida/vda-client-base": "^4.4.1", 31 | "@verida/web3": "^4.4.1", 32 | "axios": "^0.27.2", 33 | "ethers": "^5.7.0" 34 | }, 35 | "devDependencies": { 36 | "@verida/vda-common-test": "^4.0.1", 37 | "dotenv": "^16.0.3", 38 | "gts": "^3.1.0", 39 | "mocha": "^10.1.0", 40 | "ts-mocha": "^10.0.0", 41 | "ts-node": "^10.7.0", 42 | "typescript": "^4.6.4" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /packages/vda-name-client/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './blockchain/blockchainApi' -------------------------------------------------------------------------------- /packages/vda-name-client/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "rootDir": ".", 6 | "outDir": "build", 7 | "sourceMap": true, 8 | "strict": true, 9 | "declaration": true, 10 | "esModuleInterop": true, 11 | "skipLibCheck": true 12 | }, 13 | "include": [ 14 | "src/**/*.ts", 15 | ], 16 | "exclude": ["node_modules", "test", "build"], 17 | "lib": [ 18 | "es5", 19 | "es2015" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /packages/vda-node-client/.env.example: -------------------------------------------------------------------------------- 1 | ## These are used for test only. 2 | PRIVATE_KEY = "" 3 | RPC_URL="" 4 | -------------------------------------------------------------------------------- /packages/vda-node-client/.gitignore: -------------------------------------------------------------------------------- 1 | #Ignore all files starting with "." 2 | .* 3 | !/.gitignore 4 | 5 | # node_modules in all sub directories 6 | **node_modules 7 | 8 | # build 9 | dist/ 10 | lib/ 11 | build/ -------------------------------------------------------------------------------- /packages/vda-node-client/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2024-07-15 (v.4.0.0) 2 | ------------------- 3 | 4 | - Support BlockchainAnchor and Verida Network refactor 5 | - Updated test files 6 | - Updated `.env.example` file 7 | 8 | 2024-06-13 (v) 9 | ------------------- 10 | 11 | - Added `locking` feature 12 | - Updated test files 13 | 14 | 2024-03-15 (v3.0.2) 15 | ------------------- 16 | 17 | - Added pagination for `getNodesBy...()` functions 18 | 19 | 2024-03-15 (v3.0.0) 20 | ------------------- 21 | 22 | - Initial release -------------------------------------------------------------------------------- /packages/vda-node-client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@verida/vda-node-client", 3 | "version": "4.4.1", 4 | "description": "Client library that read nodat & datacentre information.", 5 | "main": "build/src/index.js", 6 | "types": "build/src/index.d.ts", 7 | "files": [ 8 | "build/src" 9 | ], 10 | "directories": { 11 | "src": "src", 12 | "test": "tests" 13 | }, 14 | "license": "Apache-2.0", 15 | "keywords": [], 16 | "scripts": { 17 | "tests": "ts-mocha './test/**/*.test.ts'", 18 | "test": "ts-mocha --timeout 200000", 19 | "lint": "gts lint", 20 | "clean": "gts clean", 21 | "compile": "rm -rf build && tsc", 22 | "build": "rm -rf build && tsc", 23 | "fix": "gts fix", 24 | "prepare": "npm run compile" 25 | }, 26 | "dependencies": { 27 | "@ethersproject/providers": "^5.7.2", 28 | "@verida/types": "^4.4.1", 29 | "@verida/vda-common": "^4.4.1", 30 | "axios": "^0.27.2", 31 | "ethers": "^5.7.0" 32 | }, 33 | "devDependencies": { 34 | "@verida/vda-common-test": "^4.0.1", 35 | "dotenv": "^16.0.3", 36 | "gts": "^3.1.0", 37 | "mocha": "^10.1.0", 38 | "ts-mocha": "^10.0.0", 39 | "ts-node": "^10.7.0", 40 | "typescript": "^4.6.4" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /packages/vda-node-client/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './blockchain/blockchainApi' -------------------------------------------------------------------------------- /packages/vda-node-client/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES6", 4 | "module": "commonjs", 5 | "rootDir": ".", 6 | "outDir": "build", 7 | "sourceMap": true, 8 | "strict": true, 9 | "declaration": true, 10 | "esModuleInterop": true, 11 | "skipLibCheck": true 12 | }, 13 | "include": [ 14 | "src/**/*.ts", 15 | ], 16 | "exclude": ["node_modules", "test", "build"], 17 | } 18 | -------------------------------------------------------------------------------- /packages/vda-node-manager/.env.example: -------------------------------------------------------------------------------- 1 | ## These are used for test only. 2 | PRIVATE_KEY = "" 3 | RPC_URL="" 4 | # Token provider for testing `depositFromProvider()` function 5 | ## There should be MATIC token on this address to run the `approve()` function 6 | ## Request the contract owner to send Tokens for testing 7 | PROVIDER_KEY="" 8 | 9 | # Test chain : One of "POLAMOY", "POLPOS", "DEVNET" 10 | BLOCKCHAIN_ANCHOR = "POLAMOY" -------------------------------------------------------------------------------- /packages/vda-node-manager/.gitignore: -------------------------------------------------------------------------------- 1 | #Ignore all files starting with "." 2 | .* 3 | !/.gitignore 4 | 5 | # node_modules in all sub directories 6 | **node_modules 7 | 8 | # build 9 | dist/ 10 | lib/ 11 | build/ -------------------------------------------------------------------------------- /packages/vda-node-manager/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2024-07-15 (v.4.0.0) 2 | ------------------- 3 | 4 | - Support BlockchainAnchor and Verida Network refactor 5 | - Add a dependency to the `@verida/vda-client-base` 6 | - Added `Test.md` file 7 | - Updated .env.example file 8 | - Separated `stake_and_lock.test.ts` from the `user_write.test.ts` 9 | - Added `owner()` function 10 | - Updated test script to let general users run the `user_write.test.ts` 11 | 12 | 2024-03-22 (v3.0.2) 13 | ------------------- 14 | 15 | - Update the functions for `StorageNodeRegitry` contract 16 | 17 | 2024-03-15 (v3.0.0) 18 | ------------------- 19 | 20 | - Initial release -------------------------------------------------------------------------------- /packages/vda-node-manager/Test.md: -------------------------------------------------------------------------------- 1 | # VDA Node Manager Test 2 | 3 | Here explains stuffs related to test this `@verida/vda-node-manager` package. 4 | 5 | ## owner.test.ts 6 | - Only the contract owner can test this file. 7 | 8 | ## user_write.test.ts 9 | Before testing this file, `owner.test.ts` should be passed. The `owner.test.ts` mange trusted signers, registered nodes & removed nodes, and etc. 10 | 11 | - Anybody can test this file 12 | 13 | ## user_read.test.ts 14 | Before testing this file, `user_write.test.ts` should be passed. In the `user_write.test.ts`, it calls `addInitialData()` function to add necessary informations 15 | 16 | - Anybody can test this file 17 | 18 | 19 | ## stake_and_lock.test.ts 20 | This test file involves Token contract operations. Here, the `PRIVATE_KEY` in the `.env` file should be the owner of the Token contract. 21 | Can check the Token contract address by the `getVDATokenAddress()` function of the `VeridaNodeManager`. -------------------------------------------------------------------------------- /packages/vda-node-manager/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@verida/vda-node-manager", 3 | "version": "4.4.1", 4 | "description": "Client to manage storage nodes from the blockchain", 5 | "main": "build/index.js", 6 | "types": "build/index.d.ts", 7 | "files": [ 8 | "build" 9 | ], 10 | "directories": { 11 | "src": "src", 12 | "test": "tests" 13 | }, 14 | "license": "Apache-2.0", 15 | "keywords": [], 16 | "scripts": { 17 | "tests": "ts-mocha './test/**/*.test.ts'", 18 | "test": "ts-mocha --timeout 500000", 19 | "lint": "gts lint", 20 | "clean": "gts clean", 21 | "compile": "rm -rf build && tsc", 22 | "build": "rm -rf build && tsc", 23 | "fix": "gts fix", 24 | "prepare": "npm run compile" 25 | }, 26 | "devDependencies": { 27 | "chai": "^4.3.10", 28 | "dotenv": "^16.3.1", 29 | "gts": "^3.1.0", 30 | "mocha": "^10.2.0", 31 | "ts-node": "^10.9.1", 32 | "ts-patch": "^3.0.2", 33 | "typescript": "^5.2.2" 34 | }, 35 | "dependencies": { 36 | "@verida/helpers": "^4.4.1", 37 | "@verida/types": "^4.4.1", 38 | "@verida/vda-client-base": "^4.4.1", 39 | "@verida/web3": "^4.4.1", 40 | "axios": "^1.6.0", 41 | "ethers": "5.7.2" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /packages/vda-node-manager/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './blockchain/userApi' 2 | export * from './blockchain/ownerApi' -------------------------------------------------------------------------------- /packages/vda-node-manager/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ 4 | "module": "commonjs", /* Specify what module code is generated. */ 5 | "outDir": "build", /* Specify an output folder for all emitted files. */ 6 | // "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ 7 | // "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ 8 | "sourceMap": true, 9 | "strict": true, /* Enable all strict type-checking options. */ 10 | "declaration": true, 11 | "esModuleInterop": true, 12 | "skipLibCheck": true, /* Skip type checking all .d.ts files. */ 13 | "plugins": [ 14 | {"transform": "ts-macros"} 15 | ] 16 | }, 17 | "include": [ 18 | "src/**/*.ts", 19 | ], 20 | "exclude": ["node_modules", "test", "build"], 21 | } 22 | -------------------------------------------------------------------------------- /packages/vda-reward-client/.env.example: -------------------------------------------------------------------------------- 1 | ## These are used for test only. 2 | PRIVATE_KEY = "" 3 | RPC_URL="" 4 | 5 | # Test chain : One of "POLAMOY", "POLPOS", "DEVNET" 6 | BLOCKCHAIN_ANCHOR = "POLAMOY" -------------------------------------------------------------------------------- /packages/vda-reward-client/.gitignore: -------------------------------------------------------------------------------- 1 | #Ignore all files starting with "." 2 | .* 3 | !/.gitignore 4 | 5 | # node_modules in all sub directories 6 | **node_modules 7 | 8 | # build 9 | dist/ 10 | lib/ 11 | build/ -------------------------------------------------------------------------------- /packages/vda-reward-client/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2024-07-15 (v.4.0.0) 2 | ------------------- 3 | 4 | - Support BlockchainAnchor and Verida Network refactor 5 | - Add a dependency to the `@verida/vda-client-base` 6 | - Updated test codes 7 | - Added `Test.md` file 8 | - Updated `.env.example` file 9 | - Added `owner()` function 10 | - Update test script to let general users run without adding initial data 11 | 12 | 2024-02-09 (v3.0.0) 13 | ------------------- 14 | 15 | - Initial version -------------------------------------------------------------------------------- /packages/vda-reward-client/Test.md: -------------------------------------------------------------------------------- 1 | # VDA Node Manager Test 2 | 3 | Here explains stuffs related to test this `@verida/vda-node-manager` package. 4 | 5 | ## Confirm the token addresses of the `StorageNodeRegistry` contract and `Reward` contract 6 | The Token contract addresses of `StorageNodeRegistry` contract and `Reward` contract should be the same. 7 | 8 | ### Check Token contract of `StorageNodeRegistry` 9 | Call the `getVDATokenAddress()` function of the `StorageNodeRegistry` contract 10 | ### Check Token contract of `Reward` contract 11 | Call the `getTokenAddress()` function of the `Reward` contract 12 | 13 | ## owner.test.ts 14 | Only the contract owner can test this file. 15 | 16 | ## user_write.test.ts 17 | - Add initial data 18 | There are some stuffs to be done before testing this file. Before running this test files, trusted signers and claim types should be added. This can be done by only the contract owner. 19 | If users try to test this `user_write.test.ts` file before the contract owner does, they'd face the errors. 20 | 21 | - Get received the token to the `Reward` contract 22 | Request the Token contract owner to send tokens to the `Reward` contract address 23 | 24 | ## user_read.test.ts 25 | - Anybody can test this file 26 | -------------------------------------------------------------------------------- /packages/vda-reward-client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@verida/vda-reward-client", 3 | "version": "4.4.1", 4 | "description": "Client to manage reward", 5 | "main": "build/index.js", 6 | "types": "build/index.d.ts", 7 | "files": [ 8 | "build/" 9 | ], 10 | "directories": { 11 | "src": "src", 12 | "test": "tests" 13 | }, 14 | "license": "Apache-2.0", 15 | "keywords": [], 16 | "scripts": { 17 | "tests": "ts-mocha './test/**/*.test.ts'", 18 | "test": "ts-mocha --timeout 500000", 19 | "lint": "gts lint", 20 | "clean": "gts clean", 21 | "compile": "rm -rf build && tsc", 22 | "build": "rm -rf build && tsc", 23 | "fix": "gts fix", 24 | "prepare": "npm run compile" 25 | }, 26 | "dependencies": { 27 | "@ethersproject/providers": "^5.7.2", 28 | "@verida/encryption-utils": "^4.0.1", 29 | "@verida/helpers": "^4.4.1", 30 | "@verida/types": "^4.4.1", 31 | "@verida/vda-client-base": "^4.4.1", 32 | "@verida/web3": "^4.4.1" 33 | }, 34 | "devDependencies": { 35 | "@verida/vda-common-test": "^4.0.1", 36 | "dotenv": "^16.0.3", 37 | "ethers": "5.7.0", 38 | "gts": "^3.1.0", 39 | "mocha": "^10.1.0", 40 | "ts-mocha": "^10.0.0", 41 | "ts-node": "^10.7.0", 42 | "typescript": "^4.6.4" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /packages/vda-reward-client/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './blockchain/userApi' 2 | export * from './blockchain/ownerApi' -------------------------------------------------------------------------------- /packages/vda-reward-client/test/const.ts: -------------------------------------------------------------------------------- 1 | export interface ClaimType { 2 | id: string 3 | reward: bigint 4 | schema: string 5 | } 6 | 7 | export const CLAIM_TYPES : ClaimType[] = [ 8 | { 9 | id: "facebook", 10 | reward: 100n, 11 | schema: "https://common.schemas.verida.io/social/creds/facebook" 12 | }, 13 | { 14 | id: "twitter", 15 | reward: 150n, 16 | schema: "https://common.schemas.verida.io/social/creds/twitter" 17 | }, 18 | ] 19 | -------------------------------------------------------------------------------- /packages/vda-reward-client/test/user_read.test.ts: -------------------------------------------------------------------------------- 1 | require('dotenv').config(); 2 | import { getBlockchainAPIConfiguration } from "@verida/vda-common-test" 3 | import { BlockchainAnchor } from "@verida/types"; 4 | import { addInitialData } from "./helpers"; 5 | import { CLAIM_TYPES } from "./const"; 6 | import { VeridaRewardClient } from "../src/blockchain/userApi"; 7 | 8 | const assert = require('assert') 9 | 10 | const privateKey = process.env.PRIVATE_KEY 11 | if (!privateKey) { 12 | throw new Error('No PRIVATE_KEY in the env file'); 13 | } 14 | const configuration = getBlockchainAPIConfiguration(privateKey); 15 | 16 | 17 | const createRewardClientAPI = () => { 18 | return new VeridaRewardClient({ 19 | blockchainAnchor: BlockchainAnchor.DEVNET, 20 | }) 21 | } 22 | 23 | describe("Verida RewardOwnerApi Test in Read mode", function() { 24 | let rewardClientApi; 25 | this.timeout(100 * 1000) 26 | 27 | before(async () => { 28 | await addInitialData(configuration); 29 | rewardClientApi = createRewardClientAPI(); 30 | }) 31 | 32 | it("Get claim type",async () => { 33 | for (let i = 0; i < CLAIM_TYPES.length; i++) { 34 | const response = await rewardClientApi.getClaimType(CLAIM_TYPES[i].id); 35 | assert.equal(response.reward, CLAIM_TYPES[i].reward); 36 | } 37 | }) 38 | 39 | it("Get token address",async () => { 40 | const response = await rewardClientApi.getTokenAddress(); 41 | assert.ok(response && typeof(response) === `string`, 'Get the result'); 42 | }) 43 | 44 | it("Get `StorageNodeContract` address",async () => { 45 | const response = await rewardClientApi.getStorageNodeContractAddress(); 46 | assert.ok(response && typeof(response) === `string`, 'Get the result'); 47 | }) 48 | 49 | }) -------------------------------------------------------------------------------- /packages/vda-reward-client/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "rootDir": ".", 6 | "outDir": "build", 7 | "sourceMap": true, 8 | "strict": true, 9 | "declaration": true, 10 | "esModuleInterop": true, 11 | "skipLibCheck": true 12 | }, 13 | "include": [ 14 | "src/**/*.ts", 15 | ], 16 | "exclude": ["node_modules", "test", "build"], 17 | "lib": [ 18 | "es5", 19 | "es2015" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /packages/vda-sbt-client/.env.example: -------------------------------------------------------------------------------- 1 | ## These are used for test only. 2 | PRIVATE_KEY = "" 3 | RPC_URL="" 4 | 5 | # @verida/types/Network values : "LOCAL", "DEVNET", "BANKSIA", "MYRTLE" 6 | TEST_NETWORK="BANKSIA" -------------------------------------------------------------------------------- /packages/vda-sbt-client/.gitignore: -------------------------------------------------------------------------------- 1 | #Ignore all files starting with "." 2 | .* 3 | !/.gitignore 4 | 5 | # node_modules in all sub directories 6 | **node_modules 7 | 8 | # build 9 | dist/ 10 | lib/ 11 | build/ -------------------------------------------------------------------------------- /packages/vda-sbt-client/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2024-07-15 (v.4.0.0) 2 | ------------------- 3 | 4 | - Support BlockchainAnchor and Verida Network refactor 5 | - Updated `proof` releated test code 6 | - Added `Test.md` 7 | - Updated test script 8 | 9 | 2023-12-26 (v3.0.0) 10 | ------------------- 11 | 12 | - Mainnet release 13 | - Update data type of `tokenID` as `BigNumberish` from `number` 14 | 15 | 2023-04-27 (v2.3.4) 16 | ------------------- 17 | 18 | - Update contract name of ABI 19 | 20 | 2023-04-20 (v2.3.0) 21 | ------------------- 22 | 23 | - Update to latest protocol dependencies 24 | - Update tests 25 | - Update contract address (breaking change) 26 | 27 | 2023-03-27 (v2.2.1) 28 | ------------------- 29 | 30 | - Fix tests 31 | - Updated `isSBTClaimed()` function 32 | - Added `getClaimedSBTList()` function 33 | - Updated test code 34 | 35 | 2023-03-07 (v2.1.4) 36 | ------------------- 37 | 38 | - Improve documentation in README.md 39 | - Simplify usage 40 | - Improve code comments 41 | - Add error reason for failed claims 42 | - Fix bug with signing mint request 43 | 44 | 2023-02-09 (v2.0.5) 45 | ------------------- 46 | 47 | - Initial release -------------------------------------------------------------------------------- /packages/vda-sbt-client/Test.md: -------------------------------------------------------------------------------- 1 | # VDA Node Manager Test 2 | 3 | Here explains stuffs related to test this `@verida/vda-node-manager` package. 4 | 5 | - Add trusted signers 6 | The contract owner should add `TRUSTED_SIGNER` in the `@verida/vda-common-test/src/const.ts`(`0x0162aE4B571E9daB51309f885200aDdF04F33747`) 7 | 8 | - Enough Matic in `RECIPIENT` wallet 9 | `RECIPIENT_WALLET` in the `verida/vda-common-test/src/const.ts` should have enough matic to make transactions. (`0xeea7e0781317408d84aD70d1AA8c7553D3D31cA5`) -------------------------------------------------------------------------------- /packages/vda-sbt-client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@verida/vda-sbt-client", 3 | "version": "4.4.4", 4 | "description": "Client to manage adding and fetching names from the blockchain", 5 | "main": "build/src/index.js", 6 | "types": "build/src/index.d.ts", 7 | "files": [ 8 | "build/src" 9 | ], 10 | "directories": { 11 | "src": "src", 12 | "test": "tests" 13 | }, 14 | "license": "Apache-2.0", 15 | "keywords": [], 16 | "scripts": { 17 | "tests": "ts-mocha './test/**/*.test.ts'", 18 | "test": "ts-mocha --timeout 200000", 19 | "lint": "gts lint", 20 | "clean": "gts clean", 21 | "compile": "rm -rf build && tsc", 22 | "build": "rm -rf build && tsc", 23 | "fix": "gts fix", 24 | "prepare": "npm run compile" 25 | }, 26 | "dependencies": { 27 | "@ethersproject/providers": "^5.7.2", 28 | "@verida/helpers": "^4.4.1", 29 | "@verida/web3": "^4.4.1", 30 | "axios": "^0.27.2", 31 | "ethers": "^5.7.0" 32 | }, 33 | "devDependencies": { 34 | "@verida/account-node": "^4.4.4", 35 | "@verida/client-ts": "^4.4.4", 36 | "@verida/keyring": "^4.4.1", 37 | "@verida/vda-common-test": "^4.0.1", 38 | "dotenv": "^16.0.3", 39 | "gts": "^3.1.0", 40 | "mocha": "^10.1.0", 41 | "ts-mocha": "^10.0.0", 42 | "ts-node": "^10.7.0", 43 | "typescript": "^4.6.4" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /packages/vda-sbt-client/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './blockchain/blockchainApi' -------------------------------------------------------------------------------- /packages/vda-sbt-client/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "rootDir": ".", 6 | "outDir": "build", 7 | "sourceMap": true, 8 | "strict": true, 9 | "declaration": true, 10 | "esModuleInterop": true, 11 | "skipLibCheck": true 12 | }, 13 | "include": [ 14 | "src/**/*.ts", 15 | ], 16 | "exclude": ["node_modules", "test", "build"], 17 | "lib": [ 18 | "es5", 19 | "es2015" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /packages/vda-token-client/.env.example: -------------------------------------------------------------------------------- 1 | ## These are used for test only. 2 | PRIVATE_KEY = "" 3 | RPC_URL="" 4 | 5 | # Test chain : One of "POLAMOY", "POLPOS", "DEVNET" 6 | BLOCKCHAIN_ANCHOR = "POLAMOY" -------------------------------------------------------------------------------- /packages/vda-token-client/.gitignore: -------------------------------------------------------------------------------- 1 | #Ignore all files starting with "." 2 | .* 3 | !/.gitignore 4 | 5 | # node_modules in all sub directories 6 | **node_modules 7 | 8 | # build 9 | dist/ 10 | lib/ 11 | build/ -------------------------------------------------------------------------------- /packages/vda-token-client/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2023-07-12 (v) 2 | ------------------- 3 | 4 | - Initial release -------------------------------------------------------------------------------- /packages/vda-token-client/README.md: -------------------------------------------------------------------------------- 1 | 2 | # VDA Token Client 3 | 4 | A client library to managet Verida Tokens 5 | 6 | ## Dependencies 7 | This package dependes on the following `verida-js` packages: 8 | - `@verida/types` 9 | - `@verida/helpers` 10 | - `@verida/vda-common` 11 | - `@verida/vda-web3` 12 | 13 | And dependes on the following packages for test: 14 | - `@verida/vda-common-test` 15 | 16 | ## Installation 17 | 18 | ``` 19 | yarn add @verida/vda-token-client 20 | ``` 21 | 22 | ## Usage 23 | 24 | There are 2 classes of `VeridaTokenClient` and `VeridaTokenOwner`.
25 | - `VeridaTokenClient` is for general users to mange VDA tokens. 26 | - `VeridaTokenOwner` adds the owner-specific functions to the `VeridaTokenClient`. 27 | 28 | These classes can be run in 2 modes of __*read-only*__ and __*read & write*__.
29 | If you provided `privateKey` field in the configuration while creating the instance, it runs in __*read & write*__ mode, otherwise it runs in __*read-only*__ mode. 30 | 31 | In the __*read-only*__ mode, it can calls only the `view` functions of the contract. 32 | 33 | ### Read Only 34 | 35 | Setup the library in `read only`: 36 | 37 | ```ts 38 | import { VeridaTokenClient } from '@verida/vda-token-client' 39 | import { BlockchainAnchor } from '@verida/types' 40 | 41 | // Create token Client 42 | const blockchainAnchor = BlockchainAnchor.POLAMOY; 43 | const rpcUrl = ``; // This is optional 44 | const tokenClient = await VeridaTokenClient.CreateAsync({ 45 | blockchainAnchor, 46 | rpcUrl 47 | }) 48 | ``` 49 | 50 | #### *Example:* Get total supply 51 | 52 | ```ts 53 | const value:BigNumber = await tokenClient.totalSupply(); 54 | ``` 55 | 56 | ### Read and Write 57 | 58 | ```ts 59 | import { VeridaTokenClient } from '@verida/vda-token-client' 60 | import { BlockchainAnchor } from '@verida/types' 61 | 62 | const blockchainAnchor = BlockchainAnchor.POLAMOY; 63 | const rpcUrl = ``; // This is optional 64 | const privateKey = ``; 65 | const tokenClient = await VeridaTokenClient.CreateAsync({ 66 | blockchainAnchor, 67 | privateKey, 68 | rpcUrl 69 | }) 70 | ``` 71 | 72 | #### *Example:* Transfer token 73 | 74 | ```ts 75 | const to = `0x...`; // Recipient address 76 | const amount = BigNumber.from(10); 77 | await tokenClient.transfer(to, amount); 78 | ``` 79 | -------------------------------------------------------------------------------- /packages/vda-token-client/Test.md: -------------------------------------------------------------------------------- 1 | # VDA Token Client Test 2 | 3 | Here explains stuffs related to test this `@verida/vda-token-client` package. 4 | 5 | ## owner.test.ts 6 | - Only the contract owner can test this file 7 | 8 | ## read.test.ts 9 | - Anybody can test this file 10 | 11 | ## write.test.ts 12 | Please check following before run this test: 13 | - Token balances of following addresses:
14 | ```ts 15 | 0x8Ec5df9Ebc9554CECaA1067F974bD34735d3e539: More than `AMOUNT_SEND`(=1000) tokens 16 | 0xE3A441c4e699433FCf1262246Cf323d8e4302998: More than `AMOUNT_APPROVE`(=1000) tokens 17 | ``` 18 | 19 | - Enough Matic in following addresses: 20 | ```ts 21 | 0x8Ec5df9Ebc9554CECaA1067F974bD34735d3e539, 22 | 0xE3A441c4e699433FCf1262246Cf323d8e4302998 23 | ``` -------------------------------------------------------------------------------- /packages/vda-token-client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@verida/vda-token-client", 3 | "version": "4.4.1", 4 | "description": "Client to manage Verida token", 5 | "main": "build/src/index.js", 6 | "types": "build/src/index.d.ts", 7 | "files": [ 8 | "build/src" 9 | ], 10 | "directories": { 11 | "src": "src", 12 | "test": "tests" 13 | }, 14 | "license": "Apache-2.0", 15 | "keywords": [], 16 | "scripts": { 17 | "tests": "ts-mocha './test/**/*.tests.ts'", 18 | "test": "ts-mocha --timeout 200000", 19 | "lint": "gts lint", 20 | "clean": "gts clean", 21 | "compile": "rm -rf build && tsc", 22 | "build": "rm -rf build && tsc", 23 | "fix": "gts fix", 24 | "prepare": "npm run compile" 25 | }, 26 | "dependencies": { 27 | "@ethersproject/providers": "^5.7.2", 28 | "@verida/helpers": "^4.4.1", 29 | "@verida/types": "^4.4.1", 30 | "@verida/web3": "^4.4.1", 31 | "axios": "^0.27.2", 32 | "ethers": "^5.7.0" 33 | }, 34 | "devDependencies": { 35 | "@verida/vda-common-test": "^4.0.1", 36 | "dotenv": "^16.0.3", 37 | "gts": "^3.1.0", 38 | "mocha": "^10.1.0", 39 | "ts-mocha": "^10.0.0", 40 | "ts-node": "^10.7.0", 41 | "typescript": "^4.6.4" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /packages/vda-token-client/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './blockchain/VeridaTokenClient' 2 | export * from './blockchain/VeridaTokenOwner' -------------------------------------------------------------------------------- /packages/vda-token-client/test/const.ts: -------------------------------------------------------------------------------- 1 | import { BlockchainAnchor } from "@verida/types" 2 | import { VeridaTokenOwner } from "../src" 3 | import { BigNumber, Wallet } from "ethers"; 4 | import { DID_LIST } from "@verida/vda-common-test"; 5 | 6 | export const TOKEN_SENDER = new Wallet(DID_LIST[0].privateKey); 7 | export const TOKEN_APPROVER = new Wallet(DID_LIST[1].privateKey); 8 | export const TOKEN_RECIVER = new Wallet(DID_LIST[2].privateKey); 9 | 10 | export const TOKEN_MINTER = new Wallet(DID_LIST[3].privateKey); -------------------------------------------------------------------------------- /packages/vda-token-client/test/utils.ts: -------------------------------------------------------------------------------- 1 | import { BlockchainAnchor } from "@verida/types" 2 | import { VeridaTokenOwner } from "../src" 3 | import { BigNumber, Wallet } from "ethers"; 4 | 5 | export interface IMintInformation { 6 | to: string 7 | amount: BigNumber 8 | } 9 | 10 | export const mintToken = async (ownerPrivateKey: string, blockchainAnchor: BlockchainAnchor, info: IMintInformation[], rpcUrl?: string) => { 11 | const tokenOwner = await VeridaTokenOwner.CreateAsync({ 12 | blockchainAnchor, 13 | privateKey: ownerPrivateKey, 14 | rpcUrl 15 | }); 16 | 17 | const contractOwner = await tokenOwner.owner(); 18 | const curKeyAddress = new Wallet(ownerPrivateKey).address; 19 | 20 | if (contractOwner.toLowerCase() !== curKeyAddress.toLowerCase()) { 21 | throw new Error(`Incorrect owner private key`); 22 | } 23 | 24 | for (let i = 0; i < info.length; i++) { 25 | await tokenOwner.mint(info[i].to, info[i].amount); 26 | } 27 | } 28 | 29 | // export const -------------------------------------------------------------------------------- /packages/vda-token-client/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "rootDir": ".", 6 | "outDir": "build", 7 | "sourceMap": true, 8 | "strict": true, 9 | "declaration": true, 10 | "esModuleInterop": true, 11 | "skipLibCheck": true 12 | }, 13 | "include": [ 14 | "src/**/*.ts", 15 | ], 16 | "exclude": ["node_modules", "test", "build"], 17 | "lib": [ 18 | "es5", 19 | "es2015" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /packages/vda-web3-client/.gitignore: -------------------------------------------------------------------------------- 1 | #Ignore all files starting with "." 2 | .* 3 | !/.gitignore 4 | 5 | # node_modules in all sub directories 6 | **node_modules 7 | 8 | # build 9 | build/ -------------------------------------------------------------------------------- /packages/vda-web3-client/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2024-07-15 (v.4.0.0) 2 | ------------------- 3 | 4 | - Support BlockchainAnchor and Verida Network refactor 5 | 6 | 2023-12-26 (v.3.0.0) 7 | ------------------- 8 | 9 | - Removed `web3` parameter in `Web3SelfTransactionConfig` 10 | 11 | 2023-12-26 (v3.0.0) 12 | ------------------- 13 | 14 | - Fix bugs in `pure` type function call 15 | 16 | 2023-10-29 (v2.4.1) 17 | ------------------- 18 | 19 | - Update `callMethod()` function to return BigNumber as BigNumber itself 20 | 21 | 2023-10-29 (v2.4.0) 22 | ------------------- 23 | 24 | - Mainnet release 25 | - Fix bugs in `pure` type function call 26 | - Update `callMethod()` function to return BigNumber as BigNumber itself 27 | - Feature: Updated gas configuration in `web3` mode 28 | 29 | 2023-04-27 (v2.3.3) 30 | ------------------- 31 | 32 | - Fix missing dependencies 33 | 34 | 2023-04-20 (v2.3.0) 35 | ------------------- 36 | 37 | - Update to latest protocol dependencies 38 | - Update tests 39 | - Update contract address (breaking change) 40 | - Contract whitelist for `meta-transaction-server` is generated automatically 41 | 42 | 2023-03-27 (v2.2.1) 43 | ------------------- 44 | 45 | - Fix tests 46 | 47 | 2022-03-01 (v2.1.3) 48 | ------------------- 49 | 50 | - Add `reason` and `errorObj` to blockchain errors that are raised 51 | 52 | 2023-01-27 (v2.0.4) 53 | ------------------- 54 | 55 | - Remove engine restriction of Node 14 only 56 | 57 | 2023-01-24 (v2.0.2) 58 | ------------------- 59 | 60 | - Upgrade to @verida/types 61 | 62 | 2023-01-17 (v2.0.1) 63 | ------------------- 64 | 65 | - Fix: Add missing axios dependency 66 | 67 | 2023-01-13 (v2.0.0) 68 | ------------------- 69 | 70 | - Initial implementation (v2.0.0 to be inline with the rest of the protocol) -------------------------------------------------------------------------------- /packages/vda-web3-client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@verida/web3", 3 | "version": "4.4.1", 4 | "description": "", 5 | "main": "build/src/index.js", 6 | "types": "build/src/index.d.ts", 7 | "files": [ 8 | "build/src" 9 | ], 10 | "license": "Apache-2.0", 11 | "keywords": [], 12 | "engines": { 13 | "node": ">=18.0.0" 14 | }, 15 | "scripts": { 16 | "tests": "ts-mocha './test/**/*.test.ts'", 17 | "test": "ts-mocha --timeout 100000", 18 | "lint": "gts lint", 19 | "clean": "gts clean", 20 | "copy": "cd src/contract && find . -name \"*.json\" | xargs cp --parents -t ../../build/src/contract && cd ../../", 21 | "compile": "rm -rf build && tsc", 22 | "build": "rm -rf build && tsc", 23 | "fix": "gts fix", 24 | "prepare": "npm run compile" 25 | }, 26 | "devDependencies": { 27 | "@types/chai": "^4.3.4", 28 | "@types/mocha": "^10.0.0", 29 | "@verida/vda-common-test": "^4.0.1", 30 | "chai": "^4.3.7", 31 | "dotenv": "^16.0.3", 32 | "gts": "^3.1.0", 33 | "loadsh": "^0.0.4", 34 | "mocha": "^10.1.0", 35 | "ts-node": "^10.7.0", 36 | "typescript": "^4.6.4" 37 | }, 38 | "dependencies": { 39 | "@ethersproject/bignumber": "^5.7.0", 40 | "@ethersproject/contracts": "^5.7.0", 41 | "@ethersproject/providers": "^5.7.2", 42 | "@verida/types": "^4.4.1", 43 | "@verida/vda-common": "^4.4.1", 44 | "axios": "^1.2.3", 45 | "ethers": "^5.7.2" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /packages/vda-web3-client/src/constants.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable prettier/prettier */ 2 | import { TContractNames } from '@verida/types'; 3 | import { NETWORK_DEFINITIONS} from '@verida/vda-common'; 4 | 5 | /** 6 | * Create whitelist of Verida contract addresses 7 | * @dev This is used for Meta Server transactions 8 | * @returns List of contract addresses 9 | */ 10 | function createContractWhiteList() { 11 | const contractList = new Array(); 12 | 13 | type ContractObject = Record; 14 | const contractProperties: ContractObject = { 15 | "didLinkage": undefined, 16 | "didRegistry": undefined, 17 | "nameRegistry": undefined, 18 | "reward": undefined, 19 | "storageNodeRegistry": undefined, 20 | "token": undefined, 21 | "solboundNFT": undefined 22 | }; 23 | const CONTRACT_NAMES = Object.keys(contractProperties) as (TContractNames)[]; 24 | 25 | let network: keyof typeof NETWORK_DEFINITIONS; 26 | for (network in NETWORK_DEFINITIONS ) { 27 | const networkData = NETWORK_DEFINITIONS[network]; 28 | 29 | CONTRACT_NAMES.forEach(contract => { 30 | if ( 31 | networkData[contract] !== null && 32 | !contractList.includes((networkData[contract]!).address.toLowerCase()) 33 | ) { 34 | contractList.push(networkData[contract]!.address.toLowerCase()); 35 | } 36 | }) 37 | } 38 | return contractList; 39 | } 40 | 41 | export const veridaContractWhiteList = createContractWhiteList() 42 | 43 | export const DEFAULT_JSON_RPC = 'http://127.0.0.1:8545/'; 44 | -------------------------------------------------------------------------------- /packages/vda-web3-client/src/index.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable prettier/prettier */ 2 | import { VeridaWeb3Config, Web3CallType } from '@verida/types' 3 | import { VeridaContract } from './VeridaContractBase' 4 | 5 | /** 6 | * Create VeridaContract instance - that is verida-web3-sdk instance 7 | * @param type - Smart contract interaction mode 8 | * @param config - Configuration to create Verida-web3-sdk instance 9 | * @returns VeridaContract instance 10 | */ 11 | export function getVeridaContract(type: Web3CallType, config: VeridaWeb3Config) { 12 | return new VeridaContract( 13 | type, 14 | config 15 | ) 16 | } 17 | 18 | export { VeridaContract } 19 | -------------------------------------------------------------------------------- /packages/vda-web3-client/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "rootDir": ".", 6 | "outDir": "build", 7 | "sourceMap": true, 8 | "strict": true, 9 | "declaration": true, 10 | "esModuleInterop": true, 11 | "skipLibCheck": true 12 | }, 13 | "include": [ 14 | "src/**/*.ts", 15 | "test/**/*.ts" 16 | ], 17 | "lib": [ 18 | "es5", 19 | "es2015" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /packages/verifiable-credentials/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | coverage 4 | apidocs 5 | dist 6 | lib 7 | yarn-error.log 8 | 9 | # Editor directories and files 10 | .idea 11 | .vscode 12 | *.suo 13 | *.ntvs* 14 | *.njsproj 15 | *.sln 16 | *.sw? 17 | 18 | -------------------------------------------------------------------------------- /packages/verifiable-credentials/README.md: -------------------------------------------------------------------------------- 1 | 2 | See https://developers.verida.io/docs/extensions/verifiable-credentials 3 | 4 | -------------------------------------------------------------------------------- /packages/verifiable-credentials/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@verida/verifiable-credentials", 3 | "version": "4.4.4", 4 | "main": "dist/index.js", 5 | "license": "ISC", 6 | "directories": { 7 | "src": "src", 8 | "test": "tests" 9 | }, 10 | "repository": "https://github.com/verida/verida-js.git", 11 | "scripts": { 12 | "tests": "ts-mocha './test/**/*.ts'", 13 | "test": "ts-mocha", 14 | "build": "rm -rf dist; tsc" 15 | }, 16 | "engines": { 17 | "node": ">=18.0.0" 18 | }, 19 | "dependencies": { 20 | "@verida/encryption-utils": "^4.0.1", 21 | "@verida/helpers": "^4.4.1", 22 | "@verida/types": "^4.4.1", 23 | "@verida/vda-did-resolver": "^4.4.2", 24 | "axios": "^1.3.3", 25 | "dayjs": "^1.10.7", 26 | "did-jwt": "^6.11.0", 27 | "did-jwt-vc": "3.1.0", 28 | "lodash": "^4.17.21", 29 | "tweetnacl-util": "^0.15.1", 30 | "url": "^0.11.0" 31 | }, 32 | "devDependencies": { 33 | "@types/lodash": "^4.14.177", 34 | "@verida/client-ts": "^4.4.4", 35 | "dotenv": "^16.0.3", 36 | "mocha": "^8.2.1", 37 | "ts-mocha": "^8.0.0", 38 | "ts-node": "^9.1.1", 39 | "typescript": "^4.1.3" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /packages/verifiable-credentials/src/index.ts: -------------------------------------------------------------------------------- 1 | import Credentials from './credentials'; 2 | import SharingCredential from './sharing-credential'; 3 | 4 | 5 | export { Credentials, SharingCredential }; 6 | export * from './interfaces'; 7 | -------------------------------------------------------------------------------- /packages/verifiable-credentials/src/interfaces.ts: -------------------------------------------------------------------------------- 1 | import { IContext } from "@verida/types"; 2 | 3 | export const VERIDA_CREDENTIAL_SCHEMA = 'https://common.schemas.verida.io/credential/base/v0.2.0/schema.json' 4 | 5 | export interface CreateCredentialOptions { 6 | expirationDate?: string; 7 | issuanceDate?: string; 8 | proofStrings?: Record; 9 | } 10 | 11 | export interface VCResult { 12 | item: any; 13 | result: any; 14 | did: string; 15 | veridaUri: string; 16 | publicUri: string; 17 | } 18 | 19 | export interface CreateCredentialJWT { 20 | options?: CreateCredentialOptions; 21 | subjectId: string; 22 | data: any; 23 | schema: string; 24 | context: IContext; 25 | payload?: Record; 26 | } 27 | 28 | export interface VeridaCredentialRecord { 29 | schema: string 30 | name: string 31 | summary?: string 32 | icon?: string 33 | didJwtVc: string 34 | credentialSchema: string 35 | credentialData: Record 36 | } 37 | 38 | export interface VeridaCredentialSchema { 39 | veridaProofs?: Record 40 | } 41 | 42 | export interface VerifiableCredentialResponse { 43 | vc: any, 44 | issuer: any 45 | } -------------------------------------------------------------------------------- /packages/verifiable-credentials/test/utils.ts: -------------------------------------------------------------------------------- 1 | import { AutoAccount } from '@verida/account-node'; 2 | import { Client, Context, Network } from '@verida/client-ts'; 3 | import { explodeVeridaUri } from '@verida/helpers'; 4 | import { ClientConfig, Network } from '@verida/types' 5 | import CONFIG from './config'; 6 | 7 | /** 8 | * 9 | * @param privateKey account private key unable creation of verida account 10 | * @param contextName application context name 11 | * @param environment network 12 | * @returns an application {context} of the connected account 13 | */ 14 | 15 | export async function connectAccount(privateKey: string, contextName: string, network: Network): Promise { 16 | const account = new AutoAccount( 17 | { 18 | network, 19 | didClientConfig: CONFIG.DID_CLIENT_CONFIG, 20 | privateKey: privateKey 21 | } 22 | ) 23 | 24 | const context = await Network.connect({ 25 | context: { 26 | name: contextName, 27 | }, 28 | client: { 29 | network 30 | }, 31 | account, 32 | }); 33 | 34 | return context as Context; 35 | }; 36 | 37 | /** 38 | * 39 | * @param uri vda decoded URI 40 | * @param environment current network 41 | * @returns an application {context} of the connected account 42 | */ 43 | export async function getClientContext(uri: string, environment: EnvironmentType): Promise { 44 | const clientConfig: ClientConfig = { 45 | environment: environment 46 | } 47 | 48 | const uriParts = explodeVeridaUri(uri) 49 | 50 | const context = await new Client(clientConfig).openExternalContext( 51 | uriParts.contextName, 52 | uriParts.did 53 | ); 54 | 55 | return context 56 | } -------------------------------------------------------------------------------- /packages/verifiable-credentials/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "declaration": true, 6 | "skipLibCheck": true, // disable TS checking of dependencies 7 | "outDir": "./dist", 8 | "strict": true, 9 | "sourceMap": true, 10 | "lib": [ 11 | "es5", 12 | "es2015" 13 | ], 14 | "esModuleInterop": true 15 | }, 16 | "include": ["src"], 17 | "exclude": ["node_modules", "test", "dist"] 18 | } -------------------------------------------------------------------------------- /packages/web-helpers/.gitignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | node_modules/ -------------------------------------------------------------------------------- /packages/web-helpers/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2024-07-15 (v.4.0.0) 2 | ------------------- 3 | 4 | - Support BlockchainAnchor and Verida Network refactor 5 | 6 | 2023-12-26 (v.3.1.0) 7 | ------------------- 8 | 9 | - Mainnet release 10 | - Fix: Unable to re-open modal after closing (`WebUser.connecting` wasn't being reset) 11 | 12 | 2023-08-22 (v3.0.2) 13 | ------------------- 14 | 15 | - Fix `WebUser.connect` crashing when getting public profile 16 | 17 | 2023-08-22 (v3.0.0) 18 | ------------------- 19 | 20 | ## Breaking Changes 21 | 22 | - Refactoring of `WebUser`: 23 | - `getClient`, `getContext`, `getAccount`, `getDid` and `isConnected` are no longer asynchronous, they return their respective output directly 24 | - `isConnected` doesn't automatically connect if there's an existing session, use `autoConnectExistingSession` instead for tist specific purpose. 25 | 26 | ## Bug Fixes 27 | 28 | - Fix `WebUser` using previous Identity profile after disconnecting and connecting with a different one. 29 | 30 | 2023-04-20 (v2.3.0) 31 | ------------------- 32 | 33 | - Update to latest protocol dependencies 34 | 35 | 2023-02-09 (v2.0.5) 36 | ------------------- 37 | 38 | - First release (migrated `WebUser` from `account-web-vault`) 39 | -------------------------------------------------------------------------------- /packages/web-helpers/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Web Tools 3 | 4 | Helper libraries and methods for using Verida in a Web Browser environment -------------------------------------------------------------------------------- /packages/web-helpers/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@verida/web-helpers", 3 | "version": "4.4.4", 4 | "main": "dist/index.js", 5 | "license": "ISC", 6 | "directories": { 7 | "src": "src", 8 | "test": "tests" 9 | }, 10 | "repository": "https://github.com/verida/verida-js.git", 11 | "scripts": { 12 | "build": "rm -rf dist/ && tsc" 13 | }, 14 | "engines": { 15 | "node": ">=18.0.0" 16 | }, 17 | "dependencies": { 18 | "@verida/account-web-vault": "^4.4.4", 19 | "@verida/client-ts": "^4.4.4", 20 | "@verida/types": "^4.4.1" 21 | }, 22 | "devDependencies": { 23 | "mocha": "^8.2.1", 24 | "ts-mocha": "^8.0.0", 25 | "ts-node": "^9.1.1", 26 | "typescript": "^4.1.3" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/web-helpers/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./WebUser" -------------------------------------------------------------------------------- /packages/web-helpers/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "declaration": true, 6 | "skipLibCheck": true, // disable TS checking of dependencies 7 | "outDir": "./dist", 8 | "strict": true, 9 | "sourceMap": true, 10 | "lib": [ 11 | "es5", 12 | "dom" 13 | ] 14 | }, 15 | "include": ["src"], 16 | "exclude": ["node_modules", "test", "dist"] 17 | } -------------------------------------------------------------------------------- /publish.sh: -------------------------------------------------------------------------------- 1 | npx lerna run build 2 | # Tag next=upcoming version, latest=current latest version 3 | npx lerna publish --dist-tag next 4 | # If publishing `latest` from `main` branch, need to merge changes back into `develop` branch -------------------------------------------------------------------------------- /releases/2.3.0.md: -------------------------------------------------------------------------------- 1 | ## v2.3.0 Release Notes (2023-04-20) 2 | 3 | This release includes some breaking changes that are important to be aware of. 4 | 5 | 1. When using `account-node` (server applications or mobile wallets), you no longer need to provide a list of storage nodes to connect. You can provide a `countryCode` to the `AutoAccount` constructor and it will automatically chose random storage nodes in your country. If there are none for your country, it will fallback to your region (ie: `Europe`) and if still none in your region, fallback to random global nodes. It is still possible to specify your own nodes (ie: If you self host or are part of a network of private nodes) 6 | 2. The smart contract addresses have changed on `testnet`. This means any existing DIDs created will no longer work and all data has been cleared from the network. This is not ideal, however there were some gas efficiency improvements that were identified in our latest protocol audit. It was decided that for consistency, those improvements should be deployed to `testnet`. These changes impacted the structure and order of state variables so there was no way to upgrade our existing contracts with these improvements. Moving forward, there will be no further clearing of DID's on the network. 7 | 8 | Other changes include: 9 | 10 | 1. Supporting `devnet` network in addition to `testnet`. `devnet` supports it's own network of storage nodes, but shares the same `testnet` Mumbai smart contract for managing DIDs 11 | 2. Updating all the tests to support automatically selecting storage nodes, instead of manually providing them 12 | 3. Tidy up of `@verida/types` interfaces to better match implementation --------------------------------------------------------------------------------