@docknetwork/wallet-sdk-wasm 0.4.22 → 1.4.0

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.
Files changed (63) hide show
  1. package/lib/index.js +6 -6
  2. package/lib/index.mjs +10 -10
  3. package/lib/modules/account.js +4 -3
  4. package/lib/modules/account.mjs +4 -3
  5. package/lib/modules/accounts.js +4 -3
  6. package/lib/modules/accounts.mjs +4 -3
  7. package/lib/modules/wallet.js +4 -3
  8. package/lib/modules/wallet.mjs +4 -3
  9. package/lib/rpc-server.js +6 -6
  10. package/lib/rpc-server.mjs +10 -10
  11. package/lib/services/credential/bbs-revocation.js +21 -12
  12. package/lib/services/credential/bbs-revocation.mjs +21 -8
  13. package/lib/services/credential/index.js +6 -6
  14. package/lib/services/credential/index.mjs +7 -7
  15. package/lib/services/credential/service.js +6 -6
  16. package/lib/services/credential/service.mjs +7 -7
  17. package/lib/services/dids/index.js +6 -6
  18. package/lib/services/dids/index.mjs +7 -7
  19. package/lib/services/dids/service.js +23 -21
  20. package/lib/services/dids/service.mjs +22 -18
  21. package/lib/services/dock/index.js +3 -2
  22. package/lib/services/dock/index.mjs +3 -2
  23. package/lib/services/dock/service.js +15 -17
  24. package/lib/services/dock/service.mjs +15 -13
  25. package/lib/services/edv/index.js +6 -6
  26. package/lib/services/edv/index.mjs +9 -9
  27. package/lib/services/edv/service.js +6 -6
  28. package/lib/services/edv/service.mjs +9 -9
  29. package/lib/services/index.js +6 -6
  30. package/lib/services/index.mjs +10 -10
  31. package/lib/services/relay-service/index.mjs +1 -1
  32. package/lib/services/relay-service/service.mjs +2 -2
  33. package/lib/services/substrate/api-utils.js +3 -2
  34. package/lib/services/substrate/api-utils.mjs +3 -2
  35. package/lib/services/substrate/index.js +3 -2
  36. package/lib/services/substrate/index.mjs +3 -2
  37. package/lib/services/substrate/service.js +3 -2
  38. package/lib/services/substrate/service.mjs +3 -2
  39. package/lib/services/test-utils.js +3 -2
  40. package/lib/services/test-utils.mjs +3 -2
  41. package/lib/services/trust-registry/index.js +3 -2
  42. package/lib/services/trust-registry/index.mjs +3 -2
  43. package/lib/services/trust-registry/service.js +3 -2
  44. package/lib/services/trust-registry/service.mjs +3 -2
  45. package/lib/setup-nodejs.js +6 -6
  46. package/lib/setup-nodejs.mjs +10 -10
  47. package/lib/setup-tests.js +6 -6
  48. package/lib/setup-tests.mjs +10 -10
  49. package/lib/src/services/credential/bbs-revocation.d.ts.map +1 -1
  50. package/lib/src/services/dids/service.d.ts +4 -1
  51. package/lib/src/services/dids/service.d.ts.map +1 -1
  52. package/lib/src/services/dock/service.d.ts +8 -1
  53. package/lib/src/services/dock/service.d.ts.map +1 -1
  54. package/lib/test/setup-test-state.js +4 -3
  55. package/lib/test/setup-test-state.mjs +4 -3
  56. package/lib/tsconfig.tsbuildinfo +1 -1
  57. package/package.json +7 -2
  58. package/src/services/credential/bbs-revocation.ts +21 -17
  59. package/src/services/dids/index.test.js +27 -4
  60. package/src/services/dids/service.ts +37 -30
  61. package/src/services/dock/service.ts +21 -16
  62. /package/lib/{account-614e6414.js → account-3c88155a.js} +0 -0
  63. /package/lib/{account-ee524484.js → account-8f5cbc4d.js} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docknetwork/wallet-sdk-wasm",
