@docknetwork/wallet-sdk-core 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.
Files changed (97) hide show
  1. package/LICENSE +39 -0
  2. package/babel.config.js +16 -0
  3. package/jest.config.ts +39 -0
  4. package/lib/account-provider.d.ts +8 -0
  5. package/lib/account-provider.d.ts.map +1 -0
  6. package/lib/account-provider.js +15 -0
  7. package/lib/account-provider.js.map +1 -0
  8. package/lib/biometric-provider.d.ts +29 -0
  9. package/lib/biometric-provider.d.ts.map +1 -0
  10. package/lib/biometric-provider.js +54 -0
  11. package/lib/biometric-provider.js.map +1 -0
  12. package/lib/credential-provider.d.ts +58 -0
  13. package/lib/credential-provider.d.ts.map +1 -0
  14. package/lib/credential-provider.js +198 -0
  15. package/lib/credential-provider.js.map +1 -0
  16. package/lib/did-provider.d.ts +79 -0
  17. package/lib/did-provider.d.ts.map +1 -0
  18. package/lib/did-provider.js +215 -0
  19. package/lib/did-provider.js.map +1 -0
  20. package/lib/ecosystem-tools.d.ts +11 -0
  21. package/lib/ecosystem-tools.d.ts.map +1 -0
  22. package/lib/ecosystem-tools.js +33 -0
  23. package/lib/ecosystem-tools.js.map +1 -0
  24. package/lib/helpers.d.ts +8 -0
  25. package/lib/helpers.d.ts.map +1 -0
  26. package/lib/helpers.js +63 -0
  27. package/lib/helpers.js.map +1 -0
  28. package/lib/message-provider.d.ts +36 -0
  29. package/lib/message-provider.d.ts.map +1 -0
  30. package/lib/message-provider.js +172 -0
  31. package/lib/message-provider.js.map +1 -0
  32. package/lib/messages/message-helpers.d.ts +110 -0
  33. package/lib/messages/message-helpers.d.ts.map +1 -0
  34. package/lib/messages/message-helpers.js +106 -0
  35. package/lib/messages/message-helpers.js.map +1 -0
  36. package/lib/network-resolver.d.ts +19 -0
  37. package/lib/network-resolver.d.ts.map +1 -0
  38. package/lib/network-resolver.js +80 -0
  39. package/lib/network-resolver.js.map +1 -0
  40. package/lib/types.d.ts +63 -0
  41. package/lib/types.d.ts.map +1 -0
  42. package/lib/types.js +3 -0
  43. package/lib/types.js.map +1 -0
  44. package/lib/v1-helpers.d.ts +20 -0
  45. package/lib/v1-helpers.d.ts.map +1 -0
  46. package/lib/v1-helpers.js +147 -0
  47. package/lib/v1-helpers.js.map +1 -0
  48. package/lib/verification-controller.d.ts +48 -0
  49. package/lib/verification-controller.d.ts.map +1 -0
  50. package/lib/verification-controller.js +219 -0
  51. package/lib/verification-controller.js.map +1 -0
  52. package/lib/wallet-to-wallet-verification/walletToWalletVerificationProvider.d.ts +20 -0
  53. package/lib/wallet-to-wallet-verification/walletToWalletVerificationProvider.d.ts.map +1 -0
  54. package/lib/wallet-to-wallet-verification/walletToWalletVerificationProvider.js +140 -0
  55. package/lib/wallet-to-wallet-verification/walletToWalletVerificationProvider.js.map +1 -0
  56. package/lib/wallet-wasm.d.ts +10 -0
  57. package/lib/wallet-wasm.d.ts.map +1 -0
  58. package/lib/wallet-wasm.js +62 -0
  59. package/lib/wallet-wasm.js.map +1 -0
  60. package/lib/wallet.d.ts +11 -0
  61. package/lib/wallet.d.ts.map +1 -0
  62. package/lib/wallet.js +173 -0
  63. package/lib/wallet.js.map +1 -0
  64. package/package.json +34 -0
  65. package/setup-tests.ts +1 -0
  66. package/src/account-provider.ts +18 -0
  67. package/src/biometric-provider.ts +82 -0
  68. package/src/credential-provider.test.ts +164 -0
  69. package/src/credential-provider.ts +272 -0
  70. package/src/did-provider.test.ts +203 -0
  71. package/src/did-provider.ts +263 -0
  72. package/src/ecosystem-tools.ts +37 -0
  73. package/src/fixtures/any-credential-proof-request.json +30 -0
  74. package/src/fixtures/biometrics-credential-bbs-revocation.json +62 -0
  75. package/src/fixtures/customer-credential.json +39 -0
  76. package/src/fixtures/iiw-credential.json +59 -0
  77. package/src/fixtures/iiw-template.json +33 -0
  78. package/src/fixtures/university-degree-bbs.json +57 -0
  79. package/src/fixtures/university-degree-proof-request.json +32 -0
  80. package/src/helpers.ts +61 -0
  81. package/src/message-provider.test.ts +115 -0
  82. package/src/message-provider.ts +221 -0
  83. package/src/messages/message-helpers.ts +125 -0
  84. package/src/messages/relay-service-mocks/demo-app-messages.json +450 -0
  85. package/src/network-resolver.test.ts +142 -0
  86. package/src/network-resolver.ts +122 -0
  87. package/src/types.ts +75 -0
  88. package/src/v1-helpers.ts +160 -0
  89. package/src/verification-controller.test.ts +149 -0
  90. package/src/verification-controller.ts +276 -0
  91. package/src/wallet-to-wallet-verification/walletToWalletVerificationProvider.ts +216 -0
  92. package/src/wallet-wasm.ts +74 -0
  93. package/src/wallet.test.ts +72 -0
  94. package/src/wallet.ts +211 -0
  95. package/tsconfig.build.json +26 -0
  96. package/tsconfig.build.tsbuildinfo +1 -0
  97. package/tsconfig.json +30 -0
