@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.
- package/LICENSE +39 -0
- package/babel.config.js +16 -0
- package/jest.config.ts +39 -0
- package/lib/account-provider.d.ts +8 -0
- package/lib/account-provider.d.ts.map +1 -0
- package/lib/account-provider.js +15 -0
- package/lib/account-provider.js.map +1 -0
- package/lib/biometric-provider.d.ts +29 -0
- package/lib/biometric-provider.d.ts.map +1 -0
- package/lib/biometric-provider.js +54 -0
- package/lib/biometric-provider.js.map +1 -0
- package/lib/credential-provider.d.ts +58 -0
- package/lib/credential-provider.d.ts.map +1 -0
- package/lib/credential-provider.js +198 -0
- package/lib/credential-provider.js.map +1 -0
- package/lib/did-provider.d.ts +79 -0
- package/lib/did-provider.d.ts.map +1 -0
- package/lib/did-provider.js +215 -0
- package/lib/did-provider.js.map +1 -0
- package/lib/ecosystem-tools.d.ts +11 -0
- package/lib/ecosystem-tools.d.ts.map +1 -0
- package/lib/ecosystem-tools.js +33 -0
- package/lib/ecosystem-tools.js.map +1 -0
- package/lib/helpers.d.ts +8 -0
- package/lib/helpers.d.ts.map +1 -0
- package/lib/helpers.js +63 -0
- package/lib/helpers.js.map +1 -0
- package/lib/message-provider.d.ts +36 -0
- package/lib/message-provider.d.ts.map +1 -0
- package/lib/message-provider.js +172 -0
- package/lib/message-provider.js.map +1 -0
- package/lib/messages/message-helpers.d.ts +110 -0
- package/lib/messages/message-helpers.d.ts.map +1 -0
- package/lib/messages/message-helpers.js +106 -0
- package/lib/messages/message-helpers.js.map +1 -0
- package/lib/network-resolver.d.ts +19 -0
- package/lib/network-resolver.d.ts.map +1 -0
- package/lib/network-resolver.js +80 -0
- package/lib/network-resolver.js.map +1 -0
- package/lib/types.d.ts +63 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/lib/v1-helpers.d.ts +20 -0
- package/lib/v1-helpers.d.ts.map +1 -0
- package/lib/v1-helpers.js +147 -0
- package/lib/v1-helpers.js.map +1 -0
- package/lib/verification-controller.d.ts +48 -0
- package/lib/verification-controller.d.ts.map +1 -0
- package/lib/verification-controller.js +219 -0
- package/lib/verification-controller.js.map +1 -0
- package/lib/wallet-to-wallet-verification/walletToWalletVerificationProvider.d.ts +20 -0
- package/lib/wallet-to-wallet-verification/walletToWalletVerificationProvider.d.ts.map +1 -0
- package/lib/wallet-to-wallet-verification/walletToWalletVerificationProvider.js +140 -0
- package/lib/wallet-to-wallet-verification/walletToWalletVerificationProvider.js.map +1 -0
- package/lib/wallet-wasm.d.ts +10 -0
- package/lib/wallet-wasm.d.ts.map +1 -0
- package/lib/wallet-wasm.js +62 -0
- package/lib/wallet-wasm.js.map +1 -0
- package/lib/wallet.d.ts +11 -0
- package/lib/wallet.d.ts.map +1 -0
- package/lib/wallet.js +173 -0
- package/lib/wallet.js.map +1 -0
- package/package.json +34 -0
- package/setup-tests.ts +1 -0
- package/src/account-provider.ts +18 -0
- package/src/biometric-provider.ts +82 -0
- package/src/credential-provider.test.ts +164 -0
- package/src/credential-provider.ts +272 -0
- package/src/did-provider.test.ts +203 -0
- package/src/did-provider.ts +263 -0
- package/src/ecosystem-tools.ts +37 -0
- package/src/fixtures/any-credential-proof-request.json +30 -0
- package/src/fixtures/biometrics-credential-bbs-revocation.json +62 -0
- package/src/fixtures/customer-credential.json +39 -0
- package/src/fixtures/iiw-credential.json +59 -0
- package/src/fixtures/iiw-template.json +33 -0
- package/src/fixtures/university-degree-bbs.json +57 -0
- package/src/fixtures/university-degree-proof-request.json +32 -0
- package/src/helpers.ts +61 -0
- package/src/message-provider.test.ts +115 -0
- package/src/message-provider.ts +221 -0
- package/src/messages/message-helpers.ts +125 -0
- package/src/messages/relay-service-mocks/demo-app-messages.json +450 -0
- package/src/network-resolver.test.ts +142 -0
- package/src/network-resolver.ts +122 -0
- package/src/types.ts +75 -0
- package/src/v1-helpers.ts +160 -0
- package/src/verification-controller.test.ts +149 -0
- package/src/verification-controller.ts +276 -0
- package/src/wallet-to-wallet-verification/walletToWalletVerificationProvider.ts +216 -0
- package/src/wallet-wasm.ts +74 -0
- package/src/wallet.test.ts +72 -0
- package/src/wallet.ts +211 -0
- package/tsconfig.build.json +26 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- 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
|
+
}
|