@0xpolygonid/js-sdk 1.21.3 → 1.24.1
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/dist/browser/esm/index.js +4378 -545
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/umd/index.js +4388 -545
- package/dist/browser/umd/index.js.map +1 -1
- package/dist/node/cjs/credentials/credential-wallet.js +11 -78
- package/dist/node/cjs/credentials/index.js +1 -0
- package/dist/node/cjs/credentials/status/did-resolver-revocation.js +21 -0
- package/dist/node/cjs/iden3comm/constants.js +25 -1
- package/dist/node/cjs/iden3comm/handlers/auth.js +52 -8
- package/dist/node/cjs/iden3comm/handlers/common.js +13 -1
- package/dist/node/cjs/iden3comm/handlers/contract-request.js +5 -1
- package/dist/node/cjs/iden3comm/handlers/credential-proposal.js +14 -3
- package/dist/node/cjs/iden3comm/handlers/fetch.js +44 -2
- package/dist/node/cjs/iden3comm/handlers/message-handler.js +4 -0
- package/dist/node/cjs/iden3comm/handlers/payment.js +265 -28
- package/dist/node/cjs/iden3comm/handlers/revocation-status.js +4 -0
- package/dist/node/cjs/iden3comm/index.js +1 -0
- package/dist/node/cjs/iden3comm/packageManager.js +12 -0
- package/dist/node/cjs/iden3comm/packers/jws.js +21 -0
- package/dist/node/cjs/iden3comm/packers/plain.js +19 -0
- package/dist/node/cjs/iden3comm/packers/zkp.js +25 -0
- package/dist/node/cjs/iden3comm/types/index.js +1 -0
- package/dist/node/cjs/iden3comm/types/protocol/accept-profile.js +2 -0
- package/dist/node/cjs/iden3comm/utils/accept-profile.js +107 -0
- package/dist/node/cjs/iden3comm/utils/index.js +1 -0
- package/dist/node/cjs/storage/blockchain/abi/ERC20.json +1 -0
- package/dist/node/cjs/storage/blockchain/abi/ERC20Permit.json +1 -0
- package/dist/node/cjs/storage/blockchain/did-resolver-readonly-storage.js +72 -0
- package/dist/node/cjs/storage/blockchain/erc20-helper.js +59 -0
- package/dist/node/cjs/storage/blockchain/index.js +3 -0
- package/dist/node/cjs/storage/blockchain/onchain-issuer-adapter/non-merklized/version/v0.0.1/onchain-non-merklized-issuer-adapter.js +245 -0
- package/dist/node/cjs/storage/blockchain/onchain-issuer.js +82 -0
- package/dist/node/cjs/storage/blockchain/onchain-zkp-verifier.js +38 -34
- package/dist/node/cjs/storage/interfaces/index.js +1 -0
- package/dist/node/cjs/storage/interfaces/onchain-issuer.js +2 -0
- package/dist/node/cjs/utils/did-helper.js +3 -3
- package/dist/node/cjs/verifiable/constants.js +29 -11
- package/dist/node/cjs/verifiable/credential.js +86 -0
- package/dist/node/esm/credentials/credential-wallet.js +12 -79
- package/dist/node/esm/credentials/index.js +1 -0
- package/dist/node/esm/credentials/status/did-resolver-revocation.js +17 -0
- package/dist/node/esm/iden3comm/constants.js +24 -0
- package/dist/node/esm/iden3comm/handlers/auth.js +55 -11
- package/dist/node/esm/iden3comm/handlers/common.js +11 -0
- package/dist/node/esm/iden3comm/handlers/contract-request.js +7 -3
- package/dist/node/esm/iden3comm/handlers/credential-proposal.js +15 -4
- package/dist/node/esm/iden3comm/handlers/fetch.js +44 -2
- package/dist/node/esm/iden3comm/handlers/message-handler.js +4 -0
- package/dist/node/esm/iden3comm/handlers/payment.js +264 -29
- package/dist/node/esm/iden3comm/handlers/revocation-status.js +4 -0
- package/dist/node/esm/iden3comm/index.js +1 -0
- package/dist/node/esm/iden3comm/packageManager.js +12 -0
- package/dist/node/esm/iden3comm/packers/jws.js +22 -1
- package/dist/node/esm/iden3comm/packers/plain.js +19 -0
- package/dist/node/esm/iden3comm/packers/zkp.js +26 -1
- package/dist/node/esm/iden3comm/types/index.js +1 -0
- package/dist/node/esm/iden3comm/types/protocol/accept-profile.js +1 -0
- package/dist/node/esm/iden3comm/utils/accept-profile.js +102 -0
- package/dist/node/esm/iden3comm/utils/index.js +1 -0
- package/dist/node/esm/storage/blockchain/abi/ERC20.json +1 -0
- package/dist/node/esm/storage/blockchain/abi/ERC20Permit.json +1 -0
- package/dist/node/esm/storage/blockchain/did-resolver-readonly-storage.js +68 -0
- package/dist/node/esm/storage/blockchain/erc20-helper.js +51 -0
- package/dist/node/esm/storage/blockchain/index.js +3 -0
- package/dist/node/esm/storage/blockchain/onchain-issuer-adapter/non-merklized/version/v0.0.1/onchain-non-merklized-issuer-adapter.js +241 -0
- package/dist/node/esm/storage/blockchain/onchain-issuer.js +78 -0
- package/dist/node/esm/storage/blockchain/onchain-zkp-verifier.js +38 -34
- package/dist/node/esm/storage/interfaces/index.js +1 -0
- package/dist/node/esm/storage/interfaces/onchain-issuer.js +1 -0
- package/dist/node/esm/utils/did-helper.js +3 -3
- package/dist/node/esm/verifiable/constants.js +28 -10
- package/dist/node/esm/verifiable/credential.js +88 -2
- package/dist/types/credentials/credential-wallet.d.ts +0 -6
- package/dist/types/credentials/index.d.ts +1 -0
- package/dist/types/credentials/models.d.ts +8 -0
- package/dist/types/credentials/status/did-resolver-revocation.d.ts +7 -0
- package/dist/types/iden3comm/constants.d.ts +16 -0
- package/dist/types/iden3comm/handlers/auth.d.ts +19 -7
- package/dist/types/iden3comm/handlers/common.d.ts +7 -1
- package/dist/types/iden3comm/handlers/contract-request.d.ts +2 -2
- package/dist/types/iden3comm/handlers/credential-proposal.d.ts +9 -4
- package/dist/types/iden3comm/handlers/fetch.d.ts +30 -6
- package/dist/types/iden3comm/handlers/message-handler.d.ts +6 -0
- package/dist/types/iden3comm/handlers/payment.d.ts +71 -10
- package/dist/types/iden3comm/handlers/revocation-status.d.ts +2 -2
- package/dist/types/iden3comm/index.d.ts +1 -0
- package/dist/types/iden3comm/packageManager.d.ts +4 -0
- package/dist/types/iden3comm/packers/jws.d.ts +5 -0
- package/dist/types/iden3comm/packers/plain.d.ts +4 -0
- package/dist/types/iden3comm/packers/zkp.d.ts +6 -0
- package/dist/types/iden3comm/types/index.d.ts +1 -0
- package/dist/types/iden3comm/types/packageManager.d.ts +14 -0
- package/dist/types/iden3comm/types/packer.d.ts +25 -0
- package/dist/types/iden3comm/types/protocol/accept-profile.d.ts +7 -0
- package/dist/types/iden3comm/types/protocol/auth.d.ts +1 -0
- package/dist/types/iden3comm/types/protocol/credentials.d.ts +6 -6
- package/dist/types/iden3comm/types/protocol/messages.d.ts +2 -2
- package/dist/types/iden3comm/types/protocol/payment.d.ts +87 -13
- package/dist/types/iden3comm/types/protocol/proof.d.ts +3 -3
- package/dist/types/iden3comm/types/protocol/revocation.d.ts +2 -2
- package/dist/types/iden3comm/utils/accept-profile.d.ts +3 -0
- package/dist/types/iden3comm/utils/index.d.ts +1 -0
- package/dist/types/storage/blockchain/did-resolver-readonly-storage.d.ts +16 -0
- package/dist/types/storage/blockchain/erc20-helper.d.ts +19 -0
- package/dist/types/storage/blockchain/index.d.ts +3 -0
- package/dist/types/storage/blockchain/onchain-issuer-adapter/non-merklized/version/v0.0.1/onchain-non-merklized-issuer-adapter.d.ts +66 -0
- package/dist/types/storage/blockchain/onchain-issuer.d.ts +40 -0
- package/dist/types/storage/blockchain/onchain-zkp-verifier.d.ts +11 -12
- package/dist/types/storage/entities/state.d.ts +2 -0
- package/dist/types/storage/interfaces/index.d.ts +1 -0
- package/dist/types/storage/interfaces/onchain-issuer.d.ts +12 -0
- package/dist/types/verifiable/constants.d.ts +28 -11
- package/dist/types/verifiable/credential.d.ts +15 -2
- package/package.json +3 -2
|
@@ -57,40 +57,18 @@ class CredentialWallet {
|
|
|
57
57
|
if (!schema.$metadata.uris['jsonLdContext']) {
|
|
58
58
|
throw new Error('jsonLdContext is missing is the schema');
|
|
59
59
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
// do copy of request to avoid mutation
|
|
61
|
+
const r = { ...request };
|
|
62
|
+
r.context = r.context ?? [];
|
|
63
|
+
if (r.displayMethod?.type === verifiable_1.DisplayMethodType.Iden3BasicDisplayMethodV1 &&
|
|
64
|
+
!r.context.includes(verifiable_1.VerifiableConstants.JSONLD_SCHEMA.IDEN3_DISPLAY_METHOD)) {
|
|
65
|
+
r.context.push(verifiable_1.VerifiableConstants.JSONLD_SCHEMA.IDEN3_DISPLAY_METHOD);
|
|
64
66
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
];
|
|
71
|
-
const credentialType = [
|
|
72
|
-
verifiable_1.VerifiableConstants.CREDENTIAL_TYPE.W3C_VERIFIABLE_CREDENTIAL,
|
|
73
|
-
request.type
|
|
74
|
-
];
|
|
75
|
-
const expirationDate = !request.expiration || request.expiration == 0 ? null : request.expiration;
|
|
76
|
-
const credentialSubject = request.credentialSubject;
|
|
77
|
-
credentialSubject['type'] = request.type;
|
|
78
|
-
const cr = new verifiable_1.W3CCredential();
|
|
79
|
-
cr.id = `urn:${uuid.v4()}`;
|
|
80
|
-
cr['@context'] = context;
|
|
81
|
-
cr.type = credentialType;
|
|
82
|
-
cr.expirationDate = expirationDate ? new Date(expirationDate * 1000).toISOString() : undefined;
|
|
83
|
-
cr.refreshService = request.refreshService;
|
|
84
|
-
cr.displayMethod = request.displayMethod;
|
|
85
|
-
cr.issuanceDate = new Date().toISOString();
|
|
86
|
-
cr.credentialSubject = credentialSubject;
|
|
87
|
-
cr.issuer = issuer.string();
|
|
88
|
-
cr.credentialSchema = {
|
|
89
|
-
id: request.credentialSchema,
|
|
90
|
-
type: verifiable_1.VerifiableConstants.JSON_SCHEMA_VALIDATOR
|
|
91
|
-
};
|
|
92
|
-
cr.credentialStatus = this.buildCredentialStatus(request, issuer);
|
|
93
|
-
return cr;
|
|
67
|
+
r.context.push(schema.$metadata.uris['jsonLdContext']);
|
|
68
|
+
r.expiration = r.expiration ? r.expiration * 1000 : undefined;
|
|
69
|
+
r.id = r.id ? r.id : `urn:${uuid.v4()}`;
|
|
70
|
+
r.issuanceDate = r.issuanceDate ? r.issuanceDate * 1000 : Date.now();
|
|
71
|
+
return verifiable_1.W3CCredential.fromCredentialRequest(issuer, r);
|
|
94
72
|
};
|
|
95
73
|
// if no credential status resolvers are provided
|
|
96
74
|
// register default issuer resolver
|
|
@@ -160,51 +138,6 @@ class CredentialWallet {
|
|
|
160
138
|
}
|
|
161
139
|
return statusResolver.resolve(credStatus, credentialStatusResolveOptions);
|
|
162
140
|
}
|
|
163
|
-
/**
|
|
164
|
-
* Builds credential status
|
|
165
|
-
* @param {CredentialRequest} request
|
|
166
|
-
* @returns `CredentialStatus`
|
|
167
|
-
*/
|
|
168
|
-
buildCredentialStatus(request, issuer) {
|
|
169
|
-
const credentialStatus = {
|
|
170
|
-
id: request.revocationOpts.id,
|
|
171
|
-
type: request.revocationOpts.type,
|
|
172
|
-
revocationNonce: request.revocationOpts.nonce
|
|
173
|
-
};
|
|
174
|
-
switch (request.revocationOpts.type) {
|
|
175
|
-
case verifiable_1.CredentialStatusType.SparseMerkleTreeProof:
|
|
176
|
-
return {
|
|
177
|
-
...credentialStatus,
|
|
178
|
-
id: `${credentialStatus.id.replace(/\/$/, '')}/${credentialStatus.revocationNonce}`
|
|
179
|
-
};
|
|
180
|
-
case verifiable_1.CredentialStatusType.Iden3ReverseSparseMerkleTreeProof:
|
|
181
|
-
return {
|
|
182
|
-
...credentialStatus,
|
|
183
|
-
id: request.revocationOpts.issuerState
|
|
184
|
-
? `${credentialStatus.id.replace(/\/$/, '')}/node?state=${request.revocationOpts.issuerState}`
|
|
185
|
-
: `${credentialStatus.id.replace(/\/$/, '')}`
|
|
186
|
-
};
|
|
187
|
-
case verifiable_1.CredentialStatusType.Iden3OnchainSparseMerkleTreeProof2023: {
|
|
188
|
-
const issuerId = js_iden3_core_1.DID.idFromDID(issuer);
|
|
189
|
-
const chainId = (0, js_iden3_core_1.getChainId)(js_iden3_core_1.DID.blockchainFromId(issuerId), js_iden3_core_1.DID.networkIdFromId(issuerId));
|
|
190
|
-
const searchParams = [
|
|
191
|
-
['revocationNonce', request.revocationOpts.nonce?.toString() || ''],
|
|
192
|
-
['contractAddress', `${chainId}:${request.revocationOpts.id}`],
|
|
193
|
-
['state', request.revocationOpts.issuerState || '']
|
|
194
|
-
]
|
|
195
|
-
.filter(([, value]) => Boolean(value))
|
|
196
|
-
.map(([key, value]) => `${key}=${value}`)
|
|
197
|
-
.join('&');
|
|
198
|
-
return {
|
|
199
|
-
...credentialStatus,
|
|
200
|
-
// `[did]:[methodid]:[chain]:[network]:[id]/credentialStatus?(revocationNonce=value)&[contractAddress=[chainID]:[contractAddress]]&(state=issuerState)`
|
|
201
|
-
id: `${issuer.string()}/credentialStatus?${searchParams}`
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
default:
|
|
205
|
-
return credentialStatus;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
141
|
/**
|
|
209
142
|
* {@inheritDoc ICredentialWallet.findById}
|
|
210
143
|
*/
|
|
@@ -20,6 +20,7 @@ __exportStar(require("./status/sparse-merkle-tree"), exports);
|
|
|
20
20
|
__exportStar(require("./status/resolver"), exports);
|
|
21
21
|
__exportStar(require("./status/agent-revocation"), exports);
|
|
22
22
|
__exportStar(require("./status/credential-status-publisher"), exports);
|
|
23
|
+
__exportStar(require("./status/did-resolver-revocation"), exports);
|
|
23
24
|
__exportStar(require("./credential-wallet"), exports);
|
|
24
25
|
__exportStar(require("./rhs"), exports);
|
|
25
26
|
__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DidDocumentCredentialStatusResolver = void 0;
|
|
4
|
+
class DidDocumentCredentialStatusResolver {
|
|
5
|
+
constructor(didResolverUrl) {
|
|
6
|
+
this.didResolverUrl = didResolverUrl;
|
|
7
|
+
}
|
|
8
|
+
async resolve(credentialStatus, opts) {
|
|
9
|
+
if (!opts?.issuerDID) {
|
|
10
|
+
throw new Error('IssuerDID is not set in options');
|
|
11
|
+
}
|
|
12
|
+
const url = `${this.didResolverUrl}/1.0/credential-status/${encodeURIComponent(opts.issuerDID.string())}`;
|
|
13
|
+
const resp = await fetch(url, {
|
|
14
|
+
method: 'POST',
|
|
15
|
+
body: JSON.stringify(credentialStatus)
|
|
16
|
+
});
|
|
17
|
+
const data = await resp.json();
|
|
18
|
+
return data;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.DidDocumentCredentialStatusResolver = DidDocumentCredentialStatusResolver;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_AUTH_VERIFY_DELAY = exports.DEFAULT_PROOF_VERIFY_DELAY = exports.SUPPORTED_PUBLIC_KEY_TYPES = exports.MediaType = exports.PROTOCOL_MESSAGE_TYPE = void 0;
|
|
3
|
+
exports.DEFAULT_AUTH_VERIFY_DELAY = exports.DEFAULT_PROOF_VERIFY_DELAY = exports.defaultAcceptProfile = exports.AcceptJwsAlgorithms = exports.AcceptJwzAlgorithms = exports.AcceptAuthCircuits = exports.ProtocolVersion = exports.SUPPORTED_PUBLIC_KEY_TYPES = exports.MediaType = exports.PROTOCOL_MESSAGE_TYPE = void 0;
|
|
4
4
|
const IDEN3_PROTOCOL = 'https://iden3-communication.io/';
|
|
5
5
|
/**
|
|
6
6
|
* Constants for Iden3 protocol
|
|
@@ -76,5 +76,29 @@ exports.SUPPORTED_PUBLIC_KEY_TYPES = {
|
|
|
76
76
|
'JsonWebKey2020'
|
|
77
77
|
]
|
|
78
78
|
};
|
|
79
|
+
var ProtocolVersion;
|
|
80
|
+
(function (ProtocolVersion) {
|
|
81
|
+
ProtocolVersion["V1"] = "iden3comm/v1";
|
|
82
|
+
})(ProtocolVersion = exports.ProtocolVersion || (exports.ProtocolVersion = {}));
|
|
83
|
+
var AcceptAuthCircuits;
|
|
84
|
+
(function (AcceptAuthCircuits) {
|
|
85
|
+
AcceptAuthCircuits["AuthV2"] = "authV2";
|
|
86
|
+
AcceptAuthCircuits["AuthV3"] = "authV3";
|
|
87
|
+
})(AcceptAuthCircuits = exports.AcceptAuthCircuits || (exports.AcceptAuthCircuits = {}));
|
|
88
|
+
var AcceptJwzAlgorithms;
|
|
89
|
+
(function (AcceptJwzAlgorithms) {
|
|
90
|
+
AcceptJwzAlgorithms["Groth16"] = "groth16";
|
|
91
|
+
})(AcceptJwzAlgorithms = exports.AcceptJwzAlgorithms || (exports.AcceptJwzAlgorithms = {}));
|
|
92
|
+
var AcceptJwsAlgorithms;
|
|
93
|
+
(function (AcceptJwsAlgorithms) {
|
|
94
|
+
AcceptJwsAlgorithms["ES256K"] = "ES256K";
|
|
95
|
+
AcceptJwsAlgorithms["ES256KR"] = "ES256K-R";
|
|
96
|
+
})(AcceptJwsAlgorithms = exports.AcceptJwsAlgorithms || (exports.AcceptJwsAlgorithms = {}));
|
|
97
|
+
exports.defaultAcceptProfile = {
|
|
98
|
+
protocolVersion: ProtocolVersion.V1,
|
|
99
|
+
env: MediaType.ZKPMessage,
|
|
100
|
+
circuits: [AcceptAuthCircuits.AuthV2],
|
|
101
|
+
alg: [AcceptJwzAlgorithms.Groth16]
|
|
102
|
+
};
|
|
79
103
|
exports.DEFAULT_PROOF_VERIFY_DELAY = 1 * 60 * 60 * 1000; // 1 hour
|
|
80
104
|
exports.DEFAULT_AUTH_VERIFY_DELAY = 5 * 60 * 1000; // 5 minutes
|
|
@@ -33,15 +33,17 @@ const utils_1 = require("../../utils");
|
|
|
33
33
|
const common_1 = require("./common");
|
|
34
34
|
const circuits_1 = require("../../circuits");
|
|
35
35
|
const message_handler_1 = require("./message-handler");
|
|
36
|
+
const utils_2 = require("../utils");
|
|
36
37
|
/**
|
|
37
38
|
* createAuthorizationRequest is a function to create protocol authorization request
|
|
38
39
|
* @param {string} reason - reason to request proof
|
|
39
40
|
* @param {string} sender - sender did
|
|
40
41
|
* @param {string} callbackUrl - callback that user should use to send response
|
|
42
|
+
* @param {AuthorizationRequestCreateOptions} opts - authorization request options
|
|
41
43
|
* @returns `Promise<AuthorizationRequestMessage>`
|
|
42
44
|
*/
|
|
43
|
-
function createAuthorizationRequest(reason, sender, callbackUrl) {
|
|
44
|
-
return createAuthorizationRequestWithMessage(reason, '', sender, callbackUrl);
|
|
45
|
+
function createAuthorizationRequest(reason, sender, callbackUrl, opts) {
|
|
46
|
+
return createAuthorizationRequestWithMessage(reason, '', sender, callbackUrl, opts);
|
|
45
47
|
}
|
|
46
48
|
exports.createAuthorizationRequest = createAuthorizationRequest;
|
|
47
49
|
/**
|
|
@@ -50,9 +52,10 @@ exports.createAuthorizationRequest = createAuthorizationRequest;
|
|
|
50
52
|
* @param {string} message - message to sign in the response
|
|
51
53
|
* @param {string} sender - sender did
|
|
52
54
|
* @param {string} callbackUrl - callback that user should use to send response
|
|
55
|
+
* @param {AuthorizationRequestCreateOptions} opts - authorization request options
|
|
53
56
|
* @returns `Promise<AuthorizationRequestMessage>`
|
|
54
57
|
*/
|
|
55
|
-
function createAuthorizationRequestWithMessage(reason, message, sender, callbackUrl) {
|
|
58
|
+
function createAuthorizationRequestWithMessage(reason, message, sender, callbackUrl, opts) {
|
|
56
59
|
const uuidv4 = uuid.v4();
|
|
57
60
|
const request = {
|
|
58
61
|
id: uuidv4,
|
|
@@ -61,11 +64,14 @@ function createAuthorizationRequestWithMessage(reason, message, sender, callback
|
|
|
61
64
|
typ: constants_1.MediaType.PlainMessage,
|
|
62
65
|
type: constants_2.PROTOCOL_MESSAGE_TYPE.AUTHORIZATION_REQUEST_MESSAGE_TYPE,
|
|
63
66
|
body: {
|
|
67
|
+
accept: opts?.accept,
|
|
64
68
|
reason: reason,
|
|
65
69
|
message: message,
|
|
66
70
|
callbackUrl: callbackUrl,
|
|
67
|
-
scope: []
|
|
68
|
-
}
|
|
71
|
+
scope: opts?.scope ?? []
|
|
72
|
+
},
|
|
73
|
+
created_time: (0, js_iden3_core_1.getUnixTimestamp)(new Date()),
|
|
74
|
+
expires_time: opts?.expires_time ? (0, js_iden3_core_1.getUnixTimestamp)(opts.expires_time) : undefined
|
|
69
75
|
};
|
|
70
76
|
return request;
|
|
71
77
|
}
|
|
@@ -125,17 +131,18 @@ class AuthHandler extends message_handler_1.AbstractMessageHandler {
|
|
|
125
131
|
}
|
|
126
132
|
// override sender did if it's explicitly specified in the auth request
|
|
127
133
|
const to = authRequest.to ? js_iden3_core_1.DID.parse(authRequest.to) : ctx.senderDid;
|
|
128
|
-
const mediaType = ctx.mediaType || constants_1.MediaType.ZKPMessage;
|
|
129
134
|
const guid = uuid.v4();
|
|
130
135
|
if (!authRequest.from) {
|
|
131
136
|
throw new Error('auth request should contain from field');
|
|
132
137
|
}
|
|
138
|
+
const responseType = constants_2.PROTOCOL_MESSAGE_TYPE.AUTHORIZATION_RESPONSE_MESSAGE_TYPE;
|
|
139
|
+
const mediaType = this.getSupportedMediaTypeByProfile(ctx, responseType, authRequest.body.accept);
|
|
133
140
|
const from = js_iden3_core_1.DID.parse(authRequest.from);
|
|
134
141
|
const responseScope = await (0, common_1.processZeroKnowledgeProofRequests)(to, authRequest?.body.scope, from, this._proofService, { mediaType, supportedCircuits: this._supportedCircuits });
|
|
135
142
|
return {
|
|
136
143
|
id: guid,
|
|
137
|
-
typ:
|
|
138
|
-
type:
|
|
144
|
+
typ: mediaType,
|
|
145
|
+
type: responseType,
|
|
139
146
|
thid: authRequest.thid ?? guid,
|
|
140
147
|
body: {
|
|
141
148
|
message: authRequest?.body?.message,
|
|
@@ -150,6 +157,9 @@ class AuthHandler extends message_handler_1.AbstractMessageHandler {
|
|
|
150
157
|
*/
|
|
151
158
|
async handleAuthorizationRequest(did, request, opts) {
|
|
152
159
|
const authRequest = await this.parseAuthorizationRequest(request);
|
|
160
|
+
if (!opts?.allowExpiredMessages) {
|
|
161
|
+
(0, common_1.verifyExpiresTime)(authRequest);
|
|
162
|
+
}
|
|
153
163
|
if (!opts) {
|
|
154
164
|
opts = {
|
|
155
165
|
mediaType: constants_1.MediaType.ZKPMessage
|
|
@@ -239,6 +249,9 @@ class AuthHandler extends message_handler_1.AbstractMessageHandler {
|
|
|
239
249
|
* @inheritdoc IAuthHandler#handleAuthorizationResponse
|
|
240
250
|
*/
|
|
241
251
|
async handleAuthorizationResponse(response, request, opts) {
|
|
252
|
+
if (!opts?.allowExpiredMessages) {
|
|
253
|
+
(0, common_1.verifyExpiresTime)(response);
|
|
254
|
+
}
|
|
242
255
|
const authResp = (await this.handleAuthResponse(response, {
|
|
243
256
|
request,
|
|
244
257
|
acceptedStateTransitionDelay: opts?.acceptedStateTransitionDelay,
|
|
@@ -272,5 +285,36 @@ class AuthHandler extends message_handler_1.AbstractMessageHandler {
|
|
|
272
285
|
}
|
|
273
286
|
}
|
|
274
287
|
}
|
|
288
|
+
getSupportedMediaTypeByProfile(ctx, responseType, profile) {
|
|
289
|
+
let mediaType;
|
|
290
|
+
if (profile?.length) {
|
|
291
|
+
const supportedMediaTypes = [];
|
|
292
|
+
for (const acceptProfile of profile) {
|
|
293
|
+
// 1. check protocol version
|
|
294
|
+
const { protocolVersion, env } = (0, utils_2.parseAcceptProfile)(acceptProfile);
|
|
295
|
+
const responseTypeVersion = Number(responseType.split('/').at(-2));
|
|
296
|
+
if (protocolVersion !== constants_1.ProtocolVersion.V1 ||
|
|
297
|
+
(protocolVersion === constants_1.ProtocolVersion.V1 &&
|
|
298
|
+
(responseTypeVersion < 1 || responseTypeVersion >= 2))) {
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
// 2. check packer support
|
|
302
|
+
if (this._packerMgr.isProfileSupported(env, acceptProfile)) {
|
|
303
|
+
supportedMediaTypes.push(env);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
if (!supportedMediaTypes.length) {
|
|
307
|
+
throw new Error('no packer with profile which meets `accept` header requirements');
|
|
308
|
+
}
|
|
309
|
+
mediaType = supportedMediaTypes[0];
|
|
310
|
+
if (ctx.mediaType && supportedMediaTypes.includes(ctx.mediaType)) {
|
|
311
|
+
mediaType = ctx.mediaType;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
mediaType = ctx.mediaType || constants_1.MediaType.ZKPMessage;
|
|
316
|
+
}
|
|
317
|
+
return mediaType;
|
|
318
|
+
}
|
|
275
319
|
}
|
|
276
320
|
exports.AuthHandler = AuthHandler;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.processZeroKnowledgeProofRequests = void 0;
|
|
3
|
+
exports.verifyExpiresTime = exports.processZeroKnowledgeProofRequests = void 0;
|
|
4
4
|
const js_crypto_1 = require("@iden3/js-crypto");
|
|
5
5
|
const utils_1 = require("../../utils");
|
|
6
|
+
const js_iden3_core_1 = require("@iden3/js-iden3-core");
|
|
6
7
|
/**
|
|
7
8
|
* Groups the ZeroKnowledgeProofRequest objects based on their groupId.
|
|
8
9
|
* Returns a Map where the key is the groupId and the value is an object containing the query and linkNonce.
|
|
@@ -83,3 +84,14 @@ const processZeroKnowledgeProofRequests = async (to, requests, from, proofServic
|
|
|
83
84
|
return zkpResponses;
|
|
84
85
|
};
|
|
85
86
|
exports.processZeroKnowledgeProofRequests = processZeroKnowledgeProofRequests;
|
|
87
|
+
/**
|
|
88
|
+
* Verifies that the expires_time field of a message is not in the past. Throws an error if it is.
|
|
89
|
+
*
|
|
90
|
+
* @param message - Basic message to verify.
|
|
91
|
+
*/
|
|
92
|
+
const verifyExpiresTime = (message) => {
|
|
93
|
+
if (message?.expires_time && message.expires_time < (0, js_iden3_core_1.getUnixTimestamp)(new Date())) {
|
|
94
|
+
throw new Error('Message expired');
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
exports.verifyExpiresTime = verifyExpiresTime;
|
|
@@ -110,7 +110,8 @@ class ContractRequestHandler extends message_handler_1.AbstractMessageHandler {
|
|
|
110
110
|
body: {
|
|
111
111
|
transaction_data: request.body.transaction_data,
|
|
112
112
|
scope: []
|
|
113
|
-
}
|
|
113
|
+
},
|
|
114
|
+
created_time: (0, js_iden3_core_1.getUnixTimestamp)(new Date())
|
|
114
115
|
};
|
|
115
116
|
for (const [txHash, zkpResponses] of txHashToZkpResponseMap) {
|
|
116
117
|
for (const zkpResponse of zkpResponses) {
|
|
@@ -134,6 +135,9 @@ class ContractRequestHandler extends message_handler_1.AbstractMessageHandler {
|
|
|
134
135
|
*/
|
|
135
136
|
async handleContractInvokeRequest(did, request, opts) {
|
|
136
137
|
const ciRequest = await this.parseContractInvokeRequest(request);
|
|
138
|
+
if (!opts.allowExpiredMessages) {
|
|
139
|
+
(0, common_1.verifyExpiresTime)(ciRequest);
|
|
140
|
+
}
|
|
137
141
|
if (ciRequest.body.transaction_data.method_id !== storage_1.FunctionSignatures.SubmitZKPResponseV1) {
|
|
138
142
|
throw new Error(`please use handle method to work with other method ids`);
|
|
139
143
|
}
|
|
@@ -30,6 +30,7 @@ const uuid = __importStar(require("uuid"));
|
|
|
30
30
|
const js_jwz_1 = require("@iden3/js-jwz");
|
|
31
31
|
const utils_1 = require("../../utils");
|
|
32
32
|
const message_handler_1 = require("./message-handler");
|
|
33
|
+
const common_1 = require("./common");
|
|
33
34
|
/**
|
|
34
35
|
* @beta
|
|
35
36
|
* createProposalRequest is a function to create protocol proposal-request protocol message
|
|
@@ -47,7 +48,9 @@ function createProposalRequest(sender, receiver, opts) {
|
|
|
47
48
|
to: receiver.string(),
|
|
48
49
|
typ: constants_1.MediaType.PlainMessage,
|
|
49
50
|
type: constants_1.PROTOCOL_MESSAGE_TYPE.PROPOSAL_REQUEST_MESSAGE_TYPE,
|
|
50
|
-
body: opts
|
|
51
|
+
body: opts,
|
|
52
|
+
created_time: (0, js_iden3_core_1.getUnixTimestamp)(new Date()),
|
|
53
|
+
expires_time: opts?.expires_time ? (0, js_iden3_core_1.getUnixTimestamp)(opts.expires_time) : undefined
|
|
51
54
|
};
|
|
52
55
|
return request;
|
|
53
56
|
}
|
|
@@ -60,7 +63,7 @@ exports.createProposalRequest = createProposalRequest;
|
|
|
60
63
|
* @param {Proposal[]} proposals - proposals
|
|
61
64
|
* @returns `Promise<ProposalRequestMessage>`
|
|
62
65
|
*/
|
|
63
|
-
function createProposal(sender, receiver, proposals) {
|
|
66
|
+
function createProposal(sender, receiver, proposals, opts) {
|
|
64
67
|
const uuidv4 = uuid.v4();
|
|
65
68
|
const request = {
|
|
66
69
|
id: uuidv4,
|
|
@@ -71,7 +74,9 @@ function createProposal(sender, receiver, proposals) {
|
|
|
71
74
|
type: constants_1.PROTOCOL_MESSAGE_TYPE.PROPOSAL_MESSAGE_TYPE,
|
|
72
75
|
body: {
|
|
73
76
|
proposals: proposals || []
|
|
74
|
-
}
|
|
77
|
+
},
|
|
78
|
+
created_time: (0, js_iden3_core_1.getUnixTimestamp)(new Date()),
|
|
79
|
+
expires_time: opts?.expires_time ? (0, js_iden3_core_1.getUnixTimestamp)(opts.expires_time) : undefined
|
|
75
80
|
};
|
|
76
81
|
return request;
|
|
77
82
|
}
|
|
@@ -210,6 +215,9 @@ class CredentialProposalHandler extends message_handler_1.AbstractMessageHandler
|
|
|
210
215
|
if (!proposalRequest.from) {
|
|
211
216
|
throw new Error(`failed request. empty 'from' field`);
|
|
212
217
|
}
|
|
218
|
+
if (!opts?.allowExpiredMessages) {
|
|
219
|
+
(0, common_1.verifyExpiresTime)(proposalRequest);
|
|
220
|
+
}
|
|
213
221
|
const senderDID = js_iden3_core_1.DID.parse(proposalRequest.from);
|
|
214
222
|
const message = await this.handleProposalRequestMessage(proposalRequest);
|
|
215
223
|
const response = utils_1.byteEncoder.encode(JSON.stringify(message));
|
|
@@ -227,6 +235,9 @@ class CredentialProposalHandler extends message_handler_1.AbstractMessageHandler
|
|
|
227
235
|
* @inheritdoc ICredentialProposalHandler#handleProposal
|
|
228
236
|
*/
|
|
229
237
|
async handleProposal(proposal, opts) {
|
|
238
|
+
if (!opts?.allowExpiredMessages) {
|
|
239
|
+
(0, common_1.verifyExpiresTime)(proposal);
|
|
240
|
+
}
|
|
230
241
|
if (opts?.proposalRequest && opts.proposalRequest.from !== proposal.to) {
|
|
231
242
|
throw new Error(`sender of the request is not a target of response - expected ${opts.proposalRequest.from}, given ${proposal.to}`);
|
|
232
243
|
}
|
|
@@ -33,6 +33,7 @@ const js_jwz_1 = require("@iden3/js-jwz");
|
|
|
33
33
|
const js_iden3_core_1 = require("@iden3/js-iden3-core");
|
|
34
34
|
const uuid = __importStar(require("uuid"));
|
|
35
35
|
const message_handler_1 = require("./message-handler");
|
|
36
|
+
const common_1 = require("./common");
|
|
36
37
|
/**
|
|
37
38
|
*
|
|
38
39
|
* Allows to handle Credential offer protocol message and return fetched credential
|
|
@@ -72,10 +73,34 @@ class FetchHandler extends message_handler_1.AbstractMessageHandler {
|
|
|
72
73
|
return this.handleFetchRequest(message);
|
|
73
74
|
case constants_2.PROTOCOL_MESSAGE_TYPE.CREDENTIAL_ISSUANCE_RESPONSE_MESSAGE_TYPE:
|
|
74
75
|
return this.handleIssuanceResponseMsg(message);
|
|
76
|
+
case constants_2.PROTOCOL_MESSAGE_TYPE.CREDENTIAL_ONCHAIN_OFFER_MESSAGE_TYPE: {
|
|
77
|
+
const result = await this.handleOnchainOfferMessage(message);
|
|
78
|
+
if (Array.isArray(result)) {
|
|
79
|
+
const credWallet = this.opts?.credentialWallet;
|
|
80
|
+
if (!credWallet)
|
|
81
|
+
throw new Error('Credential wallet is not provided');
|
|
82
|
+
await credWallet.saveAll(result);
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
75
87
|
default:
|
|
76
88
|
return super.handle(message, ctx);
|
|
77
89
|
}
|
|
78
90
|
}
|
|
91
|
+
async handleOnchainOfferMessage(offerMessage) {
|
|
92
|
+
if (!this.opts?.onchainIssuer) {
|
|
93
|
+
throw new Error('onchain issuer is not provided');
|
|
94
|
+
}
|
|
95
|
+
const credentials = [];
|
|
96
|
+
for (const credentialInfo of offerMessage.body.credentials) {
|
|
97
|
+
const issuerDID = js_iden3_core_1.DID.parse(offerMessage.from);
|
|
98
|
+
const userDID = js_iden3_core_1.DID.parse(offerMessage.to);
|
|
99
|
+
const credential = await this.opts.onchainIssuer.getCredential(issuerDID, userDID, BigInt(credentialInfo.id));
|
|
100
|
+
credentials.push(credential);
|
|
101
|
+
}
|
|
102
|
+
return credentials;
|
|
103
|
+
}
|
|
79
104
|
async handleOfferMessage(offerMessage, ctx) {
|
|
80
105
|
if (!ctx.mediaType) {
|
|
81
106
|
ctx.mediaType = constants_1.MediaType.ZKPMessage;
|
|
@@ -147,6 +172,9 @@ class FetchHandler extends message_handler_1.AbstractMessageHandler {
|
|
|
147
172
|
throw new Error(`jws packer options are required for ${constants_1.MediaType.SignedMessage}`);
|
|
148
173
|
}
|
|
149
174
|
const offerMessage = await FetchHandler.unpackMessage(this._packerMgr, offer, constants_2.PROTOCOL_MESSAGE_TYPE.CREDENTIAL_OFFER_MESSAGE_TYPE);
|
|
175
|
+
if (!opts?.allowExpiredMessages) {
|
|
176
|
+
(0, common_1.verifyExpiresTime)(offerMessage);
|
|
177
|
+
}
|
|
150
178
|
const result = await this.handleOfferMessage(offerMessage, {
|
|
151
179
|
mediaType: opts?.mediaType,
|
|
152
180
|
headers: opts?.headers,
|
|
@@ -157,6 +185,14 @@ class FetchHandler extends message_handler_1.AbstractMessageHandler {
|
|
|
157
185
|
}
|
|
158
186
|
throw new Error('invalid protocol message response');
|
|
159
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Handles only messages with credentials/1.0/onchain-offer type
|
|
190
|
+
* @beta
|
|
191
|
+
*/
|
|
192
|
+
async handleOnchainOffer(offer) {
|
|
193
|
+
const offerMessage = await FetchHandler.unpackMessage(this._packerMgr, offer, constants_2.PROTOCOL_MESSAGE_TYPE.CREDENTIAL_ONCHAIN_OFFER_MESSAGE_TYPE);
|
|
194
|
+
return this.handleOnchainOfferMessage(offerMessage);
|
|
195
|
+
}
|
|
160
196
|
async handleFetchRequest(msgRequest) {
|
|
161
197
|
if (!msgRequest.to) {
|
|
162
198
|
throw new Error("failed request. empty 'to' field");
|
|
@@ -194,8 +230,11 @@ class FetchHandler extends message_handler_1.AbstractMessageHandler {
|
|
|
194
230
|
/**
|
|
195
231
|
* @inheritdoc IFetchHandler#handleCredentialFetchRequest
|
|
196
232
|
*/
|
|
197
|
-
async handleCredentialFetchRequest(envelope) {
|
|
233
|
+
async handleCredentialFetchRequest(envelope, opts) {
|
|
198
234
|
const msgRequest = await FetchHandler.unpackMessage(this._packerMgr, envelope, constants_2.PROTOCOL_MESSAGE_TYPE.CREDENTIAL_FETCH_REQUEST_MESSAGE_TYPE);
|
|
235
|
+
if (!opts?.allowExpiredMessages) {
|
|
236
|
+
(0, common_1.verifyExpiresTime)(msgRequest);
|
|
237
|
+
}
|
|
199
238
|
const request = await this.handleFetchRequest(msgRequest);
|
|
200
239
|
return this._packerMgr.pack(constants_1.MediaType.PlainMessage, utils_1.byteEncoder.encode(JSON.stringify(request)), {});
|
|
201
240
|
}
|
|
@@ -212,8 +251,11 @@ class FetchHandler extends message_handler_1.AbstractMessageHandler {
|
|
|
212
251
|
/**
|
|
213
252
|
* @inheritdoc IFetchHandler#handleIssuanceResponseMessage
|
|
214
253
|
*/
|
|
215
|
-
async handleIssuanceResponseMessage(envelop) {
|
|
254
|
+
async handleIssuanceResponseMessage(envelop, opts) {
|
|
216
255
|
const issuanceMsg = await FetchHandler.unpackMessage(this._packerMgr, envelop, constants_2.PROTOCOL_MESSAGE_TYPE.CREDENTIAL_ISSUANCE_RESPONSE_MESSAGE_TYPE);
|
|
256
|
+
if (!opts?.allowExpiredMessages) {
|
|
257
|
+
(0, common_1.verifyExpiresTime)(issuanceMsg);
|
|
258
|
+
}
|
|
217
259
|
await this.handleIssuanceResponseMsg(issuanceMsg);
|
|
218
260
|
return Uint8Array.from([]);
|
|
219
261
|
}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.MessageHandler = exports.AbstractMessageHandler = void 0;
|
|
4
4
|
const constants_1 = require("../constants");
|
|
5
5
|
const js_jwz_1 = require("@iden3/js-jwz");
|
|
6
|
+
const common_1 = require("./common");
|
|
6
7
|
/**
|
|
7
8
|
* Base implementation of protocol message handler
|
|
8
9
|
*
|
|
@@ -17,6 +18,9 @@ class AbstractMessageHandler {
|
|
|
17
18
|
return messageHandler;
|
|
18
19
|
}
|
|
19
20
|
async handle(message, context) {
|
|
21
|
+
if (!context.allowExpiredMessages) {
|
|
22
|
+
(0, common_1.verifyExpiresTime)(message);
|
|
23
|
+
}
|
|
20
24
|
if (this.nextMessageHandler)
|
|
21
25
|
return this.nextMessageHandler.handle(message, context);
|
|
22
26
|
return Promise.reject('Message handler not provided or message not supported');
|