@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.
Files changed (37) hide show
  1. package/dist/browser/esm/index.js +239 -47
  2. package/dist/browser/esm/index.js.map +1 -1
  3. package/dist/browser/umd/index.js +241 -46
  4. package/dist/browser/umd/index.js.map +1 -1
  5. package/dist/node/cjs/iden3comm/constants.js +6 -1
  6. package/dist/node/cjs/iden3comm/handlers/auth.js +16 -24
  7. package/dist/node/cjs/iden3comm/handlers/discovery-protocol.js +198 -0
  8. package/dist/node/cjs/iden3comm/handlers/index.js +1 -0
  9. package/dist/node/cjs/iden3comm/packageManager.js +12 -0
  10. package/dist/node/cjs/iden3comm/packers/jws.js +8 -7
  11. package/dist/node/cjs/iden3comm/packers/plain.js +8 -2
  12. package/dist/node/cjs/iden3comm/packers/zkp.js +10 -12
  13. package/dist/node/cjs/iden3comm/types/index.js +1 -0
  14. package/dist/node/cjs/iden3comm/types/protocol/discovery-protocol.js +16 -0
  15. package/dist/node/esm/iden3comm/constants.js +6 -1
  16. package/dist/node/esm/iden3comm/handlers/auth.js +17 -25
  17. package/dist/node/esm/iden3comm/handlers/discovery-protocol.js +169 -0
  18. package/dist/node/esm/iden3comm/handlers/index.js +1 -0
  19. package/dist/node/esm/iden3comm/packageManager.js +12 -0
  20. package/dist/node/esm/iden3comm/packers/jws.js +9 -8
  21. package/dist/node/esm/iden3comm/packers/plain.js +9 -3
  22. package/dist/node/esm/iden3comm/packers/zkp.js +11 -13
  23. package/dist/node/esm/iden3comm/types/index.js +1 -0
  24. package/dist/node/esm/iden3comm/types/protocol/discovery-protocol.js +13 -0
  25. package/dist/types/iden3comm/constants.d.ts +2 -0
  26. package/dist/types/iden3comm/handlers/credential-proposal.d.ts +1 -5
  27. package/dist/types/iden3comm/handlers/discovery-protocol.d.ts +100 -0
  28. package/dist/types/iden3comm/handlers/index.d.ts +1 -0
  29. package/dist/types/iden3comm/packageManager.d.ts +2 -0
  30. package/dist/types/iden3comm/packers/jws.d.ts +2 -1
  31. package/dist/types/iden3comm/packers/plain.d.ts +1 -0
  32. package/dist/types/iden3comm/packers/zkp.d.ts +3 -2
  33. package/dist/types/iden3comm/types/index.d.ts +1 -0
  34. package/dist/types/iden3comm/types/packageManager.d.ts +6 -0
  35. package/dist/types/iden3comm/types/protocol/contract-request.d.ts +1 -1
  36. package/dist/types/iden3comm/types/protocol/discovery-protocol.d.ts +41 -0
  37. package/package.json +1 -1
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
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
+ const DIDCOMM_PROTOCOL = 'https://didcomm.org/';
5
6
  /**
6
7
  * Constants for Iden3 protocol
7
8
  */
@@ -45,7 +46,11 @@ exports.PROTOCOL_MESSAGE_TYPE = Object.freeze({
45
46
  // PaymentRequestMessageType is type for payment-request message
46
47
  PAYMENT_REQUEST_MESSAGE_TYPE: `${IDEN3_PROTOCOL}credentials/0.1/payment-request`,
47
48
  // PaymentMessageType is type for payment message
48
- PAYMENT_MESSAGE_TYPE: `${IDEN3_PROTOCOL}credentials/0.1/payment`
49
+ PAYMENT_MESSAGE_TYPE: `${IDEN3_PROTOCOL}credentials/0.1/payment`,
50
+ // DiscoveryProtocolQueriesMessageType is type for didcomm discovery protocol queries
51
+ DISCOVERY_PROTOCOL_QUERIES_MESSAGE_TYPE: `${DIDCOMM_PROTOCOL}discover-features/2.0/queries`,
52
+ // DiscoveryProtocolDiscloseMessageType is type for didcomm discovery protocol disclose
53
+ DISCOVERY_PROTOCOL_DISCLOSE_MESSAGE_TYPE: `${DIDCOMM_PROTOCOL}discover-features/2.0/disclose`
49
54
  });
