@0xpolygonid/js-sdk 1.25.1 → 1.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/esm/index.js +239 -47
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/umd/index.js +241 -46
- package/dist/browser/umd/index.js.map +1 -1
- package/dist/node/cjs/iden3comm/constants.js +6 -1
- package/dist/node/cjs/iden3comm/handlers/auth.js +16 -24
- package/dist/node/cjs/iden3comm/handlers/discovery-protocol.js +198 -0
- package/dist/node/cjs/iden3comm/handlers/index.js +1 -0
- package/dist/node/cjs/iden3comm/packageManager.js +12 -0
- package/dist/node/cjs/iden3comm/packers/jws.js +8 -7
- package/dist/node/cjs/iden3comm/packers/plain.js +8 -2
- package/dist/node/cjs/iden3comm/packers/zkp.js +10 -12
- package/dist/node/cjs/iden3comm/types/index.js +1 -0
- package/dist/node/cjs/iden3comm/types/protocol/discovery-protocol.js +16 -0
- package/dist/node/esm/iden3comm/constants.js +6 -1
- package/dist/node/esm/iden3comm/handlers/auth.js +17 -25
- package/dist/node/esm/iden3comm/handlers/discovery-protocol.js +169 -0
- package/dist/node/esm/iden3comm/handlers/index.js +1 -0
- package/dist/node/esm/iden3comm/packageManager.js +12 -0
- package/dist/node/esm/iden3comm/packers/jws.js +9 -8
- package/dist/node/esm/iden3comm/packers/plain.js +9 -3
- package/dist/node/esm/iden3comm/packers/zkp.js +11 -13
- package/dist/node/esm/iden3comm/types/index.js +1 -0
- package/dist/node/esm/iden3comm/types/protocol/discovery-protocol.js +13 -0
- package/dist/types/iden3comm/constants.d.ts +2 -0
- package/dist/types/iden3comm/handlers/credential-proposal.d.ts +1 -5
- package/dist/types/iden3comm/handlers/discovery-protocol.d.ts +100 -0
- package/dist/types/iden3comm/handlers/index.d.ts +1 -0
- package/dist/types/iden3comm/packageManager.d.ts +2 -0
- package/dist/types/iden3comm/packers/jws.d.ts +2 -1
- package/dist/types/iden3comm/packers/plain.d.ts +1 -0
- package/dist/types/iden3comm/packers/zkp.d.ts +3 -2
- package/dist/types/iden3comm/types/index.d.ts +1 -0
- package/dist/types/iden3comm/types/packageManager.d.ts +6 -0
- package/dist/types/iden3comm/types/protocol/contract-request.d.ts +1 -1
- package/dist/types/iden3comm/types/protocol/discovery-protocol.d.ts +41 -0
- package/package.json +1 -1
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { MediaType, PROTOCOL_MESSAGE_TYPE } from '../constants';
|
|
2
|
+
import * as uuid from 'uuid';
|
|
3
|
+
import { DiscoverFeatureQueryType, DiscoveryProtocolFeatureType } from '../types/protocol/discovery-protocol';
|
|
4
|
+
import { AbstractMessageHandler } from './message-handler';
|
|
5
|
+
import { getUnixTimestamp } from '@iden3/js-iden3-core';
|
|
6
|
+
import { verifyExpiresTime } from './common';
|
|
7
|
+
/**
|
|
8
|
+
* @beta
|
|
9
|
+
* createDiscoveryFeatureQueryMessage is a function to create didcomm protocol discovery-feature query message
|
|
10
|
+
* @param opts - discovery-feature query options
|
|
11
|
+
* @returns `DiscoverFeatureQueriesMessage`
|
|
12
|
+
*/
|
|
13
|
+
export function createDiscoveryFeatureQueryMessage(queries, opts) {
|
|
14
|
+
const uuidv4 = uuid.v4();
|
|
15
|
+
return {
|
|
16
|
+
id: uuidv4,
|
|
17
|
+
thid: uuidv4,
|
|
18
|
+
typ: MediaType.PlainMessage,
|
|
19
|
+
type: PROTOCOL_MESSAGE_TYPE.DISCOVERY_PROTOCOL_QUERIES_MESSAGE_TYPE,
|
|
20
|
+
body: {
|
|
21
|
+
queries
|
|
22
|
+
},
|
|
23
|
+
from: opts?.from,
|
|
24
|
+
to: opts?.to,
|
|
25
|
+
created_time: getUnixTimestamp(new Date()),
|
|
26
|
+
expires_time: opts?.expires_time
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @beta
|
|
31
|
+
* createDiscoveryFeatureDiscloseMessage is a function to create didcomm protocol discovery-feature disclose message
|
|
32
|
+
* @param {DiscoverFeatureDisclosure[]} disclosures - array of disclosures
|
|
33
|
+
* @param opts - basic message options
|
|
34
|
+
* @returns `DiscoverFeatureQueriesMessage`
|
|
35
|
+
*/
|
|
36
|
+
export function createDiscoveryFeatureDiscloseMessage(disclosures, opts) {
|
|
37
|
+
const uuidv4 = uuid.v4();
|
|
38
|
+
return {
|
|
39
|
+
id: uuidv4,
|
|
40
|
+
typ: MediaType.PlainMessage,
|
|
41
|
+
thid: uuidv4,
|
|
42
|
+
type: PROTOCOL_MESSAGE_TYPE.DISCOVERY_PROTOCOL_DISCLOSE_MESSAGE_TYPE,
|
|
43
|
+
body: {
|
|
44
|
+
disclosures
|
|
45
|
+
},
|
|
46
|
+
from: opts?.from,
|
|
47
|
+
to: opts?.to,
|
|
48
|
+
created_time: getUnixTimestamp(new Date()),
|
|
49
|
+
expires_time: opts?.expires_time
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
*
|
|
54
|
+
* Handler for discovery protocol
|
|
55
|
+
*
|
|
56
|
+
* @public
|
|
57
|
+
* @beta
|
|
58
|
+
* @class DiscoveryProtocolHandler
|
|
59
|
+
* @implements implements DiscoveryProtocolHandler interface
|
|
60
|
+
*/
|
|
61
|
+
export class DiscoveryProtocolHandler extends AbstractMessageHandler {
|
|
62
|
+
/**
|
|
63
|
+
* Creates an instance of DiscoveryProtocolHandler.
|
|
64
|
+
* @param {DiscoveryProtocolOptions} _options - discovery protocol options
|
|
65
|
+
*/
|
|
66
|
+
constructor(_options) {
|
|
67
|
+
super();
|
|
68
|
+
this._options = _options;
|
|
69
|
+
const headers = [
|
|
70
|
+
'id',
|
|
71
|
+
'typ',
|
|
72
|
+
'type',
|
|
73
|
+
'thid',
|
|
74
|
+
'body',
|
|
75
|
+
'from',
|
|
76
|
+
'to',
|
|
77
|
+
'created_time',
|
|
78
|
+
'expires_time'
|
|
79
|
+
];
|
|
80
|
+
if (!_options.headers) {
|
|
81
|
+
_options.headers = headers;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* @inheritdoc IProtocolMessageHandler#handle
|
|
86
|
+
*/
|
|
87
|
+
async handle(message, context) {
|
|
88
|
+
switch (message.type) {
|
|
89
|
+
case PROTOCOL_MESSAGE_TYPE.DISCOVERY_PROTOCOL_QUERIES_MESSAGE_TYPE:
|
|
90
|
+
return await this.handleDiscoveryQuery(message, context);
|
|
91
|
+
default:
|
|
92
|
+
return super.handle(message, context);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* @inheritdoc IDiscoveryProtocolHandler#handleDiscoveryQuery
|
|
97
|
+
*/
|
|
98
|
+
async handleDiscoveryQuery(message, opts) {
|
|
99
|
+
if (!opts?.allowExpiredMessages) {
|
|
100
|
+
verifyExpiresTime(message);
|
|
101
|
+
}
|
|
102
|
+
const disclosures = [];
|
|
103
|
+
for (const query of message.body.queries) {
|
|
104
|
+
disclosures.push(...this.handleQuery(query));
|
|
105
|
+
}
|
|
106
|
+
return Promise.resolve(createDiscoveryFeatureDiscloseMessage(disclosures, {
|
|
107
|
+
to: message.from,
|
|
108
|
+
from: message.to,
|
|
109
|
+
expires_time: opts?.disclosureExpiresDate
|
|
110
|
+
? getUnixTimestamp(opts.disclosureExpiresDate)
|
|
111
|
+
: undefined
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
handleQuery(query) {
|
|
115
|
+
let result = [];
|
|
116
|
+
switch (query[DiscoverFeatureQueryType.FeatureType]) {
|
|
117
|
+
case DiscoveryProtocolFeatureType.Accept:
|
|
118
|
+
result = this.handleAcceptQuery();
|
|
119
|
+
break;
|
|
120
|
+
case DiscoveryProtocolFeatureType.Protocol:
|
|
121
|
+
result = this.handleProtocolQuery();
|
|
122
|
+
break;
|
|
123
|
+
case DiscoveryProtocolFeatureType.GoalCode:
|
|
124
|
+
result = this.handleGoalCodeQuery();
|
|
125
|
+
break;
|
|
126
|
+
case DiscoveryProtocolFeatureType.Header:
|
|
127
|
+
result = this.handleHeaderQuery();
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
return this.handleMatch(result, query.match);
|
|
131
|
+
}
|
|
132
|
+
handleAcceptQuery() {
|
|
133
|
+
const acceptProfiles = this._options.packageManager.getSupportedProfiles();
|
|
134
|
+
return acceptProfiles.map((profile) => ({
|
|
135
|
+
[DiscoverFeatureQueryType.FeatureType]: DiscoveryProtocolFeatureType.Accept,
|
|
136
|
+
id: profile
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
handleProtocolQuery() {
|
|
140
|
+
return (this._options.protocols?.map((protocol) => ({
|
|
141
|
+
[DiscoverFeatureQueryType.FeatureType]: DiscoveryProtocolFeatureType.Protocol,
|
|
142
|
+
id: protocol
|
|
143
|
+
})) ?? []);
|
|
144
|
+
}
|
|
145
|
+
handleGoalCodeQuery() {
|
|
146
|
+
return (this._options.goalCodes?.map((goalCode) => ({
|
|
147
|
+
[DiscoverFeatureQueryType.FeatureType]: DiscoveryProtocolFeatureType.GoalCode,
|
|
148
|
+
id: goalCode
|
|
149
|
+
})) ?? []);
|
|
150
|
+
}
|
|
151
|
+
handleHeaderQuery() {
|
|
152
|
+
return (this._options.headers?.map((header) => ({
|
|
153
|
+
[DiscoverFeatureQueryType.FeatureType]: DiscoveryProtocolFeatureType.Header,
|
|
154
|
+
id: header
|
|
155
|
+
})) ?? []);
|
|
156
|
+
}
|
|
157
|
+
handleMatch(disclosures, match) {
|
|
158
|
+
if (!match || match === '*') {
|
|
159
|
+
return disclosures;
|
|
160
|
+
}
|
|
161
|
+
const regExp = this.wildcardToRegExp(match);
|
|
162
|
+
return disclosures.filter((disclosure) => regExp.test(disclosure.id));
|
|
163
|
+
}
|
|
164
|
+
wildcardToRegExp(match) {
|
|
165
|
+
// Escape special regex characters, then replace `*` with `.*`
|
|
166
|
+
const regexPattern = match.replace(/[.+^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*');
|
|
167
|
+
return new RegExp(`^${regexPattern}$`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -15,6 +15,18 @@ export class PackageManager {
|
|
|
15
15
|
constructor() {
|
|
16
16
|
this.packers = new Map();
|
|
17
17
|
}
|
|
18
|
+
/** {@inheritDoc IPackageManager.getSupportedProfiles} */
|
|
19
|
+
getSupportedProfiles() {
|
|
20
|
+
const acceptProfiles = [];
|
|
21
|
+
const mediaTypes = this.getSupportedMediaTypes();
|
|
22
|
+
for (const mediaType of mediaTypes) {
|
|
23
|
+
const p = this.packers.get(mediaType);
|
|
24
|
+
if (p) {
|
|
25
|
+
acceptProfiles.push(...p.getSupportedProfiles());
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return [...new Set(acceptProfiles)];
|
|
29
|
+
}
|
|
18
30
|
/** {@inheritDoc IPackageManager.isProfileSupported} */
|
|
19
31
|
isProfileSupported(mediaType, profile) {
|
|
20
32
|
const p = this.packers.get(mediaType);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AcceptJwsAlgorithms, MediaType, SUPPORTED_PUBLIC_KEY_TYPES } from '../constants';
|
|
1
|
+
import { AcceptJwsAlgorithms, MediaType, ProtocolVersion, SUPPORTED_PUBLIC_KEY_TYPES } from '../constants';
|
|
2
2
|
import { extractPublicKeyBytes, resolveVerificationMethods } from '../utils/did';
|
|
3
3
|
import { keyPath } from '../../kms/';
|
|
4
4
|
import { verifyJWS } from 'did-jwt';
|
|
@@ -24,6 +24,8 @@ export class JWSPacker {
|
|
|
24
24
|
constructor(_kms, _documentResolver) {
|
|
25
25
|
this._kms = _kms;
|
|
26
26
|
this._documentResolver = _documentResolver;
|
|
27
|
+
this.supportedAlgorithms = [AcceptJwsAlgorithms.ES256K, AcceptJwsAlgorithms.ES256KR];
|
|
28
|
+
this.supportedProtocolVersions = [ProtocolVersion.V1];
|
|
27
29
|
}
|
|
28
30
|
/**
|
|
29
31
|
* Packs the given payload and returns a promise that resolves to the packed data.
|
|
@@ -86,24 +88,23 @@ export class JWSPacker {
|
|
|
86
88
|
}
|
|
87
89
|
/** {@inheritDoc IPacker.getSupportedProfiles} */
|
|
88
90
|
getSupportedProfiles() {
|
|
89
|
-
return
|
|
91
|
+
return this.supportedProtocolVersions.map((v) => `${v};env=${this.mediaType()};alg=${this.supportedAlgorithms.join(',')}`);
|
|
90
92
|
}
|
|
91
93
|
/** {@inheritDoc IPacker.isProfileSupported} */
|
|
92
94
|
isProfileSupported(profile) {
|
|
93
|
-
const { env, circuits, alg } = parseAcceptProfile(profile);
|
|
95
|
+
const { protocolVersion, env, circuits, alg } = parseAcceptProfile(profile);
|
|
96
|
+
if (!this.supportedProtocolVersions.includes(protocolVersion)) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
94
99
|
if (env !== this.mediaType()) {
|
|
95
100
|
return false;
|
|
96
101
|
}
|
|
97
102
|
if (circuits) {
|
|
98
103
|
throw new Error(`Circuits are not supported for ${env} media type`);
|
|
99
104
|
}
|
|
100
|
-
const
|
|
101
|
-
const algSupported = !alg?.length || alg.some((a) => supportedAlgArr.includes(a));
|
|
105
|
+
const algSupported = !alg?.length || alg.some((a) => this.supportedAlgorithms.includes(a));
|
|
102
106
|
return algSupported;
|
|
103
107
|
}
|
|
104
|
-
getSupportedAlgorithms() {
|
|
105
|
-
return [AcceptJwsAlgorithms.ES256K, AcceptJwsAlgorithms.ES256KR];
|
|
106
|
-
}
|
|
107
108
|
async resolveDidDoc(from) {
|
|
108
109
|
let didDocument;
|
|
109
110
|
try {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MediaType } from '../constants';
|
|
1
|
+
import { MediaType, ProtocolVersion } from '../constants';
|
|
2
2
|
import { byteDecoder, byteEncoder } from '../../utils';
|
|
3
3
|
import { parseAcceptProfile } from '../utils';
|
|
4
4
|
/**
|
|
@@ -9,6 +9,9 @@ import { parseAcceptProfile } from '../utils';
|
|
|
9
9
|
* @implements implements IPacker interface
|
|
10
10
|
*/
|
|
11
11
|
export class PlainPacker {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.supportedProtocolVersions = [ProtocolVersion.V1];
|
|
14
|
+
}
|
|
12
15
|
/**
|
|
13
16
|
* Packs a basic message using the specified parameters.
|
|
14
17
|
*
|
|
@@ -52,11 +55,14 @@ export class PlainPacker {
|
|
|
52
55
|
}
|
|
53
56
|
/** {@inheritDoc IPacker.getSupportedProfiles} */
|
|
54
57
|
getSupportedProfiles() {
|
|
55
|
-
return
|
|
58
|
+
return this.supportedProtocolVersions.map((v) => `${v};env=${this.mediaType()}`);
|
|
56
59
|
}
|
|
57
60
|
/** {@inheritDoc IPacker.isProfileSupported} */
|
|
58
61
|
isProfileSupported(profile) {
|
|
59
|
-
const { env, circuits, alg } = parseAcceptProfile(profile);
|
|
62
|
+
const { protocolVersion, env, circuits, alg } = parseAcceptProfile(profile);
|
|
63
|
+
if (!this.supportedProtocolVersions.includes(protocolVersion)) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
60
66
|
if (env !== this.mediaType()) {
|
|
61
67
|
return false;
|
|
62
68
|
}
|
|
@@ -3,7 +3,7 @@ import { AuthV2PubSignals, CircuitId } from '../../circuits/index';
|
|
|
3
3
|
import { BytesHelper, DID } from '@iden3/js-iden3-core';
|
|
4
4
|
import { bytesToProtocolMessage } from '../utils/envelope';
|
|
5
5
|
import { ErrNoProvingMethodAlg, ErrPackedWithUnsupportedCircuit, ErrProofIsInvalid, ErrSenderNotUsedTokenCreation, ErrStateVerificationFailed, ErrUnknownCircuitID } from '../errors';
|
|
6
|
-
import { AcceptAuthCircuits, AcceptJwzAlgorithms, MediaType } from '../constants';
|
|
6
|
+
import { AcceptAuthCircuits, AcceptJwzAlgorithms, MediaType, ProtocolVersion } from '../constants';
|
|
7
7
|
import { byteDecoder, byteEncoder } from '../../utils';
|
|
8
8
|
import { DEFAULT_AUTH_VERIFY_DELAY } from '../constants';
|
|
9
9
|
import { parseAcceptProfile } from '../utils';
|
|
@@ -78,6 +78,9 @@ export class ZKPPacker {
|
|
|
78
78
|
this.provingParamsMap = provingParamsMap;
|
|
79
79
|
this.verificationParamsMap = verificationParamsMap;
|
|
80
80
|
this._opts = _opts;
|
|
81
|
+
this.supportedProtocolVersions = [ProtocolVersion.V1];
|
|
82
|
+
this.supportedAlgorithms = [AcceptJwzAlgorithms.Groth16];
|
|
83
|
+
this.supportedCircuitIds = [AcceptAuthCircuits.AuthV2];
|
|
81
84
|
}
|
|
82
85
|
/**
|
|
83
86
|
* Packs a basic message using the specified parameters.
|
|
@@ -139,28 +142,23 @@ export class ZKPPacker {
|
|
|
139
142
|
}
|
|
140
143
|
/** {@inheritDoc IPacker.getSupportedProfiles} */
|
|
141
144
|
getSupportedProfiles() {
|
|
142
|
-
return
|
|
143
|
-
`env=${this.mediaType()}&alg=${this.getSupportedAlgorithms().join(',')}&circuitIds=${this.getSupportedCircuitIds().join(',')}`
|
|
144
|
-
];
|
|
145
|
+
return this.supportedProtocolVersions.map((v) => `${v};env=${this.mediaType()};alg=${this.supportedAlgorithms.join(',')};circuitIds=${this.supportedCircuitIds.join(',')}`);
|
|
145
146
|
}
|
|
146
147
|
/** {@inheritDoc IPacker.isProfileSupported} */
|
|
147
148
|
isProfileSupported(profile) {
|
|
148
|
-
const { env, circuits, alg } = parseAcceptProfile(profile);
|
|
149
|
+
const { protocolVersion, env, circuits, alg } = parseAcceptProfile(profile);
|
|
150
|
+
if (!this.supportedProtocolVersions.includes(protocolVersion)) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
149
153
|
if (env !== this.mediaType()) {
|
|
150
154
|
return false;
|
|
151
155
|
}
|
|
152
|
-
const supportedCircuitIds = this.
|
|
156
|
+
const supportedCircuitIds = this.supportedCircuitIds;
|
|
153
157
|
const circuitIdSupported = !circuits?.length || circuits.some((c) => supportedCircuitIds.includes(c));
|
|
154
|
-
const supportedAlgArr = this.
|
|
158
|
+
const supportedAlgArr = this.supportedAlgorithms;
|
|
155
159
|
const algSupported = !alg?.length || alg.some((a) => supportedAlgArr.includes(a));
|
|
156
160
|
return algSupported && circuitIdSupported;
|
|
157
161
|
}
|
|
158
|
-
getSupportedAlgorithms() {
|
|
159
|
-
return [AcceptJwzAlgorithms.Groth16];
|
|
160
|
-
}
|
|
161
|
-
getSupportedCircuitIds() {
|
|
162
|
-
return [AcceptAuthCircuits.AuthV2];
|
|
163
|
-
}
|
|
164
162
|
}
|
|
165
163
|
const verifySender = async (token, msg) => {
|
|
166
164
|
switch (token.circuitId) {
|
|
@@ -7,6 +7,7 @@ export * from './protocol/contract-request';
|
|
|
7
7
|
export * from './protocol/proposal-request';
|
|
8
8
|
export * from './protocol/payment';
|
|
9
9
|
export * from './protocol/accept-profile';
|
|
10
|
+
export * from './protocol/discovery-protocol';
|
|
10
11
|
export * from './packer';
|
|
11
12
|
export * from './models';
|
|
12
13
|
export * from './packageManager';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** @beta DiscoverFeatureQueryType is enum for query type fields */
|
|
2
|
+
export var DiscoverFeatureQueryType;
|
|
3
|
+
(function (DiscoverFeatureQueryType) {
|
|
4
|
+
DiscoverFeatureQueryType["FeatureType"] = "feature-type";
|
|
5
|
+
})(DiscoverFeatureQueryType || (DiscoverFeatureQueryType = {}));
|
|
6
|
+
/** @beta DiscoveryProtocolFeatureType is enum for supported feature-types */
|
|
7
|
+
export var DiscoveryProtocolFeatureType;
|
|
8
|
+
(function (DiscoveryProtocolFeatureType) {
|
|
9
|
+
DiscoveryProtocolFeatureType["Accept"] = "accept";
|
|
10
|
+
DiscoveryProtocolFeatureType["Protocol"] = "protocol";
|
|
11
|
+
DiscoveryProtocolFeatureType["GoalCode"] = "goal-code";
|
|
12
|
+
DiscoveryProtocolFeatureType["Header"] = "header";
|
|
13
|
+
})(DiscoveryProtocolFeatureType || (DiscoveryProtocolFeatureType = {}));
|
|
@@ -23,6 +23,8 @@ export declare const PROTOCOL_MESSAGE_TYPE: Readonly<{
|
|
|
23
23
|
PROPOSAL_MESSAGE_TYPE: "https://iden3-communication.io/credentials/0.1/proposal";
|
|
24
24
|
PAYMENT_REQUEST_MESSAGE_TYPE: "https://iden3-communication.io/credentials/0.1/payment-request";
|
|
25
25
|
PAYMENT_MESSAGE_TYPE: "https://iden3-communication.io/credentials/0.1/payment";
|
|
26
|
+
DISCOVERY_PROTOCOL_QUERIES_MESSAGE_TYPE: "https://didcomm.org/discover-features/2.0/queries";
|
|
27
|
+
DISCOVERY_PROTOCOL_DISCLOSE_MESSAGE_TYPE: "https://didcomm.org/discover-features/2.0/disclose";
|
|
26
28
|
}>;
|
|
27
29
|
/**
|
|
28
30
|
* Media types for iden3 comm communication protocol
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BasicMessage, DIDDocument, IPackageManager,
|
|
1
|
+
import { BasicMessage, DIDDocument, IPackageManager, PackerParams } from '../types';
|
|
2
2
|
import { DID } from '@iden3/js-iden3-core';
|
|
3
3
|
import { Proposal, ProposalRequestCredential, ProposalRequestMessage, ProposalMessage } from '../types/protocol/proposal-request';
|
|
4
4
|
import { IIdentityWallet } from '../../identity';
|
|
@@ -6,10 +6,6 @@ import { AbstractMessageHandler, BasicHandlerOptions, IProtocolMessageHandler }
|
|
|
6
6
|
/** @beta ProposalRequestCreationOptions represents proposal-request creation options */
|
|
7
7
|
export type ProposalRequestCreationOptions = {
|
|
8
8
|
credentials: ProposalRequestCredential[];
|
|
9
|
-
metadata?: {
|
|
10
|
-
type: string;
|
|
11
|
-
data?: JsonDocumentObject;
|
|
12
|
-
};
|
|
13
9
|
did_doc?: DIDDocument;
|
|
14
10
|
expires_time?: Date;
|
|
15
11
|
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { BasicMessage, IPackageManager, ProtocolMessage } from '../types';
|
|
2
|
+
import { DiscoverFeatureDiscloseMessage, DiscoverFeatureDisclosure, DiscoverFeatureQueriesMessage, DiscoverFeatureQuery } from '../types/protocol/discovery-protocol';
|
|
3
|
+
import { AbstractMessageHandler, BasicHandlerOptions, IProtocolMessageHandler } from './message-handler';
|
|
4
|
+
/**
|
|
5
|
+
* @beta
|
|
6
|
+
* DiscoveryProtocolOptions contains options for DiscoveryProtocolHandler
|
|
7
|
+
* @public
|
|
8
|
+
* @interface DiscoveryProtocolOptions
|
|
9
|
+
*/
|
|
10
|
+
export interface DiscoveryProtocolOptions {
|
|
11
|
+
packageManager: IPackageManager;
|
|
12
|
+
protocols?: Array<ProtocolMessage>;
|
|
13
|
+
goalCodes?: Array<string>;
|
|
14
|
+
headers?: Array<string>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* Options to pass to discovery-protocol handler
|
|
19
|
+
*
|
|
20
|
+
* @beta
|
|
21
|
+
* @public
|
|
22
|
+
* @type DiscoveryProtocolHandlerOptions
|
|
23
|
+
*/
|
|
24
|
+
export type DiscoveryProtocolHandlerOptions = BasicHandlerOptions & {
|
|
25
|
+
disclosureExpiresDate?: Date;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* @beta
|
|
29
|
+
* createDiscoveryFeatureQueryMessage is a function to create didcomm protocol discovery-feature query message
|
|
30
|
+
* @param opts - discovery-feature query options
|
|
31
|
+
* @returns `DiscoverFeatureQueriesMessage`
|
|
32
|
+
*/
|
|
33
|
+
export declare function createDiscoveryFeatureQueryMessage(queries: DiscoverFeatureQuery[], opts?: {
|
|
34
|
+
from?: string;
|
|
35
|
+
to?: string;
|
|
36
|
+
expires_time?: number;
|
|
37
|
+
}): DiscoverFeatureQueriesMessage;
|
|
38
|
+
/**
|
|
39
|
+
* @beta
|
|
40
|
+
* createDiscoveryFeatureDiscloseMessage is a function to create didcomm protocol discovery-feature disclose message
|
|
41
|
+
* @param {DiscoverFeatureDisclosure[]} disclosures - array of disclosures
|
|
42
|
+
* @param opts - basic message options
|
|
43
|
+
* @returns `DiscoverFeatureQueriesMessage`
|
|
44
|
+
*/
|
|
45
|
+
export declare function createDiscoveryFeatureDiscloseMessage(disclosures: DiscoverFeatureDisclosure[], opts?: {
|
|
46
|
+
from?: string;
|
|
47
|
+
to?: string;
|
|
48
|
+
expires_time?: number;
|
|
49
|
+
}): DiscoverFeatureDiscloseMessage;
|
|
50
|
+
/**
|
|
51
|
+
* Interface to work with discovery protocol handler
|
|
52
|
+
*
|
|
53
|
+
* @beta
|
|
54
|
+
* @public
|
|
55
|
+
* @interface IDiscoveryProtocolHandler
|
|
56
|
+
*/
|
|
57
|
+
export interface IDiscoveryProtocolHandler {
|
|
58
|
+
/**
|
|
59
|
+
* handle discovery query message
|
|
60
|
+
*
|
|
61
|
+
* @param {DiscoverFeatureQueriesMessage} message - discover feature queries message
|
|
62
|
+
* @param {{ expires_time?: number}} opts - discover feature handle options
|
|
63
|
+
* @returns {Promise<DiscoverFeatureDiscloseMessage>} - discover feature disclose message
|
|
64
|
+
*/
|
|
65
|
+
handleDiscoveryQuery(message: DiscoverFeatureQueriesMessage, opts?: DiscoveryProtocolHandlerOptions): Promise<DiscoverFeatureDiscloseMessage>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
*
|
|
69
|
+
* Handler for discovery protocol
|
|
70
|
+
*
|
|
71
|
+
* @public
|
|
72
|
+
* @beta
|
|
73
|
+
* @class DiscoveryProtocolHandler
|
|
74
|
+
* @implements implements DiscoveryProtocolHandler interface
|
|
75
|
+
*/
|
|
76
|
+
export declare class DiscoveryProtocolHandler extends AbstractMessageHandler implements IDiscoveryProtocolHandler, IProtocolMessageHandler {
|
|
77
|
+
private readonly _options;
|
|
78
|
+
/**
|
|
79
|
+
* Creates an instance of DiscoveryProtocolHandler.
|
|
80
|
+
* @param {DiscoveryProtocolOptions} _options - discovery protocol options
|
|
81
|
+
*/
|
|
82
|
+
constructor(_options: DiscoveryProtocolOptions);
|
|
83
|
+
/**
|
|
84
|
+
* @inheritdoc IProtocolMessageHandler#handle
|
|
85
|
+
*/
|
|
86
|
+
handle(message: BasicMessage, context: {
|
|
87
|
+
[key: string]: unknown;
|
|
88
|
+
}): Promise<BasicMessage | null>;
|
|
89
|
+
/**
|
|
90
|
+
* @inheritdoc IDiscoveryProtocolHandler#handleDiscoveryQuery
|
|
91
|
+
*/
|
|
92
|
+
handleDiscoveryQuery(message: DiscoverFeatureQueriesMessage, opts?: DiscoveryProtocolHandlerOptions): Promise<DiscoverFeatureDiscloseMessage>;
|
|
93
|
+
private handleQuery;
|
|
94
|
+
private handleAcceptQuery;
|
|
95
|
+
private handleProtocolQuery;
|
|
96
|
+
private handleGoalCodeQuery;
|
|
97
|
+
private handleHeaderQuery;
|
|
98
|
+
private handleMatch;
|
|
99
|
+
private wildcardToRegExp;
|
|
100
|
+
}
|
|
@@ -13,6 +13,8 @@ export declare class PackageManager implements IPackageManager {
|
|
|
13
13
|
* Creates an instance of PackageManager.
|
|
14
14
|
*/
|
|
15
15
|
constructor();
|
|
16
|
+
/** {@inheritDoc IPackageManager.getSupportedProfiles} */
|
|
17
|
+
getSupportedProfiles(): string[];
|
|
16
18
|
/** {@inheritDoc IPackageManager.isProfileSupported} */
|
|
17
19
|
isProfileSupported(mediaType: MediaType, profile: string): boolean;
|
|
18
20
|
/** {@inheritDoc IPackageManager.getSupportedMediaTypes} */
|
|
@@ -12,6 +12,8 @@ import { Resolvable } from 'did-resolver';
|
|
|
12
12
|
export declare class JWSPacker implements IPacker {
|
|
13
13
|
private readonly _kms;
|
|
14
14
|
private readonly _documentResolver;
|
|
15
|
+
private readonly supportedAlgorithms;
|
|
16
|
+
private readonly supportedProtocolVersions;
|
|
15
17
|
/**
|
|
16
18
|
* Creates an instance of JWSPacker.
|
|
17
19
|
*
|
|
@@ -48,7 +50,6 @@ export declare class JWSPacker implements IPacker {
|
|
|
48
50
|
getSupportedProfiles(): string[];
|
|
49
51
|
/** {@inheritDoc IPacker.isProfileSupported} */
|
|
50
52
|
isProfileSupported(profile: string): boolean;
|
|
51
|
-
private getSupportedAlgorithms;
|
|
52
53
|
private resolveDidDoc;
|
|
53
54
|
private packInternal;
|
|
54
55
|
}
|
|
@@ -8,6 +8,7 @@ import { MediaType } from '../constants';
|
|
|
8
8
|
* @implements implements IPacker interface
|
|
9
9
|
*/
|
|
10
10
|
export declare class PlainPacker implements IPacker {
|
|
11
|
+
private readonly supportedProtocolVersions;
|
|
11
12
|
/**
|
|
12
13
|
* Packs a basic message using the specified parameters.
|
|
13
14
|
*
|
|
@@ -58,6 +58,9 @@ export declare class ZKPPacker implements IPacker {
|
|
|
58
58
|
readonly provingParamsMap: Map<string, ProvingParams>;
|
|
59
59
|
readonly verificationParamsMap: Map<string, VerificationParams>;
|
|
60
60
|
private readonly _opts;
|
|
61
|
+
private readonly supportedProtocolVersions;
|
|
62
|
+
private readonly supportedAlgorithms;
|
|
63
|
+
private readonly supportedCircuitIds;
|
|
61
64
|
/**
|
|
62
65
|
* Creates an instance of ZKPPacker.
|
|
63
66
|
* @param {Map<string, ProvingParams>} provingParamsMap - string is derived by JSON.parse(ProvingMethodAlg)
|
|
@@ -91,6 +94,4 @@ export declare class ZKPPacker implements IPacker {
|
|
|
91
94
|
getSupportedProfiles(): string[];
|
|
92
95
|
/** {@inheritDoc IPacker.isProfileSupported} */
|
|
93
96
|
isProfileSupported(profile: string): boolean;
|
|
94
|
-
private getSupportedAlgorithms;
|
|
95
|
-
private getSupportedCircuitIds;
|
|
96
97
|
}
|
|
@@ -7,6 +7,7 @@ export * from './protocol/contract-request';
|
|
|
7
7
|
export * from './protocol/proposal-request';
|
|
8
8
|
export * from './protocol/payment';
|
|
9
9
|
export * from './protocol/accept-profile';
|
|
10
|
+
export * from './protocol/discovery-protocol';
|
|
10
11
|
export * from './packer';
|
|
11
12
|
export * from './models';
|
|
12
13
|
export * from './packageManager';
|
|
@@ -70,6 +70,12 @@ export interface IPackageManager {
|
|
|
70
70
|
* @returns MediaType[]
|
|
71
71
|
*/
|
|
72
72
|
getSupportedMediaTypes(): MediaType[];
|
|
73
|
+
/**
|
|
74
|
+
* gets supported accept profiles by packer manager
|
|
75
|
+
*
|
|
76
|
+
* @returns string[]
|
|
77
|
+
*/
|
|
78
|
+
getSupportedProfiles(): string[];
|
|
73
79
|
/**
|
|
74
80
|
* returns true if media type and algorithms supported by packer manager
|
|
75
81
|
*
|
|
@@ -26,7 +26,7 @@ export type ContractInvokeResponseBody = {
|
|
|
26
26
|
};
|
|
27
27
|
/** OnChainZeroKnowledgeProofResponse represents structure of onchain zero knowledge proof response */
|
|
28
28
|
export type OnChainZeroKnowledgeProofResponse = ZeroKnowledgeProofResponse & {
|
|
29
|
-
txHash
|
|
29
|
+
txHash?: string;
|
|
30
30
|
};
|
|
31
31
|
/** ContractInvokeTransactionData represents structure of contract invoke transaction data object */
|
|
32
32
|
export type ContractInvokeTransactionData = {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { PROTOCOL_MESSAGE_TYPE } from '../../constants';
|
|
2
|
+
import { BasicMessage } from '../packer';
|
|
3
|
+
/** @beta DiscoverFeatureQueryType is enum for query type fields */
|
|
4
|
+
export declare enum DiscoverFeatureQueryType {
|
|
5
|
+
FeatureType = "feature-type"
|
|
6
|
+
}
|
|
7
|
+
/** @beta DiscoveryProtocolFeatureType is enum for supported feature-types */
|
|
8
|
+
export declare enum DiscoveryProtocolFeatureType {
|
|
9
|
+
Accept = "accept",
|
|
10
|
+
Protocol = "protocol",
|
|
11
|
+
GoalCode = "goal-code",
|
|
12
|
+
Header = "header"
|
|
13
|
+
}
|
|
14
|
+
/** @beta DiscoverFeatureQueriesMessage is struct the represents discover feature queries message */
|
|
15
|
+
export type DiscoverFeatureQueriesMessage = BasicMessage & {
|
|
16
|
+
body: DiscoverFeatureQueriesBody;
|
|
17
|
+
type: typeof PROTOCOL_MESSAGE_TYPE.DISCOVERY_PROTOCOL_QUERIES_MESSAGE_TYPE;
|
|
18
|
+
};
|
|
19
|
+
/** @beta DiscoverFeatureQueriesBody is struct the represents discover feature queries body */
|
|
20
|
+
export type DiscoverFeatureQueriesBody = {
|
|
21
|
+
queries: DiscoverFeatureQuery[];
|
|
22
|
+
};
|
|
23
|
+
/** @beta DiscoverFeatureQuery is struct the represents discover feature query */
|
|
24
|
+
export type DiscoverFeatureQuery = {
|
|
25
|
+
[DiscoverFeatureQueryType.FeatureType]: DiscoveryProtocolFeatureType;
|
|
26
|
+
match?: string;
|
|
27
|
+
};
|
|
28
|
+
/** @beta DiscoverFeatureDiscloseMessage is struct the represents discover feature disclose message */
|
|
29
|
+
export type DiscoverFeatureDiscloseMessage = BasicMessage & {
|
|
30
|
+
body: DiscoverFeatureDiscloseBody;
|
|
31
|
+
type: typeof PROTOCOL_MESSAGE_TYPE.DISCOVERY_PROTOCOL_DISCLOSE_MESSAGE_TYPE;
|
|
32
|
+
};
|
|
33
|
+
/** @beta DiscoverFeatureDiscloseBody is struct the represents discover feature disclose body */
|
|
34
|
+
export type DiscoverFeatureDiscloseBody = {
|
|
35
|
+
disclosures: DiscoverFeatureDisclosure[];
|
|
36
|
+
};
|
|
37
|
+
/** @beta DiscoverFeatureDisclosure is struct the represents discover feature disclosure */
|
|
38
|
+
export type DiscoverFeatureDisclosure = {
|
|
39
|
+
[DiscoverFeatureQueryType.FeatureType]: DiscoveryProtocolFeatureType;
|
|
40
|
+
id: string;
|
|
41
|
+
};
|