package/src/wallet.ts ADDED
@@ -0,0 +1,211 @@
1
+ import {createDataStore} from '@docknetwork/wallet-sdk-data-store/src';
2
+ import {
3
+ DataStore,
4
+ DataStoreConfigs,
5
+ WalletDocument,
6
+ } from '@docknetwork/wallet-sdk-data-store/src/types';
7
+ import {
8
+ getDocumentsByType,
9
+ getDocumentById,
10
+ createDocument,
11
+ removeDocument,
12
+ getDocumentCorrelations,
13
+ getAllDocuments,
14
+ updateDocument,
15
+ removeAllDocuments,
16
+ getDocumentsById,
17
+ } from '@docknetwork/wallet-sdk-data-store/src/entities/document';
18
+ import {CreateWalletProps, IWallet} from './types';
19
+ import {toV1Wallet} from './v1-helpers';
20
+ import {initWalletWasm} from './wallet-wasm';
21
+ import {EventEmitter} from 'events';
22
+ import {WalletEvents} from '@docknetwork/wallet-sdk-wasm/src/modules/wallet';
23
+ import {walletService} from '@docknetwork/wallet-sdk-wasm/src/services/wallet';
24
+ import {importUniversalWalletDocuments} from '@docknetwork/wallet-sdk-data-store/src/migration/migration1/migrate-v1-data';
25
+ import {ensureDID} from './did-provider';
26
+ export type {IWallet};
27
+
28
+ function once(emitter: EventEmitter, eventName: string) {
29
+ return new Promise(resolve => emitter.once(eventName, resolve));
30
+ }
31
+
32
+ export function ensureDocumentContext(document) {
33
+ if (document['@context']) {
34
+ return document;
35
+ }
36
+
37
+ return {
38
+ ...document,
39
+ '@context': ['https://w3id.org/wallet/v1'],
40
+ };
41
+ }
42
+
43
+ /**
44
+ * Create wallet
45
+ *
46
+ * @param createWalletProps
47
+ * @returns {Promise<IWallet>}
48
+ */
49
+ export async function createWallet(
50
+ createWalletProps: CreateWalletProps,
51
+ ): Promise<IWallet> {
52
+ const dataStore = await createDataStore(createWalletProps);
53
+ let status;
54
+
55
+ const eventEmitter = new EventEmitter();
56
+
57
+ const wallet = {
58
+ eventManager: eventEmitter,
59
+ waitForEvent: (eventName: string) => once(eventEmitter, eventName) as any,
60
+ dataStore,
61
+ getStatus() {
62
+ return status;
63
+ },
64
+ resolveDocumentNetwork: async (document: any) => {
65
+ return dataStore.resolveDocumentNetwork({
66
+ document,
67
+ dataStore,
68
+ });
69
+ },
70
+ deleteWallet: async () => {
71
+ await removeAllDocuments({
72
+ dataStore,
73
+ });
74
+
75
+ eventEmitter.emit(WalletEvents.walletDeleted);
76
+ },
77
+ setStatus(newStatus: string) {
78
+ status = newStatus;
79
+ },
80
+ setNetwork: async (networkId: string) => {
81
+ await dataStore.setNetwork(networkId);
82
+ eventEmitter.emit(WalletEvents.networkUpdated, networkId);
83
+ },
84
+ getNetworkId: () => {
85
+ return dataStore.networkId;
86
+ },
87
+ getDocumentById: id =>
88
+ getDocumentById({
89
+ dataStore,
90
+ id,
91
+ }),
92
+
93
+ getAllDocuments: () => {
94
+ return getAllDocuments({
95
+ dataStore,
96
+ });
97
+ },
98
+ getDocumentsById: idList =>
99
+ getDocumentsById({
100
+ dataStore,
101
+ idList,
102
+ }),
103
+ getDocumentsByType: type =>
104
+ getDocumentsByType({
105
+ dataStore,
106
+ type,
107
+ }),
108
+ addDocument: (json: any) => {
109
+ return createDocument({
110
+ dataStore,
111
+ json,
112
+ }).then(result => {
113
+ eventEmitter.emit(WalletEvents.documentAdded, result);
114
+ return result;
115
+ });
116
+ },
117
+ updateDocument: (document: any) => {
118
+ return updateDocument({
119
+ dataStore,
120
+ document,
121
+ }).then(result => {
122
+ eventEmitter.emit(WalletEvents.documentUpdated, result);
123
+ return result;
124
+ });
125
+ },
126
+ removeDocument: async (id: string) => {
127
+ const document = await wallet.getDocumentById(id);
128
+
129
+ return removeDocument({
130
+ dataStore,
131
+ id,
132
+ }).then(result => {
133
+ eventEmitter.emit(WalletEvents.documentRemoved, document);
134
+ return result;
135
+ });
136
+ },
137
+ getDocumentCorrelations: (documentId: string) => {
138
+ return getDocumentCorrelations({
139
+ dataStore,
140
+ documentId,
141
+ });
142
+ },
143
+ getAccountKeyPair: async (accountId: string) => {
144
+ const correlations = await getDocumentCorrelations({
145
+ dataStore,
146
+ documentId: accountId,
147
+ });
148
+
149
+ const keyPair = correlations.find(
150
+ correlation => correlation.type === 'KeyringPair',
151
+ );
152
+
153
+ return keyPair?.value;
154
+ },
155
+ getDocumentsFromEncryptedWallet: async (json: any, password: string) => {
156
+ return walletService.getDocumentsFromEncryptedWallet({
157
+ encryptedJSONWallet: json,
158
+ password,
159
+ });
160
+ },
161
+ importUniversalWalletJSON: async (json: any, password: string) => {
162
+ const documents = await walletService.getDocumentsFromEncryptedWallet({
163
+ encryptedJSONWallet: json,
164
+ password,
165
+ });
166
+
167
+ await importUniversalWalletDocuments({
168
+ documents,
169
+ dataStore,
170
+ });
171
+
172
+ return documents;
173
+ },
174
+ exportDocuments: async (params: {documents: any; password: string}) => {
175
+ const documents = params.documents.map(ensureDocumentContext);
176
+ return walletService.exportDocuments({
177
+ documents,
178
+ password: params.password,
179
+ });
180
+ },
181
+ exportUniversalWalletJSON: async (password: string) => {
182
+ let documents = await getAllDocuments({
183
+ dataStore,
184
+ allNetworks: true,
185
+ });
186
+
187
+ const result = await wallet.exportDocuments({
188
+ documents,
189
+ password,
190
+ });
191
+
192
+ return result;
193
+ },
194
+ } as IWallet;
195
+
196
+ const v1Wallet = await toV1Wallet(wallet);
197
+
198
+ await initWalletWasm(v1Wallet);
199
+
200
+ await ensureDID({
201
+ wallet: v1Wallet,
202
+ });
203
+
204
+ [WalletEvents.networkUpdated, WalletEvents.walletDeleted].forEach((event) => eventEmitter.on(event, () => {
205
+ ensureDID({
206
+ wallet: v1Wallet,
207
+ });
208
+ }));
209
+
210
+ return v1Wallet;
211
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "extends": "./tsconfig",
3
+ "compilerOptions": {
4
+ "strict": false,
5
+ "preserveConstEnums": true,
6
+ "sourceMap": true,
7
+ "target": "ESNext",
8
+ "module": "CommonJS",
9
+ "moduleResolution": "Node",
10
+ "esModuleInterop": true,
11
+ "downlevelIteration": true,
12
+ "declarationMap": true,
13
+ "declaration": true,
14
+ "composite": true,
15
+ "skipLibCheck": true,
16
+ "emitDecoratorMetadata": true,
17
+ "experimentalDecorators": true,
18
+ "useUnknownInCatchVariables": false,
19
+ "resolveJsonModule": true,
20
+ "allowSyntheticDefaultImports": true,
21
+ "outDir": "lib",
22
+ "rootDir": "./src"
23
+ },
24
+ "include": ["./src/**/*.ts*"],
25
+ "exclude": ["src/**/*.spec.ts*", "src/**/*.test.ts*", "node_modules"]
26
+ }