@docknetwork/wallet-sdk-dids 0.4.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ {
2
+ "presets": [
3
+ [
4
+ "@babel/preset-env",
5
+ {
6
+ "targets": {
7
+ "node": "current"
8
+ },
9
+ "useBuiltIns": "usage",
10
+ "corejs": "3.6.5"
11
+ }
12
+ ]
13
+ ]
14
+ }
package/lib/index.js ADDED
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.DIDKeyManager = void 0;
7
+ var _didMethodKey = require("@digitalbazaar/did-method-key");
8
+ var _ed25519VerificationKey = require("@digitalbazaar/ed25519-verification-key-2020");
9
+ var _uuid = require("uuid");
10
+ const didKeyDriver = (0, _didMethodKey.driver)({
11
+ verificationSuite: _ed25519VerificationKey.Ed25519VerificationKey2020
12
+ });
13
+ const DID_DEFAULT_CONTEXT = ['https://w3id.org/wallet/v1', 'https://w3id.org/did-resolution/v1'];
14
+ const DIDKeyManager = function () {
15
+ const keypairToDIDKeyDocument = async keyDoc => {
16
+ const {
17
+ didDocument
18
+ } = await didKeyDriver._keyPairToDidDocument({
19
+ keyPair: {
20
+ ...keyDoc,
21
+ keyPair: keyDoc
22
+ }
23
+ });
24
+ return {
25
+ didDocument,
26
+ keyDoc
27
+ };
28
+ };
29
+ const getDIDResolution = (didDocument, didDocumentCustomProp = {}) => {
30
+ const expiryDate = new Date();
31
+ expiryDate.setFullYear(expiryDate.getFullYear() + 1000);
32
+ const {
33
+ name
34
+ } = didDocumentCustomProp;
35
+ return {
36
+ '@context': DID_DEFAULT_CONTEXT,
37
+ id: (0, _uuid.v4)(),
38
+ type: 'DIDResolutionResponse',
39
+ correlation: [],
40
+ created: new Date().toISOString(),
41
+ expires: expiryDate.toISOString(),
42
+ name,
43
+ didDocument
44
+ };
45
+ };
46
+ return {
47
+ keypairToDIDKeyDocument,
48
+ getDIDResolution
49
+ };
50
+ }();
51
+ exports.DIDKeyManager = DIDKeyManager;
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@docknetwork/wallet-sdk-dids",
3
+ "version": "0.4.19",
4
+ "license": "https://github.com/docknetwork/react-native-sdk/LICENSE",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/docknetwork/react-native-sdk.git",
8
+ "directory": "packages/dids"
9
+ },
10
+ "main": "lib/index.js",
11
+ "dependencies": {
12
+ "@digitalbazaar/did-method-key": "^2.0.0",
13
+ "uuid": "^8.3.2"
14
+ },
15
+ "scripts": {
16
+ "prepublishOnly": "npm run build",
17
+ "build": "rm -rf lib && NODE_ENV=production babel src/ --out-dir lib --copy-files"
18
+ },
19
+ "devDependencies": {
20
+ "@babel/cli": "^7.17.10",
21
+ "@babel/core": "^7.17.12",
22
+ "@babel/preset-env": "^7.17.12",
23
+ "@babel/polyfill": "^7.12.1",
24
+ "@babel/preset-react": "^7.17.12"
25
+ }
26
+ }
package/readme.md ADDED
@@ -0,0 +1,39 @@
1
+
2
+ # DID Manager
3
+
4
+ DID stands for Decentralized IDentifiers. DIDs are meant to be globally unique identifiers that allow their owner to prove cryptographic control over them. A DID identifies any subject (e.g., a person, organization, thing, data model, abstract entity, etc.) that the controller of the DID decides that it identifies.
5
+
6
+ On React Native it's required to set up the WalletSDKProvider, described on [@docknetwork/wallet-sdk-react-native](https://www.npmjs.com/package/@docknetwork/wallet-sdk-react-native)
7
+
8
+ Supports did:key
9
+
10
+ ```js
11
+ import {DIDKeyManager} from '@docknetwork/wallet-sdk-dids/lib';
12
+
13
+ // Create did document from keypair
14
+
15
+ const keyDoc = {
16
+ id: 'did:key:z6MkhN7PBjWgSMQ24Bebdpvvw8fVRv7m6MHDqiwTKozzBgrJ#z6MkhN7PBjWgSMQ24Bebdpvvw8fVRv7m6MHDqiwTKozzBgrJ',
17
+ controller: 'did:key:z6MkhN7PBjWgSMQ24Bebdpvvw8fVRv7m6MHDqiwTKozzBgrJ',
18
+ type: 'Ed25519VerificationKey2018',
19
+ publicKeyBase58: '3urLbVGF6ouYwgotxFy6637VcLqugU2s9i2XVY2yGU4v',
20
+ privateKeyBase58:
21
+ '3rF4Jhp7vF6tavGZCSgkdMM3ANLB7YpmzfRcB5FTs1Q7EgN6u5cCwzCaHCDYcestRSEHzjF82TvJUaj3mdqcbGnS',
22
+ publicKeyMultibase: 'z3urLbVGF6ouYwgotxFy6637VcLqugU2s9i2XVY2yGU4v',
23
+ privateKeyMultibase:
24
+ 'z3rF4Jhp7vF6tavGZCSgkdMM3ANLB7YpmzfRcB5FTs1Q7EgN6u5cCwzCaHCDYcestRSEHzjF82TvJUaj3mdqcbGnS',
25
+ };
26
+
27
+ const {didDocument, keyDoc: resKeyDoc} =
28
+ await DIDKeyManager.keypairToDIDKeyDocument(keyDoc);
29
+
30
+
31
+ // Get DID resolution
32
+
33
+ const didDocument = {
34
+ id: 'did:key:z6Mks8mvCnVx4HQcoq7ZwvpTbMnoRGudHSiEpXhMf6VW8XMg',
35
+ };
36
+
37
+ const didResolution = await DIDKeyManager.getDIDResolution(didDocument);
38
+
39
+ ```
package/src/index.js ADDED
@@ -0,0 +1,46 @@
1
+ import {driver} from '@digitalbazaar/did-method-key';
2
+ import {Ed25519VerificationKey2020} from '@digitalbazaar/ed25519-verification-key-2020';
3
+ import {v4 as uuidv4} from 'uuid';
4
+
5
+ const didKeyDriver = driver({
6
+ verificationSuite: Ed25519VerificationKey2020,
7
+ });
8
+
9
+ const DID_DEFAULT_CONTEXT = [
10
+ 'https://w3id.org/wallet/v1',
11
+ 'https://w3id.org/did-resolution/v1',
12
+ ];
13
+
14
+ export const DIDKeyManager = (function () {
15
+ const keypairToDIDKeyDocument = async keyDoc => {
16
+ const {didDocument} = await didKeyDriver._keyPairToDidDocument({
17
+ keyPair: {
18
+ ...keyDoc,
19
+ keyPair: keyDoc,
20
+ },
21
+ });
22
+ return {didDocument, keyDoc};
23
+ };
24
+
25
+ const getDIDResolution = (didDocument, didDocumentCustomProp = {}) => {
26
+ const expiryDate = new Date();
27
+ expiryDate.setFullYear(expiryDate.getFullYear() + 1000);
28
+
29
+ const {name} = didDocumentCustomProp;
30
+ return {
31
+ '@context': DID_DEFAULT_CONTEXT,
32
+ id: uuidv4(),
33
+ type: 'DIDResolutionResponse',
34
+ correlation: [],
35
+ created: new Date().toISOString(),
36
+ expires: expiryDate.toISOString(),
37
+ name,
38
+ didDocument,
39
+ };
40
+ };
41
+
42
+ return {
43
+ keypairToDIDKeyDocument,
44
+ getDIDResolution,
45
+ };
46
+ })();
@@ -0,0 +1,42 @@
1
+ import {DIDKeyManager} from '../src';
2
+
3
+ describe('DID module', () => {
4
+ it('Create DID key', async () => {
5
+ const keyDoc = {
6
+ id: 'did:key:z6MkhN7PBjWgSMQ24Bebdpvvw8fVRv7m6MHDqiwTKozzBgrJ#z6MkhN7PBjWgSMQ24Bebdpvvw8fVRv7m6MHDqiwTKozzBgrJ',
7
+ controller: 'did:key:z6MkhN7PBjWgSMQ24Bebdpvvw8fVRv7m6MHDqiwTKozzBgrJ',
8
+ type: 'Ed25519VerificationKey2018',
9
+ publicKeyBase58: '3urLbVGF6ouYwgotxFy6637VcLqugU2s9i2XVY2yGU4v',
10
+ privateKeyBase58:
11
+ '3rF4Jhp7vF6tavGZCSgkdMM3ANLB7YpmzfRcB5FTs1Q7EgN6u5cCwzCaHCDYcestRSEHzjF82TvJUaj3mdqcbGnS',
12
+ publicKeyMultibase: 'z3urLbVGF6ouYwgotxFy6637VcLqugU2s9i2XVY2yGU4v',
13
+ privateKeyMultibase:
14
+ 'z3rF4Jhp7vF6tavGZCSgkdMM3ANLB7YpmzfRcB5FTs1Q7EgN6u5cCwzCaHCDYcestRSEHzjF82TvJUaj3mdqcbGnS',
15
+ };
16
+
17
+ const {didDocument, keyDoc: resKeyDoc} =
18
+ await DIDKeyManager.keypairToDIDKeyDocument(keyDoc);
19
+
20
+ expect(didDocument).toBeDefined();
21
+ expect(resKeyDoc).toBeDefined();
22
+ expect(didDocument).toHaveProperty('@context');
23
+ expect(didDocument).toHaveProperty(
24
+ 'id',
25
+ 'did:key:z6MkhN7PBjWgSMQ24Bebdpvvw8fVRv7m6MHDqiwTKozzBgrJ',
26
+ );
27
+ });
28
+
29
+ it('Get Did Resolution', async () => {
30
+ const didDocument = {
31
+ id: 'did:key:z6Mks8mvCnVx4HQcoq7ZwvpTbMnoRGudHSiEpXhMf6VW8XMg',
32
+ };
33
+ const didResolution = await DIDKeyManager.getDIDResolution(didDocument);
34
+
35
+ expect(didResolution).toHaveProperty('id');
36
+ expect(didResolution).toHaveProperty('type', 'DIDResolutionResponse');
37
+ expect(didResolution).toHaveProperty('correlation', []);
38
+ expect(didResolution).toHaveProperty('created');
39
+ expect(didResolution).toHaveProperty('expires');
40
+ expect(didResolution).toHaveProperty('didDocument', didDocument);
41
+ });
42
+ });