@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
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DIDComm Message helpers
|
|
3
|
+
* Check https://identity.foundation/didcomm-messaging/spec/#out-of-band-messages for more details
|
|
4
|
+
*/
|
|
5
|
+
export declare const MessageTypes: {
|
|
6
|
+
Invitation: string;
|
|
7
|
+
RequestPresentation: string;
|
|
8
|
+
Presentation: string;
|
|
9
|
+
Ack: string;
|
|
10
|
+
IssuerDirect: string;
|
|
11
|
+
Basic: string;
|
|
12
|
+
IssueWithData: string;
|
|
13
|
+
};
|
|
14
|
+
export declare const Goals: {
|
|
15
|
+
WalletToWalletVerification: string;
|
|
16
|
+
PresentationAckFromVerifier: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @return OOB message to start a wallet to wallet verification flow
|
|
21
|
+
* The holder will scan it as QR code and should have the context to start the verification flow
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
export declare function buildVerificationFlowInviteMessage({ verifierDID, proofRequestId }: {
|
|
25
|
+
verifierDID: any;
|
|
26
|
+
proofRequestId: any;
|
|
27
|
+
}): {
|
|
28
|
+
type: string;
|
|
29
|
+
from: any;
|
|
30
|
+
body: {
|
|
31
|
+
goal_code: string;
|
|
32
|
+
goal: string;
|
|
33
|
+
proofRequestId: any;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Sender: Verifier
|
|
38
|
+
* OOB message to request a verifiable presentation from the holder
|
|
39
|
+
*/
|
|
40
|
+
export declare function buildRequestVerifiablePresentationMessage({ verifierDID, holderDID, proofRequest, proofRequestId }: {
|
|
41
|
+
verifierDID: any;
|
|
42
|
+
holderDID: any;
|
|
43
|
+
proofRequest: any;
|
|
44
|
+
proofRequestId: any;
|
|
45
|
+
}): {
|
|
46
|
+
type: string;
|
|
47
|
+
from: any;
|
|
48
|
+
to: any;
|
|
49
|
+
body: {
|
|
50
|
+
proofRequest: any;
|
|
51
|
+
proofRequestId: any;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Sender: Holder
|
|
56
|
+
* Start a wallet to wallet verification flow
|
|
57
|
+
*/
|
|
58
|
+
export declare function buildAckWalletToWalletVerificationMessage({ holderDID, verifierDID, proofRequestId, }: {
|
|
59
|
+
holderDID: any;
|
|
60
|
+
verifierDID: any;
|
|
61
|
+
proofRequestId: any;
|
|
62
|
+
}): {
|
|
63
|
+
type: string;
|
|
64
|
+
from: any;
|
|
65
|
+
to: any;
|
|
66
|
+
body: {
|
|
67
|
+
goal_code: string;
|
|
68
|
+
goal: string;
|
|
69
|
+
proofRequestId: any;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Sender: Holder
|
|
74
|
+
* Send a verifiable presentation to the verifier
|
|
75
|
+
*/
|
|
76
|
+
export declare function buildVerifiablePresentationMessage({ verifierDID, holderDID, proofRequestId, presentation, }: {
|
|
77
|
+
verifierDID: any;
|
|
78
|
+
holderDID: any;
|
|
79
|
+
proofRequestId: any;
|
|
80
|
+
presentation: any;
|
|
81
|
+
}): {
|
|
82
|
+
type: string;
|
|
83
|
+
from: any;
|
|
84
|
+
to: any;
|
|
85
|
+
body: {
|
|
86
|
+
proofRequestId: any;
|
|
87
|
+
presentation: any;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Sender: Verifier
|
|
92
|
+
* Sends an the presentation result to the holder
|
|
93
|
+
*/
|
|
94
|
+
export declare function buildVerifiablePresentationAckMessage({ verifierDID, holderDID, proofRequestId, presentationResult, }: {
|
|
95
|
+
verifierDID: any;
|
|
96
|
+
holderDID: any;
|
|
97
|
+
proofRequestId: any;
|
|
98
|
+
presentationResult: any;
|
|
99
|
+
}): {
|
|
100
|
+
type: string;
|
|
101
|
+
from: any;
|
|
102
|
+
to: any;
|
|
103
|
+
body: {
|
|
104
|
+
goal_code: string;
|
|
105
|
+
goal: string;
|
|
106
|
+
proofRequestId: any;
|
|
107
|
+
presentationResult: any;
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
//# sourceMappingURL=message-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-helpers.d.ts","sourceRoot":"","sources":["../../src/messages/message-helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,YAAY;;;;;;;;CASxB,CAAC;AAEF,eAAO,MAAM,KAAK;;;CAGjB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,kCAAkC,CAAC,EAAC,WAAW,EAAE,cAAc,EAAC;;;CAAA;;;;;;;;EAU/E;AAED;;;GAGG;AACH,wBAAgB,yCAAyC,CAAC,EACxD,WAAW,EACX,SAAS,EACT,YAAY,EACZ,cAAc,EACf;;;;;CAAA;;;;;;;;EAUA;AAED;;;GAGG;AACH,wBAAgB,yCAAyC,CAAC,EACxD,SAAS,EACT,WAAW,EACX,cAAc,GACf;;;;CAAA;;;;;;;;;EAWA;AAGD;;;GAGG;AACH,wBAAgB,kCAAkC,CAAC,EACjD,WAAW,EACX,SAAS,EACT,cAAc,EACd,YAAY,GACb;;;;;CAAA;;;;;;;;EAUA;AAED;;;GAGG;AACH,wBAAgB,qCAAqC,CAAC,EACpD,WAAW,EACX,SAAS,EACT,cAAc,EACd,kBAAkB,GACnB;;;;;CAAA;;;;;;;;;;EAYA"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* DIDComm Message helpers
|
|
4
|
+
* Check https://identity.foundation/didcomm-messaging/spec/#out-of-band-messages for more details
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.buildVerifiablePresentationAckMessage = exports.buildVerifiablePresentationMessage = exports.buildAckWalletToWalletVerificationMessage = exports.buildRequestVerifiablePresentationMessage = exports.buildVerificationFlowInviteMessage = exports.Goals = exports.MessageTypes = void 0;
|
|
8
|
+
exports.MessageTypes = {
|
|
9
|
+
Invitation: 'https://didcomm.org/out-of-band/2.0/invitation',
|
|
10
|
+
RequestPresentation: 'https://didcomm.org/present-proof/1.0/request-presentation',
|
|
11
|
+
Presentation: 'https://didcomm.org/present-proof/1.0/presentation',
|
|
12
|
+
Ack: 'https://didcomm.org/ack/1.0/ack',
|
|
13
|
+
IssuerDirect: 'https://didcomm.org/issue-credential/2.0/issue-credential',
|
|
14
|
+
Basic: 'https://didcomm.org/basicmessage/1.0/message',
|
|
15
|
+
IssueWithData: 'https://didcomm.org/issue-credential/2.0/offer-credential',
|
|
16
|
+
};
|
|
17
|
+
exports.Goals = {
|
|
18
|
+
WalletToWalletVerification: 'wallet-to-wallet-verification',
|
|
19
|
+
PresentationAckFromVerifier: 'presentation-ack-from-verifier',
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @return OOB message to start a wallet to wallet verification flow
|
|
24
|
+
* The holder will scan it as QR code and should have the context to start the verification flow
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
27
|
+
function buildVerificationFlowInviteMessage({ verifierDID, proofRequestId }) {
|
|
28
|
+
return {
|
|
29
|
+
type: exports.MessageTypes.Invitation,
|
|
30
|
+
from: verifierDID,
|
|
31
|
+
body: {
|
|
32
|
+
goal_code: exports.Goals.WalletToWalletVerification,
|
|
33
|
+
goal: 'Invite for a Wallet to Wallet Verification',
|
|
34
|
+
proofRequestId: proofRequestId,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
exports.buildVerificationFlowInviteMessage = buildVerificationFlowInviteMessage;
|
|
39
|
+
/**
|
|
40
|
+
* Sender: Verifier
|
|
41
|
+
* OOB message to request a verifiable presentation from the holder
|
|
42
|
+
*/
|
|
43
|
+
function buildRequestVerifiablePresentationMessage({ verifierDID, holderDID, proofRequest, proofRequestId }) {
|
|
44
|
+
return {
|
|
45
|
+
type: exports.MessageTypes.RequestPresentation,
|
|
46
|
+
from: verifierDID,
|
|
47
|
+
to: holderDID,
|
|
48
|
+
body: {
|
|
49
|
+
proofRequest,
|
|
50
|
+
proofRequestId,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
exports.buildRequestVerifiablePresentationMessage = buildRequestVerifiablePresentationMessage;
|
|
55
|
+
/**
|
|
56
|
+
* Sender: Holder
|
|
57
|
+
* Start a wallet to wallet verification flow
|
|
58
|
+
*/
|
|
59
|
+
function buildAckWalletToWalletVerificationMessage({ holderDID, verifierDID, proofRequestId, }) {
|
|
60
|
+
return {
|
|
61
|
+
type: exports.MessageTypes.Ack,
|
|
62
|
+
from: holderDID,
|
|
63
|
+
to: verifierDID,
|
|
64
|
+
body: {
|
|
65
|
+
goal_code: exports.Goals.WalletToWalletVerification,
|
|
66
|
+
goal: 'Ack for for a Wallet to Wallet Verification invite',
|
|
67
|
+
proofRequestId: proofRequestId,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
exports.buildAckWalletToWalletVerificationMessage = buildAckWalletToWalletVerificationMessage;
|
|
72
|
+
/**
|
|
73
|
+
* Sender: Holder
|
|
74
|
+
* Send a verifiable presentation to the verifier
|
|
75
|
+
*/
|
|
76
|
+
function buildVerifiablePresentationMessage({ verifierDID, holderDID, proofRequestId, presentation, }) {
|
|
77
|
+
return {
|
|
78
|
+
type: exports.MessageTypes.Presentation,
|
|
79
|
+
from: verifierDID,
|
|
80
|
+
to: holderDID,
|
|
81
|
+
body: {
|
|
82
|
+
proofRequestId,
|
|
83
|
+
presentation,
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
exports.buildVerifiablePresentationMessage = buildVerifiablePresentationMessage;
|
|
88
|
+
/**
|
|
89
|
+
* Sender: Verifier
|
|
90
|
+
* Sends an the presentation result to the holder
|
|
91
|
+
*/
|
|
92
|
+
function buildVerifiablePresentationAckMessage({ verifierDID, holderDID, proofRequestId, presentationResult, }) {
|
|
93
|
+
return {
|
|
94
|
+
type: exports.MessageTypes.Ack,
|
|
95
|
+
from: verifierDID,
|
|
96
|
+
to: holderDID,
|
|
97
|
+
body: {
|
|
98
|
+
goal_code: exports.Goals.PresentationAckFromVerifier,
|
|
99
|
+
goal: 'Verifier is sending an Ack for a presentation sent by the holder',
|
|
100
|
+
proofRequestId,
|
|
101
|
+
presentationResult,
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
exports.buildVerifiablePresentationAckMessage = buildVerifiablePresentationAckMessage;
|
|
106
|
+
//# sourceMappingURL=message-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-helpers.js","sourceRoot":"","sources":["../../src/messages/message-helpers.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEU,QAAA,YAAY,GAAG;IAC1B,UAAU,EAAE,gDAAgD;IAC5D,mBAAmB,EACjB,4DAA4D;IAC9D,YAAY,EAAE,oDAAoD;IAClE,GAAG,EAAE,iCAAiC;IACtC,YAAY,EAAE,2DAA2D;IACzE,KAAK,EAAE,8CAA8C;IACrD,aAAa,EAAE,2DAA2D;CAC3E,CAAC;AAEW,QAAA,KAAK,GAAG;IACnB,0BAA0B,EAAE,+BAA+B;IAC3D,2BAA2B,EAAE,gCAAgC;CAC9D,CAAC;AAEF;;;;;GAKG;AACH,SAAgB,kCAAkC,CAAC,EAAC,WAAW,EAAE,cAAc,EAAC;IAC9E,OAAO;QACL,IAAI,EAAE,oBAAY,CAAC,UAAU;QAC7B,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE;YACJ,SAA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C,IAAI,EAAE,kEAAkE;YACxE,cAAc;YACd,kBAAkB;SACnB;KACF,CAAC;AACJ,CAAC;AAjBD,sFAiBC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DataStore, DocumentNetworkResolver, DocumentResolverProps } from '@docknetwork/wallet-sdk-data-store/src/types';
|
|
2
|
+
type ResolverResult = string | null;
|
|
3
|
+
export declare const dockDocumentNetworkResolver: DocumentNetworkResolver;
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* Given an Api URL, resolve the network ID
|
|
7
|
+
* For now it will be applied for creds and certs
|
|
8
|
+
* It can be extended to resolve other external URLs
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveApiNetwork({ url, dataStore, }: {
|
|
12
|
+
url: string;
|
|
13
|
+
dataStore: DataStore;
|
|
14
|
+
}): string;
|
|
15
|
+
export declare function credentialResolver({ document, dataStore, }: DocumentResolverProps): Promise<ResolverResult>;
|
|
16
|
+
export declare function didResolver({ document, dataStore, }: DocumentResolverProps): Promise<ResolverResult>;
|
|
17
|
+
export declare function accountResolver({ document, dataStore, }: DocumentResolverProps): Promise<ResolverResult>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=network-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network-resolver.d.ts","sourceRoot":"","sources":["../src/network-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,uBAAuB,EACvB,qBAAqB,EAGtB,MAAM,8CAA8C,CAAC;AAGtD,KAAK,cAAc,GAAG,MAAM,GAAG,IAAI,CAAC;AAEpC,eAAO,MAAM,2BAA2B,EAAE,uBAwBzC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,GAAG,EACH,SAAS,GACV,EAAE;IACD,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,SAAS,CAAC;CACtB,UAUA;AAED,wBAAsB,kBAAkB,CAAC,EACvC,QAAQ,EACR,SAAS,GACV,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC,CAejD;AAED,wBAAsB,WAAW,CAAC,EAChC,QAAQ,EACR,SAAS,GACV,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC,CAGjD;AAED,wBAAsB,eAAe,CAAC,EACpC,QAAQ,EACR,SAAS,GACV,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC,CA0BjD"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.accountResolver = exports.didResolver = exports.credentialResolver = exports.resolveApiNetwork = exports.dockDocumentNetworkResolver = void 0;
|
|
4
|
+
const util_crypto_1 = require("@docknetwork/wallet-sdk-wasm/src/services/util-crypto");
|
|
5
|
+
const dockDocumentNetworkResolver = async ({ document, dataStore, }) => {
|
|
6
|
+
let networkId;
|
|
7
|
+
let isFallback = false;
|
|
8
|
+
for (const resolver of resolvers) {
|
|
9
|
+
networkId = await resolver({ document, dataStore });
|
|
10
|
+
if (networkId) {
|
|
11
|
+
break;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
if (!networkId) {
|
|
15
|
+
isFallback = true;
|
|
16
|
+
networkId = dataStore.networkId;
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
networkId: networkId,
|
|
20
|
+
isFallback,
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
exports.dockDocumentNetworkResolver = dockDocumentNetworkResolver;
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* Given an Api URL, resolve the network ID
|
|
27
|
+
* For now it will be applied for creds and certs
|
|
28
|
+
* It can be extended to resolve other external URLs
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
function resolveApiNetwork({ url, dataStore, }) {
|
|
32
|
+
for (const network of dataStore.networks) {
|
|
33
|
+
for (const hostname of network.credentialHostnames) {
|
|
34
|
+
if (url.indexOf(hostname) > -1) {
|
|
35
|
+
return network.id;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
exports.resolveApiNetwork = resolveApiNetwork;
|
|
42
|
+
async function credentialResolver({ document, dataStore, }) {
|
|
43
|
+
if (!document) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
if (!document.type?.includes('VerifiableCredential')) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
// TODO: create fallback with DID resolution
|
|
50
|
+
return resolveApiNetwork({
|
|
51
|
+
url: document.id,
|
|
52
|
+
dataStore,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
exports.credentialResolver = credentialResolver;
|
|
56
|
+
async function didResolver({ document, dataStore, }) {
|
|
57
|
+
// TODO: Define DID resolver
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
exports.didResolver = didResolver;
|
|
61
|
+
async function accountResolver({ document, dataStore, }) {
|
|
62
|
+
if (!document) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
const isAddress = Array.isArray(document.type) ? document.type.includes('Address') : document.type === 'Address';
|
|
66
|
+
if (!isAddress) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
const addressPrefixList = dataStore.networks.map(network => network?.configs?.addressPrefix);
|
|
70
|
+
const addressPrefix = await util_crypto_1.utilCryptoService.getAddressPrefix({
|
|
71
|
+
address: document.id,
|
|
72
|
+
startPrefix: Math.min(...addressPrefixList),
|
|
73
|
+
endPrefix: Math.max(...addressPrefixList),
|
|
74
|
+
});
|
|
75
|
+
const network = dataStore.networks.find(item => item.configs?.addressPrefix === addressPrefix);
|
|
76
|
+
return network?.id;
|
|
77
|
+
}
|
|
78
|
+
exports.accountResolver = accountResolver;
|
|
79
|
+
const resolvers = [credentialResolver, accountResolver, didResolver];
|
|
80
|
+
//# sourceMappingURL=network-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network-resolver.js","sourceRoot":"","sources":["../src/network-resolver.ts"],"names":[],"mappings":";;;AAOA,uFAAwF;AAIjF,MAAM,2BAA2B,GAA4B,KAAK,EAAE,EACzE,QAAQ,EACR,SAAS,GACa,EAAmC,EAAE;IAC3D,IAAI,SAAS,CAAC;IACd,IAAI,UAAU,GAAG,KAAK,CAAC;IAEvB,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;QAChC,SAAS,GAAG,MAAM,QAAQ,CAAC,EAAC,QAAQ,EAAE,SAAS,EAAC,CAAC,CAAC;QAElD,IAAI,SAAS,EAAE;YACb,MAAM;SACP;KACF;IAED,IAAI,CAAC,SAAS,EAAE;QACd,UAAU,GAAG,IAAI,CAAC;QAClB,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC;KACjC;IAED,OAAO;QACL,SAAS,EAAE,SAAS;QACpB,UAAU;KACX,CAAC;AACJ,CAAC,CAAC;AAxBW,QAAA,2BAA2B,+BAwBtC;AAEF;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAAC,EAChC,GAAG,EACH,SAAS,GAIV;IACC,KAAK,MAAM,OAAO,IAAI,SAAS,CAAC,QAAQ,EAAE;QACxC,KAAK,MAAM,QAAQ,IAAI,OAAO,CAAC,mBAAmB,EAAE;YAClD,IAAI,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE;gBAC9B,OAAO,OAAO,CAAC,EAAE,CAAC;aACnB;SACF;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAhBD,8CAgBC;AAEM,KAAK,UAAU,kBAAkB,CAAC,EACvC,QAAQ,EACR,SAAS,GACa;IACtB,IAAI,CAAC,QAAQ,EAAE;QACb,OAAO,IAAI,CAAC;KACb;IAED,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,sBAAsB,CAAC,EAAE;QACpD,OAA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AM,SAAS,GAAG,CAAC,kBAAkB,EAAE,eAAe,EAAE,WAAW,CAAC,CAAC"}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { DataStore, DataStoreConfigs, DocumentResolverResult, WalletDocument } from '@docknetwork/wallet-sdk-data-store/src/types';
|
|
3
|
+
import { Accounts } from '@docknetwork/wallet-sdk-wasm/src/modules/accounts';
|
|
4
|
+
import { EventEmitter } from 'events';
|
|
5
|
+
export interface IV1Wallet {
|
|
6
|
+
accounts: Accounts;
|
|
7
|
+
getStatus: () => string;
|
|
8
|
+
setStatus: (status: string) => void;
|
|
9
|
+
eventManager: EventEmitter;
|
|
10
|
+
waitForEvent: (eventName: string) => Promise<any>;
|
|
11
|
+
resolveCorrelations: (id: string) => Promise<WalletDocument[]>;
|
|
12
|
+
query: ({ id, type, }?: {
|
|
13
|
+
id?: string;
|
|
14
|
+
type?: string;
|
|
15
|
+
}) => Promise<WalletDocument[]>;
|
|
16
|
+
ensureNetwork: () => Promise<void>;
|
|
17
|
+
sync: () => Promise<void>;
|
|
18
|
+
remove: (id: string) => Promise<void>;
|
|
19
|
+
create: (json: any) => Promise<WalletDocument>;
|
|
20
|
+
update: (json: any) => Promise<WalletDocument>;
|
|
21
|
+
upsert: (json: any) => Promise<WalletDocument>;
|
|
22
|
+
deleteWallet: () => Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export type IWallet = {
|
|
25
|
+
getDocumentById: (id: string) => Promise<WalletDocument>;
|
|
26
|
+
getDocumentsById: (idList: string[]) => Promise<WalletDocument[]>;
|
|
27
|
+
getDocumentsByType: (type: string) => Promise<WalletDocument[]>;
|
|
28
|
+
getAllDocuments: () => Promise<WalletDocument[]>;
|
|
29
|
+
addDocument: (json: any) => Promise<WalletDocument>;
|
|
30
|
+
upsertDocument: (json: any) => Promise<WalletDocument>;
|
|
31
|
+
updateDocument: (json: any) => Promise<WalletDocument>;
|
|
32
|
+
getDocumentCorrelations: (documentId: string) => Promise<WalletDocument[]>;
|
|
33
|
+
getAccountKeyPair: (accountId: string) => Promise<any>;
|
|
34
|
+
/**
|
|
35
|
+
* Remove document by id
|
|
36
|
+
* @param id
|
|
37
|
+
*/
|
|
38
|
+
removeDocument: (id: string) => Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Import data from a Universal Wallet 2020 JSON
|
|
41
|
+
* https://w3c-ccg.github.io/universal-wallet-interop-spec/
|
|
42
|
+
*
|
|
43
|
+
* @param json
|
|
44
|
+
*/
|
|
45
|
+
importUniversalWalletJSON: (json: any, password: string) => Promise<void>;
|
|
46
|
+
getDocumentsFromEncryptedWallet: (json: any, password: string) => Promise<any>;
|
|
47
|
+
exportDocuments: (params: {
|
|
48
|
+
documents: any;
|
|
49
|
+
password: string;
|
|
50
|
+
}) => Promise<any>;
|
|
51
|
+
/**
|
|
52
|
+
* Create a Universal Wallet 2020 JSON representation of the wallet
|
|
53
|
+
* https://w3c-ccg.github.io/universal-wallet-interop-spec/
|
|
54
|
+
* @returns JSON representation of the wallet
|
|
55
|
+
*/
|
|
56
|
+
exportUniversalWalletJSON: (password: string) => any;
|
|
57
|
+
setNetwork: (networkId: string) => Promise<void>;
|
|
58
|
+
getNetworkId: () => string;
|
|
59
|
+
resolveDocumentNetwork: (document: any) => Promise<DocumentResolverResult>;
|
|
60
|
+
dataStore: DataStore;
|
|
61
|
+
} & IV1Wallet;
|
|
62
|
+
export type CreateWalletProps = DataStoreConfigs & {};
|
|
63
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,sBAAsB,EACtB,cAAc,EACf,MAAM,8CAA8C,CAAC;AACtD,OAAO,EAAC,QAAQ,EAAC,MAAM,mDAAmD,CAAC;AAC3E,OAAO,EAAC,YAAY,EAA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E,CAAC,QAAQ,EAAE,GAAG,KAAK,OAAO,CAAC,sBAAsB,CAAC,CAAC;IAC3E,SAAS,EAAE,SAAS,CAAC;CACtB,GAAG,SAAS,CAAC;AAEd,MAAM,MAAM,iBAAiB,GAAG,gBAAgB,GAAG,EAAE,CAAC"}
|
package/lib/types.js
ADDED
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IWallet } from './types';
|
|
2
|
+
export declare function toV1Wallet(wallet: IWallet): Promise<IWallet>;
|
|
3
|
+
export type KeypairType = 'sr25519' | 'ed25519' | 'ecdsa';
|
|
4
|
+
/**
|
|
5
|
+
* Wallet service methods
|
|
6
|
+
* @param wallet
|
|
7
|
+
*/
|
|
8
|
+
export declare function toV1WalletService(wallet: IWallet): {
|
|
9
|
+
getDocumentById: (id: any) => Promise<any>;
|
|
10
|
+
createAccountDocuments: (params: {
|
|
11
|
+
name: string;
|
|
12
|
+
json?: string;
|
|
13
|
+
password?: string;
|
|
14
|
+
mnemonic?: string;
|
|
15
|
+
type?: KeypairType;
|
|
16
|
+
derivePath?: string;
|
|
17
|
+
hasBackup?: boolean;
|
|
18
|
+
}) => Promise<any[]>;
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=v1-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v1-helpers.d.ts","sourceRoot":"","sources":["../src/v1-helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,OAAO,EAAC,MAAM,SAAS,CAAC;AAS3C,wBAAsB,UAAU,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CA6DlE;AAED,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AAE1D;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO;;qCAQN;QACrC,MAAM,MAAM,CAAC;QACb,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,IAAI,CAAC,EAAE,WAAW,CAAC;QACnB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,SAAS,CAAC,EAAE,OAAO,CAAC;KACrB;EAgEJ"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.toV1WalletService = exports.toV1Wallet = void 0;
|
|
27
|
+
const account_provider_1 = require("./account-provider");
|
|
28
|
+
const walletServiceConfigs = __importStar(require("@docknetwork/wallet-sdk-wasm/src/services/wallet/configs"));
|
|
29
|
+
const index_1 = require("@docknetwork/wallet-sdk-wasm/src/services/keyring/index");
|
|
30
|
+
const wallet_1 = require("@docknetwork/wallet-sdk-wasm/src/services/wallet");
|
|
31
|
+
const uuid_1 = require("uuid");
|
|
32
|
+
async function toV1Wallet(wallet) {
|
|
33
|
+
const accounts = await (0, account_provider_1.createAccountProvider)({
|
|
34
|
+
wallet,
|
|
35
|
+
});
|
|
36
|
+
const v1Wallet = {
|
|
37
|
+
accounts: accounts,
|
|
38
|
+
create(json) {
|
|
39
|
+
return wallet.addDocument(document);
|
|
40
|
+
},
|
|
41
|
+
deleteWallet() {
|
|
42
|
+
return wallet.deleteWallet();
|
|
43
|
+
},
|
|
44
|
+
exportDocuments: (params) => {
|
|
45
|
+
return wallet_1.walletService.exportDocuments(params);
|
|
46
|
+
},
|
|
47
|
+
ensureNetwork() {
|
|
48
|
+
return Promise.resolve(undefined);
|
|
49
|
+
},
|
|
50
|
+
async query({ id, type, }) {
|
|
51
|
+
if (id) {
|
|
52
|
+
return [await wallet.getDocumentById(id)].filter(item => !!item);
|
|
53
|
+
}
|
|
54
|
+
if (type) {
|
|
55
|
+
return wallet.getDocumentsByType(type);
|
|
56
|
+
}
|
|
57
|
+
return wallet.getAllDocuments();
|
|
58
|
+
},
|
|
59
|
+
remove(id) {
|
|
60
|
+
return wallet.removeDocument(id);
|
|
61
|
+
},
|
|
62
|
+
add(json) {
|
|
63
|
+
return wallet.addDocument(json);
|
|
64
|
+
},
|
|
65
|
+
resolveCorrelations(id) {
|
|
66
|
+
return wallet.getDocumentCorrelations(id);
|
|
67
|
+
},
|
|
68
|
+
sync() {
|
|
69
|
+
return Promise.resolve(undefined);
|
|
70
|
+
},
|
|
71
|
+
update(json) {
|
|
72
|
+
return wallet.updateDocument(json);
|
|
73
|
+
},
|
|
74
|
+
upsert(json) {
|
|
75
|
+
return wallet.upsertDocument(json);
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
const newWallet = {
|
|
79
|
+
...v1Wallet,
|
|
80
|
+
...wallet,
|
|
81
|
+
};
|
|
82
|
+
accounts.wallet = newWallet;
|
|
83
|
+
return newWallet;
|
|
84
|
+
}
|
|
85
|
+
exports.toV1Wallet = toV1Wallet;
|
|
86
|
+
/**
|
|
87
|
+
* Wallet service methods
|
|
88
|
+
* @param wallet
|
|
89
|
+
*/
|
|
90
|
+
function toV1WalletService(wallet) {
|
|
91
|
+
return {
|
|
92
|
+
getDocumentById: id => {
|
|
93
|
+
return wallet.getDocumentById(id);
|
|
94
|
+
},
|
|
95
|
+
// accounts are not required in a wallet
|
|
96
|
+
// Ideally should move this code to the accounts provider file
|
|
97
|
+
// and make account provider available on its own package
|
|
98
|
+
createAccountDocuments: async (params) => {
|
|
99
|
+
walletServiceConfigs.validation.createAccountDocuments(params);
|
|
100
|
+
const { name, type = 'sr25519', derivePath, mnemonic, json, password, hasBackup } = params;
|
|
101
|
+
const keyringJson = json
|
|
102
|
+
? await index_1.keyringService.addFromJson({ jsonData: json, password })
|
|
103
|
+
: await index_1.keyringService.getKeyringPairJSON({ mnemonic, derivePath, type });
|
|
104
|
+
const correlations = [];
|
|
105
|
+
correlations.push({
|
|
106
|
+
'@context': ['https://w3id.org/wallet/v1'],
|
|
107
|
+
id: (0, uuid_1.v4)(),
|
|
108
|
+
type: 'KeyringPair',
|
|
109
|
+
value: keyringJson,
|
|
110
|
+
});
|
|
111
|
+
correlations.push({
|
|
112
|
+
'@context': ['https://w3id.org/wallet/v1'],
|
|
113
|
+
id: (0, uuid_1.v4)(),
|
|
114
|
+
type: 'Currency',
|
|
115
|
+
value: 0,
|
|
116
|
+
symbol: 'DOCK',
|
|
117
|
+
});
|
|
118
|
+
if (mnemonic) {
|
|
119
|
+
correlations.push({
|
|
120
|
+
'@context': ['https://w3id.org/wallet/v1'],
|
|
121
|
+
id: (0, uuid_1.v4)(),
|
|
122
|
+
type: 'Mnemonic',
|
|
123
|
+
value: mnemonic,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
const correlationsDocs = [];
|
|
127
|
+
for (let i = 0; i < correlations.length; i++) {
|
|
128
|
+
const doc = correlations[i];
|
|
129
|
+
const addedDoc = await wallet.addDocument(doc);
|
|
130
|
+
correlationsDocs.push(addedDoc);
|
|
131
|
+
}
|
|
132
|
+
const addressDocument = await wallet.addDocument({
|
|
133
|
+
'@context': ['https://w3id.org/wallet/v1'],
|
|
134
|
+
id: keyringJson.address,
|
|
135
|
+
type: 'Address',
|
|
136
|
+
value: keyringJson.address,
|
|
137
|
+
address: keyringJson.address,
|
|
138
|
+
name,
|
|
139
|
+
hasBackup,
|
|
140
|
+
correlation: correlations.map(doc => doc.id),
|
|
141
|
+
});
|
|
142
|
+
return [addressDocument, ...correlationsDocs];
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
exports.toV1WalletService = toV1WalletService;
|
|
147
|
+
//# sourceMappingURL=v1-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v1-helpers.js","sourceRoot":"","sources":["../src/v1-helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,yDAAyD;AAEzD,+GAAiG;AACjG,mFAAuF;AACvF,6EAA+E;AAC/E,+BAAgC;AAGzB,KAAK,UAAU,UAAU,CAAC,MAAe;IAC9C,MAAM,QAAQ,GAAG,MAAM,IAAA,wCAAqB,EAAC;QAC3C,MAAM;KACP,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG;QACf,QAAQ,EAAE,QAAQ;QAClB,MAAM,CAAC,IAAS;YACd,OAAO,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QACtC,CAAC;QACD,YAAY;YACV,OAAO,MAAM,CAAC,YAAY,EAAE,CAAC;QAC/B,CAAC;QACD,eAAe,EAAE,CAAC,MAAwB,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,IAAI,EAAE,UAAU;oBAChB,KAAK,EAAE,QAAQ;iBAChB,CAAC,CAAC;aACJ;YAED,MAAM,gBAAgB,GAAG,EAAE,CAAC;YAE5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBAC5C,MAAM,GAAG,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;gBAC5B,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;gBAC/C,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;aACjC;YAED,MAAM,eAAe,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC;gBAC/C,UAAU,EAAE,CAAC,4BAA4B,CAAC;gBAC1C,EAAE,EAAE,WAAW,CAAC,OAAO;gBACvB,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE,WAAW,CAAC,OAAO;gBAC1B,OAAO,EAAE,WAAW,CAAC,OAAO;gBAC5B,IAAI;gBACJ,SAAS;gBACT,WAAW,EAAE,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC;aAC7C,CAAC,CAAC;YAEH,OAAO,CAAC,eAAe,EAAE,GAAG,gBAAgB,CAAC,CAAC;QAChD,CAAC;KACF,CAAC;AACJ,CAAC;AAhFD,8CAgFC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ICredentialProvider } from './credential-provider';
|
|
3
|
+
import { IWallet } from './types';
|
|
4
|
+
import { EventEmitter } from 'events';
|
|
5
|
+
import { IDIDProvider } from './did-provider';
|
|
6
|
+
export declare enum VerificationStatus {
|
|
7
|
+
Started = "Started",
|
|
8
|
+
LoadingTemplate = "LoadingTemplate",
|
|
9
|
+
Filtering = "Filtering",
|
|
10
|
+
FetchingProvingKey = "FetchingProvingKey",
|
|
11
|
+
Error = "Error",
|
|
12
|
+
NoCredentialsInTheWallet = "NoCredentialsInTheWallet",
|
|
13
|
+
SelectingCredentials = "SelectingCredentials"
|
|
14
|
+
}
|
|
15
|
+
type CredentialId = string;
|
|
16
|
+
type CredentialSelection = {
|
|
17
|
+
credential: any;
|
|
18
|
+
attributesToReveal?: string[];
|
|
19
|
+
};
|
|
20
|
+
type CredentialSelectionMap = Map<CredentialId, CredentialSelection>;
|
|
21
|
+
export declare function createVerificationController({ wallet, credentialProvider, didProvider, }: {
|
|
22
|
+
wallet: IWallet;
|
|
23
|
+
credentialProvider?: ICredentialProvider;
|
|
24
|
+
didProvider?: IDIDProvider;
|
|
25
|
+
}): {
|
|
26
|
+
emitter: EventEmitter;
|
|
27
|
+
selectedCredentials: CredentialSelectionMap;
|
|
28
|
+
getStatus: () => VerificationStatus;
|
|
29
|
+
getStatusData: () => any;
|
|
30
|
+
submitPresentation: (presentation: any) => Promise<any>;
|
|
31
|
+
getSelectedDID(): any;
|
|
32
|
+
setSelectedDID: (did: string) => void;
|
|
33
|
+
start: ({ template }: {
|
|
34
|
+
template: string | any;
|
|
35
|
+
}) => Promise<void>;
|
|
36
|
+
isBBSPlusCredential: (credential: any) => Promise<any>;
|
|
37
|
+
loadCredentials: () => Promise<void>;
|
|
38
|
+
getFilteredCredentials: () => any[];
|
|
39
|
+
createPresentation: () => Promise<any>;
|
|
40
|
+
evaluatePresentation: (presentation: any) => {
|
|
41
|
+
isValid: boolean;
|
|
42
|
+
errors: import("@sphereon/pex").Checked[];
|
|
43
|
+
warnings: import("@sphereon/pex").Checked[];
|
|
44
|
+
};
|
|
45
|
+
getTemplateJSON(): any;
|
|
46
|
+
};
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=verification-controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verification-controller.d.ts","sourceRoot":"","sources":["../src/verification-controller.ts"],"names":[],"mappings":";AAGA,OAAO,EAEL,mBAAmB,EACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAC,OAAO,EAAC,MAAM,SAAS,CAAC;AAChC,OAAO,EAAC,YAAY,EAAC,MAAM,QAAQ,CAAC;AAGpC,OAAO,EAAoB,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAG/D,oBAAY,kBAAkB;IAC5B,OAAO,YAAY;IACnB,eAAe,oBAAoB;IACnC,SAAS,cAAc;IACvB,kBAAkB,uBAAuB;IACzC,KAAK,UAAU;IACf,wBAAwB,6BAA6B;IACrD,oBAAoB,yBAAyB;CAC9C;AAMD,KAAK,YAAY,GAAG,MAAM,CAAC;AAC3B,KAAK,mBAAmB,GAAG;IACzB,UAAU,EAAE,GAAG,CAAC;IAChB,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC/B,CAAC;AACF,KAAK,sBAAsB,GAAG,GAAG,CAAC,YAAY,EAAE,mBAAmB,CAAC,CAAC;AAErE,wBAAgB,4BAA4B,CAAC,EAC3C,MAAM,EACN,kBAAkB,EAClB,WAAW,GACZ,EAAE;IACD,MAAM,EAAE,OAAO,CAAC;IAChB,kBAAkB,CAAC,EAAE,mBAAmB,CAAC;IACzC,WAAW,CAAC,EAAE,YAAY,CAAC;CAC5B;;;;;;;0BAuL8B,MAAM;;kBAhJS,MAAM,GAAG,GAAG;;;;;;;;;;;;EAiMzD"}
|