50
55
  /**
51
56
  * Media types for iden3 comm communication protocol
@@ -287,32 +287,24 @@ class AuthHandler extends message_handler_1.AbstractMessageHandler {
287
287
  }
288
288
  getSupportedMediaTypeByProfile(ctx, responseType, profile) {
289
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;
290
+ if (!profile?.length) {
291
+ return ctx.mediaType || constants_1.MediaType.ZKPMessage;
292
+ }
293
+ const supportedMediaTypes = [];
294
+ for (const acceptProfile of profile) {
295
+ const { env } = (0, utils_2.parseAcceptProfile)(acceptProfile);
296
+ if (this._packerMgr.isProfileSupported(env, acceptProfile)) {
297
+ supportedMediaTypes.push(env);
312
298
  }
313
299
  }
314
- else {
315
- mediaType = ctx.mediaType || constants_1.MediaType.ZKPMessage;
300
+ if (!supportedMediaTypes.length) {
301
+ throw new Error('no packer with profile which meets `accept` header requirements');
302
+ }
303
+ mediaType = supportedMediaTypes.includes(constants_1.MediaType.ZKPMessage)
304
+ ? constants_1.MediaType.ZKPMessage
305
+ : supportedMediaTypes[0];
306
+ if (ctx.mediaType && supportedMediaTypes.includes(ctx.mediaType)) {
307
+ mediaType = ctx.mediaType;
316
308
  }
317
309
  return mediaType;
318
310
  }
@@ -0,0 +1,198 @@
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.DiscoveryProtocolHandler = exports.createDiscoveryFeatureDiscloseMessage = exports.createDiscoveryFeatureQueryMessage = void 0;
27
+ const constants_1 = require("../constants");
28
+ const uuid = __importStar(require("uuid"));
29
+ const discovery_protocol_1 = require("../types/protocol/discovery-protocol");
30
+ const message_handler_1 = require("./message-handler");
31
+ const js_iden3_core_1 = require("@iden3/js-iden3-core");
32
+ const common_1 = require("./common");
33
+ /**
34
+ * @beta
35
+ * createDiscoveryFeatureQueryMessage is a function to create didcomm protocol discovery-feature query message
36
+ * @param opts - discovery-feature query options
37
+ * @returns `DiscoverFeatureQueriesMessage`
38
+ */
39
+ function createDiscoveryFeatureQueryMessage(queries, opts) {
40
+ const uuidv4 = uuid.v4();
41
+ return {
42
+ id: uuidv4,
43
+ thid: uuidv4,
44
+ typ: constants_1.MediaType.PlainMessage,
45
+ type: constants_1.PROTOCOL_MESSAGE_TYPE.DISCOVERY_PROTOCOL_QUERIES_MESSAGE_TYPE,
46
+ body: {
47
+ queries
48
+ },
49
+ from: opts?.from,
50
+ to: opts?.to,
51
+ created_time: (0, js_iden3_core_1.getUnixTimestamp)(new Date()),
52
+ expires_time: opts?.expires_time
53
+ };
54
+ }
55
+ exports.createDiscoveryFeatureQueryMessage = createDiscoveryFeatureQueryMessage;
56
+ /**
57
+ * @beta
58
+ * createDiscoveryFeatureDiscloseMessage is a function to create didcomm protocol discovery-feature disclose message
59
+ * @param {DiscoverFeatureDisclosure[]} disclosures - array of disclosures
60
+ * @param opts - basic message options
61
+ * @returns `DiscoverFeatureQueriesMessage`
62
+ */
63
+ function createDiscoveryFeatureDiscloseMessage(disclosures, opts) {
64
+ const uuidv4 = uuid.v4();
65
+ return {
66
+ id: uuidv4,
67
+ typ: constants_1.MediaType.PlainMessage,
68
+ thid: uuidv4,
69
+ type: constants_1.PROTOCOL_MESSAGE_TYPE.DISCOVERY_PROTOCOL_DISCLOSE_MESSAGE_TYPE,
70
+ body: {
71
+ disclosures
72
+ },
73
+ from: opts?.from,
74
+ to: opts?.to,
75
+ created_time: (0, js_iden3_core_1.getUnixTimestamp)(new Date()),
76
+ expires_time: opts?.expires_time
77
+ };
78
+ }
79
+ exports.createDiscoveryFeatureDiscloseMessage = createDiscoveryFeatureDiscloseMessage;
80
+ /**
81
+ *
82
+ * Handler for discovery protocol
83
+ *
84
+ * @public
85
+ * @beta
86
+ * @class DiscoveryProtocolHandler
87
+ * @implements implements DiscoveryProtocolHandler interface
88
+ */
89
+ class DiscoveryProtocolHandler extends message_handler_1.AbstractMessageHandler {
90
+ /**
91
+ * Creates an instance of DiscoveryProtocolHandler.
92
+ * @param {DiscoveryProtocolOptions} _options - discovery protocol options
93
+ */
94
+ constructor(_options) {
95
+ super();
96
+ this._options = _options;
97
+ const headers = [
98
+ 'id',
99
+ 'typ',
100
+ 'type',
101
+ 'thid',
102
+ 'body',
103
+ 'from',
104
+ 'to',
105
+ 'created_time',
106
+ 'expires_time'
107
+ ];
108
+ if (!_options.headers) {
109
+ _options.headers = headers;
110
+ }
111
+ }
112
+ /**
113
+ * @inheritdoc IProtocolMessageHandler#handle
114
+ */
115
+ async handle(message, context) {
116
+ switch (message.type) {
117
+ case constants_1.PROTOCOL_MESSAGE_TYPE.DISCOVERY_PROTOCOL_QUERIES_MESSAGE_TYPE:
118
+ return await this.handleDiscoveryQuery(message, context);
119
+ default:
120
+ return super.handle(message, context);
121
+ }
122
+ }
123
+ /**
124
+ * @inheritdoc IDiscoveryProtocolHandler#handleDiscoveryQuery
125
+ */
126
+ async handleDiscoveryQuery(message, opts) {
127
+ if (!opts?.allowExpiredMessages) {
128
+ (0, common_1.verifyExpiresTime)(message);
129
+ }
130
+ const disclosures = [];
131
+ for (const query of message.body.queries) {
132
+ disclosures.push(...this.handleQuery(query));
133
+ }
134
+ return Promise.resolve(createDiscoveryFeatureDiscloseMessage(disclosures, {
135
+ to: message.from,
136
+ from: message.to,
137
+ expires_time: opts?.disclosureExpiresDate
138
+ ? (0, js_iden3_core_1.getUnixTimestamp)(opts.disclosureExpiresDate)
139
+ : undefined
140
+ }));
141
+ }
142
+ handleQuery(query) {
143
+ let result = [];
144
+ switch (query[discovery_protocol_1.DiscoverFeatureQueryType.FeatureType]) {
145
+ case discovery_protocol_1.DiscoveryProtocolFeatureType.Accept:
146
+ result = this.handleAcceptQuery();
147
+ break;
148
+ case discovery_protocol_1.DiscoveryProtocolFeatureType.Protocol:
149
+ result = this.handleProtocolQuery();
150
+ break;
151
+ case discovery_protocol_1.DiscoveryProtocolFeatureType.GoalCode:
152
+ result = this.handleGoalCodeQuery();
153
+ break;
154
+ case discovery_protocol_1.DiscoveryProtocolFeatureType.Header:
155
+ result = this.handleHeaderQuery();
156
+ break;
157
+ }
158
+ return this.handleMatch(result, query.match);
159
+ }
160
+ handleAcceptQuery() {
161
+ const acceptProfiles = this._options.packageManager.getSupportedProfiles();
162
+ return acceptProfiles.map((profile) => ({
163
+ [discovery_protocol_1.DiscoverFeatureQueryType.FeatureType]: discovery_protocol_1.DiscoveryProtocolFeatureType.Accept,
164
+ id: profile
165
+ }));
166
+ }
167
+ handleProtocolQuery() {
168
+ return (this._options.protocols?.map((protocol) => ({
169
+ [discovery_protocol_1.DiscoverFeatureQueryType.FeatureType]: discovery_protocol_1.DiscoveryProtocolFeatureType.Protocol,
170
+ id: protocol
171
+ })) ?? []);
172
+ }
173
+ handleGoalCodeQuery() {
174
+ return (this._options.goalCodes?.map((goalCode) => ({
175
+ [discovery_protocol_1.DiscoverFeatureQueryType.FeatureType]: discovery_protocol_1.DiscoveryProtocolFeatureType.GoalCode,
176
+ id: goalCode
177
+ })) ?? []);
178
+ }
179
+ handleHeaderQuery() {
180
+ return (this._options.headers?.map((header) => ({
181
+ [discovery_protocol_1.DiscoverFeatureQueryType.FeatureType]: discovery_protocol_1.DiscoveryProtocolFeatureType.Header,
182
+ id: header
183
+ })) ?? []);
184
+ }
185
+ handleMatch(disclosures, match) {
186
+ if (!match || match === '*') {
187
+ return disclosures;
188
+ }
189
+ const regExp = this.wildcardToRegExp(match);
190
+ return disclosures.filter((disclosure) => regExp.test(disclosure.id));
191
+ }
192
+ wildcardToRegExp(match) {
193
+ // Escape special regex characters, then replace `*` with `.*`
194
+ const regexPattern = match.replace(/[.+^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*');
195
+ return new RegExp(`^${regexPattern}$`);
196
+ }
197
+ }
198
+ exports.DiscoveryProtocolHandler = DiscoveryProtocolHandler;
@@ -23,3 +23,4 @@ __exportStar(require("./common"), exports);
23
23
  __exportStar(require("./credential-proposal"), exports);
24
24
  __exportStar(require("./message-handler"), exports);
25
25
  __exportStar(require("./payment"), exports);
26
+ __exportStar(require("./discovery-protocol"), exports);
@@ -18,6 +18,18 @@ class PackageManager {
18
18
  constructor() {
19
19
  this.packers = new Map();
20
20
  }
21
+ /** {@inheritDoc IPackageManager.getSupportedProfiles} */
22
+ getSupportedProfiles() {
23
+ const acceptProfiles = [];
24
+ const mediaTypes = this.getSupportedMediaTypes();
25
+ for (const mediaType of mediaTypes) {
26
+ const p = this.packers.get(mediaType);
27
+ if (p) {
28
+ acceptProfiles.push(...p.getSupportedProfiles());
29
+ }
30
+ }
31
+ return [...new Set(acceptProfiles)];
32
+ }
21
33
  /** {@inheritDoc IPackageManager.isProfileSupported} */
22
34
  isProfileSupported(mediaType, profile) {
23
35
  const p = this.packers.get(mediaType);
@@ -27,6 +27,8 @@ class JWSPacker {
27
27
  constructor(_kms, _documentResolver) {
28
28
  this._kms = _kms;
29
29
  this._documentResolver = _documentResolver;
30
+ this.supportedAlgorithms = [constants_1.AcceptJwsAlgorithms.ES256K, constants_1.AcceptJwsAlgorithms.ES256KR];
31
+ this.supportedProtocolVersions = [constants_1.ProtocolVersion.V1];
30
32
  }
31
33
  /**
32
34
  * Packs the given payload and returns a promise that resolves to the packed data.
@@ -89,24 +91,23 @@ class JWSPacker {
89
91
  }
90
92
  /** {@inheritDoc IPacker.getSupportedProfiles} */
91
93
  getSupportedProfiles() {
92
- return [`env=${this.mediaType()}&alg=${this.getSupportedAlgorithms().join(',')}`];
94
+ return this.supportedProtocolVersions.map((v) => `${v};env=${this.mediaType()};alg=${this.supportedAlgorithms.join(',')}`);
93
95
  }
94
96
  /** {@inheritDoc IPacker.isProfileSupported} */
95
97
  isProfileSupported(profile) {
96
- const { env, circuits, alg } = (0, utils_2.parseAcceptProfile)(profile);
98
+ const { protocolVersion, env, circuits, alg } = (0, utils_2.parseAcceptProfile)(profile);
99
+ if (!this.supportedProtocolVersions.includes(protocolVersion)) {
100
+ return false;
101
+ }
97
102
  if (env !== this.mediaType()) {
98
103
  return false;
99
104
  }
100
105
  if (circuits) {
101
106
  throw new Error(`Circuits are not supported for ${env} media type`);
102
107
  }
103
- const supportedAlgArr = this.getSupportedAlgorithms();
104
- const algSupported = !alg?.length || alg.some((a) => supportedAlgArr.includes(a));
108
+ const algSupported = !alg?.length || alg.some((a) => this.supportedAlgorithms.includes(a));
105
109
  return algSupported;
106
110
  }
107
- getSupportedAlgorithms() {
108
- return [constants_1.AcceptJwsAlgorithms.ES256K, constants_1.AcceptJwsAlgorithms.ES256KR];
109
- }
110
111
  async resolveDidDoc(from) {
111
112
  let didDocument;
112
113
  try {
@@ -12,6 +12,9 @@ const utils_2 = require("../utils");
12
12
  * @implements implements IPacker interface
13
13
  */
14
14
  class PlainPacker {
15
+ constructor() {
16
+ this.supportedProtocolVersions = [constants_1.ProtocolVersion.V1];
17
+ }
15
18
  /**
16
19
  * Packs a basic message using the specified parameters.
17
20
  *
@@ -55,11 +58,14 @@ class PlainPacker {
55
58
  }
56
59
  /** {@inheritDoc IPacker.getSupportedProfiles} */
57
60
  getSupportedProfiles() {
58
- return [`env=${this.mediaType()}`];
61
+ return this.supportedProtocolVersions.map((v) => `${v};env=${this.mediaType()}`);
59
62
  }
60
63
  /** {@inheritDoc IPacker.isProfileSupported} */
61
64
  isProfileSupported(profile) {
62
- const { env, circuits, alg } = (0, utils_2.parseAcceptProfile)(profile);
65
+ const { protocolVersion, env, circuits, alg } = (0, utils_2.parseAcceptProfile)(profile);
66
+ if (!this.supportedProtocolVersions.includes(protocolVersion)) {
67
+ return false;
68
+ }
63
69
  if (env !== this.mediaType()) {
64
70
  return false;
65
71
  }
@@ -83,6 +83,9 @@ class ZKPPacker {
83
83
  this.provingParamsMap = provingParamsMap;
84
84
  this.verificationParamsMap = verificationParamsMap;
85
85
  this._opts = _opts;
86
+ this.supportedProtocolVersions = [constants_1.ProtocolVersion.V1];
87
+ this.supportedAlgorithms = [constants_1.AcceptJwzAlgorithms.Groth16];
88
+ this.supportedCircuitIds = [constants_1.AcceptAuthCircuits.AuthV2];
86
89
  }
87
90
  /**
88
91
  * Packs a basic message using the specified parameters.
@@ -144,28 +147,23 @@ class ZKPPacker {
144
147
  }
145
148
  /** {@inheritDoc IPacker.getSupportedProfiles} */
146
149
  getSupportedProfiles() {
147
- return [
148
- `env=${this.mediaType()}&alg=${this.getSupportedAlgorithms().join(',')}&circuitIds=${this.getSupportedCircuitIds().join(',')}`
149
- ];
150
+ return this.supportedProtocolVersions.map((v) => `${v};env=${this.mediaType()};alg=${this.supportedAlgorithms.join(',')};circuitIds=${this.supportedCircuitIds.join(',')}`);
150
151
  }
151
152
  /** {@inheritDoc IPacker.isProfileSupported} */
152
153
  isProfileSupported(profile) {
153
- const { env, circuits, alg } = (0, utils_2.parseAcceptProfile)(profile);
154
+ const { protocolVersion, env, circuits, alg } = (0, utils_2.parseAcceptProfile)(profile);
155
+ if (!this.supportedProtocolVersions.includes(protocolVersion)) {
156
+ return false;
157
+ }
154
158
  if (env !== this.mediaType()) {
155
159
  return false;
156
160
  }
157
- const supportedCircuitIds = this.getSupportedCircuitIds();
161
+ const supportedCircuitIds = this.supportedCircuitIds;
158
162
  const circuitIdSupported = !circuits?.length || circuits.some((c) => supportedCircuitIds.includes(c));
159
- const supportedAlgArr = this.getSupportedAlgorithms();
163
+ const supportedAlgArr = this.supportedAlgorithms;
160
164
  const algSupported = !alg?.length || alg.some((a) => supportedAlgArr.includes(a));
161
165
  return algSupported && circuitIdSupported;
162
166
  }
163
- getSupportedAlgorithms() {
164
- return [constants_1.AcceptJwzAlgorithms.Groth16];
165
- }
166
- getSupportedCircuitIds() {
167
- return [constants_1.AcceptAuthCircuits.AuthV2];
168
- }
169
167
  }
170
168
  exports.ZKPPacker = ZKPPacker;
171
169
  const verifySender = async (token, msg) => {
@@ -23,6 +23,7 @@ __exportStar(require("./protocol/contract-request"), exports);
23
23
  __exportStar(require("./protocol/proposal-request"), exports);
24
24
  __exportStar(require("./protocol/payment"), exports);
25
25
  __exportStar(require("./protocol/accept-profile"), exports);
26
+ __exportStar(require("./protocol/discovery-protocol"), exports);
26
27
  __exportStar(require("./packer"), exports);
27
28
  __exportStar(require("./models"), exports);
28
29
  __exportStar(require("./packageManager"), exports);
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DiscoveryProtocolFeatureType = exports.DiscoverFeatureQueryType = void 0;
4
+ /** @beta DiscoverFeatureQueryType is enum for query type fields */
5
+ var DiscoverFeatureQueryType;
6
+ (function (DiscoverFeatureQueryType) {
7
+ DiscoverFeatureQueryType["FeatureType"] = "feature-type";
8
+ })(DiscoverFeatureQueryType = exports.DiscoverFeatureQueryType || (exports.DiscoverFeatureQueryType = {}));
9
+ /** @beta DiscoveryProtocolFeatureType is enum for supported feature-types */
10
+ var DiscoveryProtocolFeatureType;
11
+ (function (DiscoveryProtocolFeatureType) {
12
+ DiscoveryProtocolFeatureType["Accept"] = "accept";
13
+ DiscoveryProtocolFeatureType["Protocol"] = "protocol";
14
+ DiscoveryProtocolFeatureType["GoalCode"] = "goal-code";
15
+ DiscoveryProtocolFeatureType["Header"] = "header";
16
+ })(DiscoveryProtocolFeatureType = exports.DiscoveryProtocolFeatureType || (exports.DiscoveryProtocolFeatureType = {}));
@@ -1,4 +1,5 @@
1
1
  const IDEN3_PROTOCOL = 'https://iden3-communication.io/';
2
+ const DIDCOMM_PROTOCOL = 'https://didcomm.org/';
2
3
  /**
3
4
  * Constants for Iden3 protocol
4
5
  */
@@ -42,7 +43,11 @@ export const PROTOCOL_MESSAGE_TYPE = Object.freeze({
42
43
  // PaymentRequestMessageType is type for payment-request message
43
44
  PAYMENT_REQUEST_MESSAGE_TYPE: `${IDEN3_PROTOCOL}credentials/0.1/payment-request`,
44
45
  // PaymentMessageType is type for payment message
45
- PAYMENT_MESSAGE_TYPE: `${IDEN3_PROTOCOL}credentials/0.1/payment`
46
+ PAYMENT_MESSAGE_TYPE: `${IDEN3_PROTOCOL}credentials/0.1/payment`,
47
+ // DiscoveryProtocolQueriesMessageType is type for didcomm discovery protocol queries
48
+ DISCOVERY_PROTOCOL_QUERIES_MESSAGE_TYPE: `${DIDCOMM_PROTOCOL}discover-features/2.0/queries`,
49
+ // DiscoveryProtocolDiscloseMessageType is type for didcomm discovery protocol disclose
50
+ DISCOVERY_PROTOCOL_DISCLOSE_MESSAGE_TYPE: `${DIDCOMM_PROTOCOL}discover-features/2.0/disclose`
46
51
  });
47
52
  /**
48
53
  * Media types for iden3 comm communication protocol
@@ -1,4 +1,4 @@
1
- import { MediaType, ProtocolVersion } from '../constants';
1
+ import { MediaType } from '../constants';
2
2
  import { PROTOCOL_MESSAGE_TYPE } from '../constants';
3
3
  import { DID, getUnixTimestamp } from '@iden3/js-iden3-core';
4
4
  import { proving } from '@iden3/js-jwz';
@@ -259,32 +259,24 @@ export class AuthHandler extends AbstractMessageHandler {
259
259
  }
260
260
  getSupportedMediaTypeByProfile(ctx, responseType, profile) {
261
261
  let mediaType;
262
- if (profile?.length) {
263
- const supportedMediaTypes = [];
264
- for (const acceptProfile of profile) {
265
- // 1. check protocol version
266
- const { protocolVersion, env } = parseAcceptProfile(acceptProfile);
267
- const responseTypeVersion = Number(responseType.split('/').at(-2));
268
- if (protocolVersion !== ProtocolVersion.V1 ||
269
- (protocolVersion === ProtocolVersion.V1 &&
270
- (responseTypeVersion < 1 || responseTypeVersion >= 2))) {
271
- continue;
272
- }
273
- // 2. check packer support
274
- if (this._packerMgr.isProfileSupported(env, acceptProfile)) {
275
- supportedMediaTypes.push(env);
276
- }
277
- }
278
- if (!supportedMediaTypes.length) {
279
- throw new Error('no packer with profile which meets `accept` header requirements');
280
- }
281
- mediaType = supportedMediaTypes[0];
282
- if (ctx.mediaType && supportedMediaTypes.includes(ctx.mediaType)) {
283
- mediaType = ctx.mediaType;
262
+ if (!profile?.length) {
263
+ return ctx.mediaType || MediaType.ZKPMessage;
264
+ }
265
+ const supportedMediaTypes = [];
266
+ for (const acceptProfile of profile) {
267
+ const { env } = parseAcceptProfile(acceptProfile);
268
+ if (this._packerMgr.isProfileSupported(env, acceptProfile)) {
269
+ supportedMediaTypes.push(env);
284
270
  }
285
271
  }
286
- else {
287
- mediaType = ctx.mediaType || MediaType.ZKPMessage;
272
+ if (!supportedMediaTypes.length) {
273
+ throw new Error('no packer with profile which meets `accept` header requirements');
274
+ }
275
+ mediaType = supportedMediaTypes.includes(MediaType.ZKPMessage)
276
+ ? MediaType.ZKPMessage
277
+ : supportedMediaTypes[0];
278
+ if (ctx.mediaType && supportedMediaTypes.includes(ctx.mediaType)) {
279
+ mediaType = ctx.mediaType;
288
280
  }
289
281
  return mediaType;
290
282
  }