3
- "version": "0.4.22",
3
+ "version": "1.4.0",
4
4
  "license": "https://github.com/docknetwork/react-native-sdk/LICENSE",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,7 +25,9 @@
25
25
  "@polkadot/util-crypto": "10.1.11"
26
26
  },
27
27
  "dependencies": {
28
+ "@astronautlabs/jsonpath": "^1.1.2",
28
29
  "@docknetwork/universal-wallet": "^2.0.1",
30
+ "@docknetwork/wallet-sdk-dids": "^1.4.0",
29
31
  "@polkadot/api": "9.7.1",
30
32
  "@polkadot/keyring": "10.1.11",
31
33
  "@polkadot/rpc-core": "9.7.1",
@@ -48,7 +50,10 @@
48
50
  "winston": "^3.3.3",
49
51
  "cwait": "1.1.2",
50
52
  "axios-retry": "^3.2.5",
51
- "@sphereon/pex": "^1.1.4"
53
+ "@sphereon/pex": "^1.1.4",
54
+ "@docknetwork/credential-sdk": "0.12.0",
55
+ "@docknetwork/dock-blockchain-api": "0.6.1",
56
+ "@docknetwork/dock-blockchain-modules": "0.8.0"
52
57
  },
53
58
  "devDependencies": {
54
59
  "@babel/node": "^7.16.0",
@@ -7,9 +7,9 @@ import {
7
7
  VBWitnessUpdateInfo,
8
8
  Encoder,
9
9
  } from '@docknetwork/crypto-wasm-ts';
10
- import dock from '@docknetwork/sdk';
11
10
 
12
11
  import {hexToU8a} from '@polkadot/util';
12
+ import { dockService } from '../dock/service';
13
13
 
14
14
  const trimHexID = id => {
15
15
  if (id.substr(0, 2) !== '0x') {
@@ -36,7 +36,9 @@ async function updateMembershipWitness({
36
36
 
37
37
  let updates = [];
38
38
  try {
39
- updates = await dock.accumulatorModule.getUpdatesFromBlock(
39
+ // TODO: Ensure it will for cheqd
40
+ // Will be handled on https://dock-team.atlassian.net/browse/DCKW-572
41
+ updates = await dockService.modules.accumulator.dockOnly.getUpdatesFromBlock(
40
42
  registryId,
41
43
  blockNo,
42
44
  );
@@ -64,17 +66,21 @@ async function updateMembershipWitness({
64
66
  }
65
67
  }
66
68
 
67
- const queriedWitnessInfo = new VBWitnessUpdateInfo(
68
- hexToU8a(updates[0].witnessUpdateInfo),
69
- );
69
+
70
70
  const witness = new VBMembershipWitness(hexToU8a(membershipWitness));
71
71
 
72
- witness.updateUsingPublicInfoPostBatchUpdate(
73
- member,
74
- additions,
75
- removals,
76
- queriedWitnessInfo,
77
- );
72
+ if (updates.length) {
73
+ const queriedWitnessInfo = new VBWitnessUpdateInfo(
74
+ hexToU8a(updates[0].witnessUpdateInfo),
75
+ )
76
+
77
+ witness.updateUsingPublicInfoPostBatchUpdate(
78
+ member,
79
+ additions,
80
+ removals,
81
+ queriedWitnessInfo,
82
+ );
83
+ }
78
84
 
79
85
  return witness;
80
86
  }
@@ -93,7 +99,7 @@ export const getWitnessDetails = async (credential, _membershipWitness) => {
93
99
  const registryId = credentialStatus?.id.replace('dock:accumulator:', '');
94
100
  const revocationIndex = credentialStatus.revocationId;
95
101
 
96
- const queriedAccumulator = await dock.accumulatorModule.getAccumulator(
102
+ const queriedAccumulator = await dockService.modules.accumulator.getAccumulator(
97
103
  registryId,
98
104
  false,
99
105
  );
@@ -102,19 +108,17 @@ export const getWitnessDetails = async (credential, _membershipWitness) => {
102
108
  throw new Error('Accumulator not found');
103
109
  }
104
110
 
105
- const accumulator = PositiveAccumulator.fromAccumulated(
106
- hexToU8a(queriedAccumulator.accumulated),
107
- );
111
+ const accumulator = PositiveAccumulator.fromAccumulated(queriedAccumulator.accumulated.bytes);
108
112
 
109
113
  const encodedRevId = Encoder.defaultEncodeFunc()(revocationIndex.toString());
110
114
 
111
- const publicKey = await dock.accumulatorModule.getPublicKeyByHexDid(
115
+ const publicKey = await dockService.modules.accumulator.getPublicKey(
112
116
  queriedAccumulator.keyRef[0],
113
117
  queriedAccumulator.keyRef[1],
114
118
  );
115
119
 
116
120
  const params = dockAccumulatorParams();
117
- const pk = new AccumulatorPublicKey(hexToU8a(publicKey.bytes));
121
+ const pk = new AccumulatorPublicKey(publicKey.bytes);
118
122
 
119
123
  let membershipWitness = new VBMembershipWitness(
120
124
  hexToU8a(witness),
@@ -5,7 +5,8 @@ import {validation} from './config';
5
5
  import {DIDKeyManager} from '@docknetwork/wallet-sdk-dids/src';
6
6
  import {TestFixtures} from '../../fixtures';
7
7
  import {getTestWallet} from '../../test/setup-test-state';
8
- import {getDock} from '../dock/service';
8
+ import {dockService, getDock} from '../dock/service';
9
+ import {DockDid} from '@docknetwork/credential-sdk/types';
9
10
 
10
11
  describe('DID Service', () => {
11
12
  beforeAll(async () => {
@@ -99,6 +100,18 @@ describe('DID Service', () => {
99
100
  });
100
101
 
101
102
  it('expect to register did dock', async () => {
103
+ dockService.modules = {
104
+ did: {
105
+ dockOnly: {
106
+ rawTx: {
107
+ newOnchain: jest.fn(),
108
+ },
109
+ },
110
+ },
111
+ };
112
+
113
+ jest.spyOn(DockDid, 'fromQualifiedString').mockReturnValueOnce('');
114
+
102
115
  const result = await service.registerDidDock(
103
116
  TestFixtures.account1.getKeyring().toJson(''),
104
117
  );
@@ -107,14 +120,24 @@ describe('DID Service', () => {
107
120
  });
108
121
 
109
122
  it('expect to fail to register did dock', async () => {
123
+ dockService.modules = {
124
+ did: {
125
+ dockOnly: {
126
+ rawTx: {
127
+ newOnchain: () => {
128
+ throw new Error('');
129
+ },
130
+ },
131
+ },
132
+ },
133
+ };
134
+
110
135
  const error = await getPromiseError(() =>
111
136
  service.registerDidDock(
112
137
  TestFixtures.noBalanceAccount.getKeyring().toJson(''),
113
138
  ),
114
139
  );
115
- expect(error.message).toBe(
116
- '1010: Invalid Transaction: Inability to pay some fees , e.g. account balance too low',
117
- );
140
+ expect(error.message).toBeDefined();
118
141
  });
119
142
 
120
143
  it('expect to get did document', async () => {
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  import {DIDKeyManager} from '@docknetwork/wallet-sdk-dids/src';
2
3
  import {
3
4
  serviceName,
@@ -8,16 +9,42 @@ import {
8
9
  import {keyringService} from '../keyring/service';
9
10
  import {utilCryptoService} from '../util-crypto/service';
10
11
  import assert from 'assert';
11
- import {createNewDockDID} from '@docknetwork/sdk/utils/did';
12
12
  import {dockService, getDock} from '../dock/service';
13
- import {PublicKeySr25519} from '@docknetwork/sdk';
14
- import {DidKey, VerificationRelationship} from '@docknetwork/sdk/public-keys';
13
+
14
+ import {
15
+ DidKey,
16
+ DockDid,
17
+ VerificationRelationship,
18
+ DidMethodKey,
19
+ } from '@docknetwork/credential-sdk/types';
20
+ import {Ed25519Keypair} from '@docknetwork/credential-sdk/keypairs';
21
+
15
22
  import {Logger} from '../../core/logger';
16
23
  import {polkadotToKeydoc} from '../../core/polkadot-utils';
17
24
  import base64url from 'base64url';
18
- import { keyDocToKeypair } from '../credential/utils';
19
- import Ed25519Signature2020 from '@docknetwork/sdk/utils/vc/crypto/Ed25519Signature2020';
20
- import EcdsaSecp256k1Signature2019 from '@docknetwork/sdk/utils/vc/crypto/EcdsaSecp256k1Signature2019';
25
+ import {keyDocToKeypair} from '../credential/utils';
26
+ import {
27
+ Ed25519Signature2020,
28
+ EcdsaSecp256k1Signature2019,
29
+ } from '@docknetwork/credential-sdk/vc/crypto';
30
+
31
+ async function createDockDID({keyPair}) {
32
+ const dockDID = DockDid.random();
33
+ const dockController = dockDID.toString();
34
+ const publicKey = keyPair.publicKey();
35
+ const verRels = new VerificationRelationship();
36
+ const didKey = new DidKey(publicKey, verRels);
37
+
38
+ await dockService.modules.did.dockOnly.rawTx.newOnchain(
39
+ dockDID.did,
40
+ [didKey],
41
+ dockController === dockDID.toString()
42
+ ? []
43
+ : [DockDid.fromQualifiedString(dockController)],
44
+ );
45
+
46
+ return {did: dockDID.toString(), controller: dockController};
47
+ }
21
48
 
22
49
  async function getSignerKeypair(privateKeyDoc) {
23
50
  const privateKey =
@@ -60,7 +87,6 @@ class DIDService {
60
87
  DIDService.prototype.registerDidDock,
61
88
  DIDService.prototype.getDidDockDocument,
62
89
  DIDService.prototype.createSignedJWT,
63
-
64
90
  ];
65
91
  keypairToDIDKeyDocument(params: KeypairToDIDKeyDocumentParams) {
66
92
  validation.keypairToDIDKeyDocument(params);
@@ -94,11 +120,7 @@ class DIDService {
94
120
  return polkadotToKeydoc(keyring, params.controller);
95
121
  }
96
122
 
97
- async createSignedJWT({
98
- payload,
99
- privateKeyDoc,
100
- headerInput
101
- }) {
123
+ async createSignedJWT({payload, privateKeyDoc, headerInput}) {
102
124
  const privateKey = await getSignerKeypair(privateKeyDoc);
103
125
  const {sign} =
104
126
  typeof privateKey.signer === 'function'
@@ -113,7 +135,7 @@ class DIDService {
113
135
  const payloadBase64URL = base64url(JSON.stringify(payload));
114
136
  const headerAndPayloadBase64URL = `${headerBase64URL}.${payloadBase64URL}`;
115
137
  const signPayload = Buffer.from(headerAndPayloadBase64URL);
116
-
138
+
117
139
  const signature = await sign({data: signPayload});
118
140
  return `${headerAndPayloadBase64URL}.${base64url.encode(signature)}`;
119
141
  }
@@ -127,23 +149,8 @@ class DIDService {
127
149
 
128
150
  async registerDidDock(keyPairJSON) {
129
151
  assert(!!keyPairJSON, 'keyPair is required');
130
- const dockDID = createNewDockDID();
131
- const dock = getDock();
132
- const keyPair = keyringService.keyring.addFromJson(keyPairJSON);
133
-
134
- keyPair.unlock('');
135
-
136
- dock.setAccount(keyPair);
137
-
138
- const publicKey = PublicKeySr25519.fromKeyringPair(keyPair);
139
-
140
- const didKey = new DidKey(publicKey, new VerificationRelationship());
141
-
142
- Logger.info(`Submitting new DID: ${dockDID}`);
143
-
144
- const result = await dock.did.new(dockDID, [didKey], [], false);
145
-
146
- Logger.info(`DID created with tx hash ${result.txHash.toString()}`);
152
+ const keyPair = Ed25519Keypair.random();
153
+ const dockDID = await createDockDID({keyPair});
147
154
 
148
155
  return {
149
156
  dockDID,
@@ -1,18 +1,21 @@
1
1
  // @ts-nocheck
2
- import dock from '@docknetwork/sdk';
2
+ import { DockAPI } from '@docknetwork/dock-blockchain-api';
3
3
  import {
4
- DockResolver,
5
4
  DIDKeyResolver,
6
- WildcardMultiResolver,
7
5
  UniversalResolver,
8
- } from '@docknetwork/sdk/resolver';
6
+ WILDCARD,
7
+ DIDResolver,
8
+ ResolverRouter,
9
+ } from '@docknetwork/credential-sdk/resolver';
10
+ import {DockDIDModule} from '@docknetwork/dock-blockchain-modules';
9
11
  import {initializeWasm} from '@docknetwork/crypto-wasm-ts/lib/index';
10
12
  import {EventEmitter} from 'events';
11
13
  import {Logger} from '../../core/logger';
12
14
  import {once} from '../../modules/event-manager';
13
15
  import {InitParams, validation} from './configs';
16
+ import {DockCoreModules} from '@docknetwork/dock-blockchain-modules';
14
17
 
15
- let dockInstance = dock;
18
+ let dockInstance;
16
19
 
17
20
  export function getDock() {
18
21
  return dockInstance;
@@ -25,19 +28,17 @@ export function setDock(instance) {
25
28
  // Create a resolver in order to lookup DIDs for verifying
26
29
  export const universalResolverUrl = 'https://uniresolver.io';
27
30
 
28
- // class WalletSDKResolver extends WildcardMultiResolver {
29
- // async resolve(did) {
30
- // const trimmedDID = did.split('#')[0];
31
- // const document = await super.resolve(trimmedDID);
32
- // return document;
33
- // }
34
- // }
31
+ class AnyDIDResolver extends ResolverRouter {
32
+ method = WILDCARD;
33
+ }
35
34
 
36
35
  /**
37
36
  *
38
37
  */
39
38
  export class DockService {
40
39
  dock;
40
+ modules;
41
+ didModule;
41
42
  isDockReady = false;
42
43
  resolver: any;
43
44
  static Events = {
@@ -54,7 +55,10 @@ export class DockService {
54
55
 
55
56
  constructor() {
56
57
  this.name = 'dock';
57
- this.dock = dock;
58
+ this.dock = new DockAPI();
59
+ this.didModule = new DockDIDModule(this.dock);
60
+ this.modules = new DockCoreModules(this.dock);
61
+ dockInstance = this.dock;
58
62
  this.emitter = new EventEmitter();
59
63
  this.resolver = this.createDIDResolver();
60
64
  }
@@ -72,11 +76,12 @@ export class DockService {
72
76
  }
73
77
 
74
78
  createDIDResolver() {
75
- return new WildcardMultiResolver([
76
- new DockResolver(getDock()), // Prebuilt resolver
77
- new DIDKeyResolver(), // did:key resolution
79
+ return new AnyDIDResolver([
80
+ new DIDKeyResolver(),
81
+ new DIDResolver(this.didModule),
78
82
  new UniversalResolver(universalResolverUrl),
79
83
  ]);
84
+
80
85
  }
81
86
  /**
82
87
  *