@keetanetwork/anchor 0.0.24 → 0.0.26

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 (32) hide show
  1. package/lib/certificates.d.ts +23 -9
  2. package/lib/certificates.d.ts.map +1 -1
  3. package/lib/certificates.generated.js +16 -1
  4. package/lib/certificates.generated.js.map +1 -1
  5. package/lib/certificates.js +74 -157
  6. package/lib/certificates.js.map +1 -1
  7. package/lib/resolver.js +40 -40
  8. package/lib/utils/asn1.d.ts +13 -0
  9. package/lib/utils/asn1.d.ts.map +1 -1
  10. package/lib/utils/asn1.js +1973 -0
  11. package/lib/utils/asn1.js.map +1 -1
  12. package/lib/utils/external.d.ts.map +1 -1
  13. package/lib/utils/external.js +2 -9
  14. package/lib/utils/external.js.map +1 -1
  15. package/npm-shrinkwrap.json +2 -2
  16. package/package.json +1 -1
  17. package/services/asset-movement/common.d.ts +70 -46
  18. package/services/asset-movement/common.d.ts.map +1 -1
  19. package/services/asset-movement/common.js +1442 -708
  20. package/services/asset-movement/common.js.map +1 -1
  21. package/services/asset-movement/lib/location.d.ts +64 -0
  22. package/services/asset-movement/lib/location.d.ts.map +1 -0
  23. package/services/asset-movement/lib/location.generated.d.ts +4 -0
  24. package/services/asset-movement/lib/location.generated.d.ts.map +1 -0
  25. package/services/asset-movement/lib/location.generated.js +16 -0
  26. package/services/asset-movement/lib/location.generated.js.map +1 -0
  27. package/services/asset-movement/lib/location.js +155 -0
  28. package/services/asset-movement/lib/location.js.map +1 -0
  29. package/services/kyc/iso20022.generated.js +54 -54
  30. package/services/kyc/iso20022.generated.js.map +1 -1
  31. package/services/kyc/utils/generate-kyc-schema.js +6 -34
  32. package/services/kyc/utils/generate-kyc-schema.js.map +1 -1
@@ -2,15 +2,18 @@ import * as KeetaNetClient from '@keetanetwork/keetanet-client';
2
2
  import { Buffer } from './utils/buffer.js';
3
3
  import type { CertificateAttributeValue } from '../services/kyc/iso20022.generated.js';
4
4
  import { CertificateAttributeOIDDB } from '../services/kyc/iso20022.generated.js';
5
- /**
6
- * Short alias for the KeetaNetAccount type
7
- */
8
- declare const KeetaNetAccount: typeof KeetaNetClient.lib.Account;
5
+ type BaseCertificateClass = typeof KeetaNetClient.lib.Utils.Certificate.Certificate;
6
+ type BaseCertificate = InstanceType<BaseCertificateClass>;
7
+ declare const BaseCertificate: BaseCertificateClass;
8
+ type BaseCertificateBuilderClass = typeof KeetaNetClient.lib.Utils.Certificate.CertificateBuilder;
9
+ type BaseCertificateBuilder = InstanceType<BaseCertificateBuilderClass>;
10
+ declare const BaseCertificateBuilder: BaseCertificateBuilderClass;
9
11
  type AccountKeyAlgorithm = InstanceType<typeof KeetaNetClient.lib.Account>['keyType'];
10
12
  /**
11
13
  * An alias for the KeetaNetAccount type
12
14
  */
13
15
  type KeetaNetAccount = ReturnType<typeof KeetaNetClient.lib.Account.fromSeed<AccountKeyAlgorithm>>;
16
+ declare const KeetaNetAccount: typeof KeetaNetClient.lib.Account;
14
17
  declare function assertCertificateAttributeNames(name: string): asserts name is CertificateAttributeNames;
15
18
  declare class SensitiveAttribute<T = ArrayBuffer> {
16
19
  #private;
@@ -48,7 +51,7 @@ declare class SensitiveAttribute<T = ArrayBuffer> {
48
51
  * Type for certificate attribute names (derived from generated OID database)
49
52
  */
50
53
  type CertificateAttributeNames = keyof typeof CertificateAttributeOIDDB;
51
- type BaseCertificateBuilderParams = NonNullable<ConstructorParameters<typeof KeetaNetClient.lib.Utils.Certificate.CertificateBuilder>[0]>;
54
+ type BaseCertificateBuilderParams = NonNullable<ConstructorParameters<BaseCertificateBuilderClass>[0]>;
52
55
  type CertificateBuilderParams = Required<Pick<BaseCertificateBuilderParams, 'issuer' | 'validFrom' | 'validTo' | 'serial' | 'hashLib' | 'issuerDN' | 'subjectDN' | 'isCA'> & {
53
56
  /**
54
57
  * The key of the subject -- used for Sensitive Attributes as well
@@ -57,7 +60,7 @@ type CertificateBuilderParams = Required<Pick<BaseCertificateBuilderParams, 'iss
57
60
  subject: BaseCertificateBuilderParams['subjectPublicKey'];
58
61
  }>;
59
62
  type CertificateAttributeInput<NAME extends CertificateAttributeNames> = CertificateAttributeValue<NAME>;
60
- export declare class CertificateBuilder extends KeetaNetClient.lib.Utils.Certificate.CertificateBuilder {
63
+ export declare class CertificateBuilder extends BaseCertificateBuilder {
61
64
  #private;
62
65
  /**
63
66
  * Map the parameters from the public interface to the internal
@@ -74,7 +77,7 @@ export declare class CertificateBuilder extends KeetaNetClient.lib.Utils.Certifi
74
77
  * value can be proven later without revealing it.
75
78
  */
76
79
  setAttribute<NAME extends CertificateAttributeNames>(name: NAME, sensitive: boolean, value: CertificateAttributeInput<NAME>): void;
77
- protected addExtensions(...args: Parameters<InstanceType<typeof KeetaNetClient.lib.Utils.Certificate.CertificateBuilder>['addExtensions']>): ReturnType<InstanceType<typeof KeetaNetClient.lib.Utils.Certificate.CertificateBuilder>['addExtensions']>;
80
+ protected addExtensions(...args: Parameters<BaseCertificateBuilder['addExtensions']>): ReturnType<BaseCertificateBuilder['addExtensions']>;
78
81
  /**
79
82
  * Create a Certificate object from the builder
80
83
  *
@@ -83,7 +86,7 @@ export declare class CertificateBuilder extends KeetaNetClient.lib.Utils.Certifi
83
86
  */
84
87
  build(params?: Partial<CertificateBuilderParams>): Promise<Certificate>;
85
88
  }
86
- export declare class Certificate extends KeetaNetClient.lib.Utils.Certificate.Certificate {
89
+ export declare class Certificate extends BaseCertificate {
87
90
  private readonly subjectKey;
88
91
  static readonly Builder: typeof CertificateBuilder;
89
92
  static readonly SharableAttributes: typeof SharableCertificateAttributes;
@@ -99,7 +102,7 @@ export declare class Certificate extends KeetaNetClient.lib.Utils.Certificate.Ce
99
102
  value: ArrayBuffer;
100
103
  };
101
104
  };
102
- constructor(input: ConstructorParameters<typeof KeetaNetClient.lib.Utils.Certificate.Certificate>[0], options?: ConstructorParameters<typeof KeetaNetClient.lib.Utils.Certificate.Certificate>[1] & {
105
+ constructor(input: ConstructorParameters<BaseCertificateClass>[0], options?: ConstructorParameters<BaseCertificateClass>[1] & {
103
106
  subjectKey?: KeetaNetAccount;
104
107
  });
105
108
  protected finalizeConstruction(): void;
@@ -132,6 +135,7 @@ export declare namespace SharableCertificateAttributesTypes {
132
135
  };
133
136
  type ContentsSchema = {
134
137
  certificate: string;
138
+ intermediates?: string[] | undefined;
135
139
  attributes: {
136
140
  [name: string]: {
137
141
  sensitive: true;
@@ -162,11 +166,21 @@ export declare class SharableCertificateAttributes {
162
166
  * and a list of attribute names to include -- if no list is
163
167
  * provided, all attributes are included.
164
168
  */
169
+ static fromCertificate(certificate: Certificate, intermediates?: Set<BaseCertificate>, attributeNames?: CertificateAttributeNames[]): Promise<SharableCertificateAttributes>;
170
+ /** @deprecated Use the overload with three parameters instead */
165
171
  static fromCertificate(certificate: Certificate, attributeNames?: CertificateAttributeNames[]): Promise<SharableCertificateAttributes>;
166
172
  grantAccess(principal: KeetaNetAccount): Promise<this>;
167
173
  revokeAccess(principal: KeetaNetAccount): Promise<this>;
168
174
  get principals(): KeetaNetAccount[];
169
175
  getCertificate(): Promise<Certificate>;
176
+ /**
177
+ * Get the intermediate certificates included in this sharable
178
+ * certificate container
179
+ *
180
+ * @return A set of BaseCertificate objects representing the
181
+ * intermediate certificates attached to this container
182
+ */
183
+ getIntermediates(): Promise<Set<BaseCertificate>>;
170
184
  getAttributeBuffer(name: string): Promise<ArrayBuffer | undefined>;
171
185
  getAttribute<NAME extends CertificateAttributeNames>(name: NAME): Promise<CertificateAttributeValue<NAME> | undefined>;
172
186
  getAttributeNames(includeUnknown: true): Promise<string[]>;
@@ -1 +1 @@
1
- {"version":3,"file":"certificates.d.ts","sourceRoot":"","sources":["../../src/lib/certificates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,cAAc,MAAM,+BAA+B,CAAC;AAGhE,OAAO,EAAgD,MAAM,EAAuB,MAAM,mBAAmB,CAAC;AAG9G,OAAO,KAAK,EAA0B,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;A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MAAM,CAAC;IACnH,MAAM,CAAC,OAAO,CAAC,EAAE,0CAA0C,GAAG,OAAO,CAAC,WAAW,GAAG,MAAM,CAAC;CA8B3F"}
@@ -1,7 +1,7 @@
1
1
  import * as __typia_transform__assertGuard from "typia/lib/internal/_assertGuard.js";
2
2
  import * as __typia_transform__accessExpressionAsString from "typia/lib/internal/_accessExpressionAsString.js";
3
3
  import * as typia from 'typia';
4
- export const assertSharableCertificateAttributesContentsSchema = (() => { const _io0 = input => "string" === typeof input.certificate && ("object" === typeof input.attributes && null !== input.attributes && false === Array.isArray(input.attributes) && _io1(input.attributes)); const _io1 = input => Object.keys(input).every(key => {
4
+ export const assertSharableCertificateAttributesContentsSchema = (() => { const _io0 = input => "string" === typeof input.certificate && (undefined === input.intermediates || Array.isArray(input.intermediates) && input.intermediates.every(elem => "string" === typeof elem)) && ("object" === typeof input.attributes && null !== input.attributes && false === Array.isArray(input.attributes) && _io1(input.attributes)); const _io1 = input => Object.keys(input).every(key => {
5
5
  const value = input[key];
6
6
  if (undefined === value)
7
7
  return true;
@@ -28,6 +28,21 @@ export const assertSharableCertificateAttributesContentsSchema = (() => { const
28
28
  path: _path + ".certificate",
29
29
  expected: "string",
30
30
  value: input.certificate
31
+ }, _errorFactory)) && (undefined === input.intermediates || (Array.isArray(input.intermediates) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
32
+ method: "typia.createAssert",
33
+ path: _path + ".intermediates",
34
+ expected: "(Array<string> | undefined)",
35
+ value: input.intermediates
36
+ }, _errorFactory)) && input.intermediates.every((elem, _index2) => "string" === typeof elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
37
+ method: "typia.createAssert",
38
+ path: _path + ".intermediates[" + _index2 + "]",
39
+ expected: "string",
40
+ value: elem
41
+ }, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
42
+ method: "typia.createAssert",
43
+ path: _path + ".intermediates",
44
+ expected: "(Array<string> | undefined)",
45
+ value: input.intermediates
31
46
  }, _errorFactory)) && (("object" === typeof input.attributes && null !== input.attributes && false === Array.isArray(input.attributes) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
32
47
  method: "typia.createAssert",
33
48
  path: _path + ".attributes",
@@ -1 +1 @@
1
- {"version":3,"file":"certificates.generated.js","sourceRoot":"","sources":["../../src/lib/certificates.generated.ts"],"names":[],"mappings":";;AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,MAAM,CAAC,MAAM,iDAAiD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAAiJ,CAAC","sourcesContent":["import * as typia from 'typia';\nimport type { SharableCertificateAttributesTypes } from './certificates.js';\n\nexport const assertSharableCertificateAttributesContentsSchema: (input: unknown) => SharableCertificateAttributesTypes.ContentsSchema = typia.createAssert<SharableCertificateAttributesTypes.ContentsSchema>();\n"]}
1
+ {"version":3,"file":"certificates.generated.js","sourceRoot":"","sources":["../../src/lib/certificates.generated.ts"],"names":[],"mappings":";;AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,MAAM,CAAC,MAAM,iDAAiD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAAiJ,CAAC","sourcesContent":["import * as typia from 'typia';\nimport type { SharableCertificateAttributesTypes } from './certificates.js';\n\nexport const assertSharableCertificateAttributesContentsSchema: (input: unknown) => SharableCertificateAttributesTypes.ContentsSchema = typia.createAssert<SharableCertificateAttributesTypes.ContentsSchema>();\n"]}
@@ -1,6 +1,7 @@
1
1
  import * as KeetaNetClient from '@keetanetwork/keetanet-client';
2
2
  import * as oids from '../services/kyc/oids.generated.js';
3
3
  import * as ASN1 from './utils/asn1.js';
4
+ import { ASN1toJS, contextualizeStructSchema, encodeValueBySchema, normalizeDecodedASN1 } from './utils/asn1.js';
4
5
  import { arrayBufferLikeToBuffer, arrayBufferToBuffer, Buffer, bufferToArrayBuffer } from './utils/buffer.js';
5
6
  import crypto from './utils/crypto.js';
6
7
  import { assertNever } from './utils/never.js';
@@ -14,127 +15,9 @@ import { checkHashWithOID } from './utils/external.js';
14
15
  * Short alias for printing a debug representation of an object
15
16
  */
16
17
  const DPO = KeetaNetClient.lib.Utils.Helper.debugPrintableObject.bind(KeetaNetClient.lib.Utils.Helper);
17
- /**
18
- * Short alias for the KeetaNetAccount type
19
- */
18
+ const BaseCertificate = KeetaNetClient.lib.Utils.Certificate.Certificate;
19
+ const BaseCertificateBuilder = KeetaNetClient.lib.Utils.Certificate.CertificateBuilder;
20
20
  const KeetaNetAccount = KeetaNetClient.lib.Account;
21
- function isPlainObject(value) {
22
- return (typeof value === 'object' && value !== null && !Array.isArray(value));
23
- }
24
- /**
25
- * Recursively normalize object properties
26
- */
27
- function normalizeDecodedASN1Object(obj, principals) {
28
- const result = {};
29
- for (const [key, value] of Object.entries(obj)) {
30
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
31
- result[key] = normalizeDecodedASN1(value, principals);
32
- }
33
- return (result);
34
- }
35
- /**
36
- * Post-process the output from toJavaScriptObject() to:
37
- * 1. Unwrap any remaining ASN.1-like objects (from IsAnyString/IsAnyDate)
38
- * 2. Add domain-specific $blob function to Reference objects
39
- */
40
- function normalizeDecodedASN1(input, principals) {
41
- // Handle primitives
42
- if (input === undefined || input === null || typeof input !== 'object') {
43
- return (input);
44
- }
45
- if (input instanceof Date || Buffer.isBuffer(input) || input instanceof ArrayBuffer) {
46
- return (input);
47
- }
48
- // Handle arrays
49
- if (Array.isArray(input)) {
50
- return (input.map(item => normalizeDecodedASN1(item, principals)));
51
- }
52
- // Unwrap ASN.1-like objects from ambiguous schemas (IsAnyString, IsAnyDate, IsBitString)
53
- // These are plain objects like { type: 'string', kind: 'utf8', value: 'text' }
54
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
55
- const obj = input;
56
- if (obj.type === 'string' && 'value' in obj && typeof obj.value === 'string') {
57
- return (obj.value);
58
- }
59
- if (obj.type === 'date' && 'value' in obj && obj.value instanceof Date) {
60
- return (obj.value);
61
- }
62
- if (obj.type === 'bitstring' && 'value' in obj && Buffer.isBuffer(obj.value)) {
63
- return (obj.value);
64
- }
65
- // Check if this is a Reference object (has external.url and digest fields)
66
- if ('external' in obj && 'digest' in obj && isPlainObject(obj.external) && isPlainObject(obj.digest)) {
67
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
68
- const ref = obj;
69
- const url = ref.external.url;
70
- const mimeType = ref.external.contentType;
71
- // After toJavaScriptObject(), OIDs are strings, not {oid: string}
72
- const encryptionAlgoOID = typeof ref.encryptionAlgorithm === 'string'
73
- ? ref.encryptionAlgorithm
74
- : ref.encryptionAlgorithm?.oid;
75
- const digestInfo = ref.digest;
76
- if (typeof url === 'string' && typeof mimeType === 'string' && digestInfo) {
77
- let cachedValue = null;
78
- return ({
79
- ...normalizeDecodedASN1Object(obj, principals),
80
- $blob: async function (additionalPrincipals) {
81
- if (cachedValue) {
82
- return (cachedValue);
83
- }
84
- const fetchResult = await fetch(url);
85
- if (!fetchResult.ok) {
86
- throw (new Error(`Failed to fetch remote data from ${url}: ${fetchResult.status} ${fetchResult.statusText}`));
87
- }
88
- const dataBlob = await fetchResult.blob();
89
- let data = await dataBlob.arrayBuffer();
90
- // Handle JSON base64 encoding
91
- if (dataBlob.type === 'application/json') {
92
- try {
93
- const asJSON = JSON.parse(Buffer.from(data).toString('utf-8'));
94
- if (isPlainObject(asJSON) && Object.keys(asJSON).length === 2) {
95
- if ('data' in asJSON && typeof asJSON.data === 'string' && 'mimeType' in asJSON && typeof asJSON.mimeType === 'string') {
96
- data = bufferToArrayBuffer(Buffer.from(asJSON.data, 'base64'));
97
- }
98
- }
99
- }
100
- catch {
101
- /* Ignored */
102
- }
103
- }
104
- // Decrypt if needed
105
- if (encryptionAlgoOID) {
106
- switch (encryptionAlgoOID) {
107
- case '1.3.6.1.4.1.62675.2':
108
- case 'KeetaEncryptedContainerV1': {
109
- const container = EncryptedContainer.fromEncryptedBuffer(data, [
110
- ...principals,
111
- ...(additionalPrincipals ?? [])
112
- ]);
113
- data = await container.getPlaintext();
114
- break;
115
- }
116
- default:
117
- throw (new Error(`Unsupported encryption algorithm OID: ${encryptionAlgoOID}`));
118
- }
119
- }
120
- // Verify hash (checkHashWithOID now accepts string OIDs directly)
121
- if (!Buffer.isBuffer(digestInfo.digest)) {
122
- throw (new TypeError('Digest value is not a buffer'));
123
- }
124
- const validHash = await checkHashWithOID(data, digestInfo);
125
- if (validHash !== true) {
126
- throw (validHash);
127
- }
128
- const blob = new Blob([data], { type: mimeType });
129
- cachedValue = blob;
130
- return (blob);
131
- }
132
- });
133
- }
134
- }
135
- // Recursively process plain objects
136
- return (normalizeDecodedASN1Object(obj, principals));
137
- }
138
21
  function isBlob(input) {
139
22
  if (typeof input !== 'object' || input === null) {
140
23
  return (false);
@@ -254,16 +137,12 @@ function asCertificateAttributeNames(name) {
254
137
  assertCertificateAttributeNames(name);
255
138
  return (name);
256
139
  }
140
+ function resolveSchema(name, schema) {
141
+ return (contextualizeStructSchema(schema));
142
+ }
257
143
  function encodeAttribute(name, value) {
258
- const schema = CertificateAttributeSchema[name];
259
- let encodedJS;
260
- try {
261
- encodedJS = new ASN1.ValidateASN1(schema).fromJavaScriptObject(value);
262
- }
263
- catch (err) {
264
- const message = err instanceof Error ? err.message : String(err);
265
- throw (new Error(`Attribute ${name}: ${message} (value: ${JSON.stringify(DPO(value))})`));
266
- }
144
+ const schema = resolveSchema(name, CertificateAttributeSchema[name]);
145
+ const encodedJS = encodeValueBySchema(schema, value, { attributeName: name });
267
146
  if (encodedJS === undefined) {
268
147
  throw (new Error(`Unsupported attribute value for encoding: ${JSON.stringify(DPO(value))}`));
269
148
  }
@@ -299,18 +178,11 @@ function encodeForSensitive(name, value) {
299
178
  return (Buffer.from(String(value), 'utf-8'));
300
179
  }
301
180
  async function decodeAttribute(name, value, principals) {
302
- const schema = CertificateAttributeSchema[name];
303
- const decodedASN1 = new ASN1.BufferStorageASN1(value, schema).getASN1();
304
- const validator = new ASN1.ValidateASN1(schema);
181
+ const schema = resolveSchema(name, CertificateAttributeSchema[name]);
305
182
  // XXX:TODO Fix depth issue
306
- // @ts-expect-error
307
- const plainObject = validator.toJavaScriptObject(decodedASN1);
308
- // Post-process to:
309
- // 1. Unwrap any remaining ASN.1-like objects
310
- // 2. Add domain-specific $blob function to Reference objects
311
- // XXX:TODO Fix depth issue
312
- // @ts-expect-error
313
- const candidate = normalizeDecodedASN1(plainObject, principals);
183
+ // @ts-ignore
184
+ const decodedUnknown = new ASN1.BufferStorageASN1(value, schema).getASN1();
185
+ const candidate = normalizeDecodedASN1(decodedUnknown, principals);
314
186
  return (asAttributeValue(name, candidate));
315
187
  }
316
188
  class SensitiveAttributeBuilder {
@@ -411,7 +283,7 @@ class SensitiveAttribute {
411
283
  decodedAttribute = dataObject.getASN1();
412
284
  }
413
285
  catch {
414
- const js = ASN1.ASN1toJS(data);
286
+ const js = ASN1toJS(data);
415
287
  throw (new Error(`SensitiveAttribute.decode: unexpected DER shape ${JSON.stringify(DPO(js))}`));
416
288
  }
417
289
  const decodedVersion = decodedAttribute[0] + 1n;
@@ -552,7 +424,7 @@ const CertificateKYCAttributeSchemaValidation = {
552
424
  ]
553
425
  }]
554
426
  };
555
- export class CertificateBuilder extends KeetaNetClient.lib.Utils.Certificate.CertificateBuilder {
427
+ export class CertificateBuilder extends BaseCertificateBuilder {
556
428
  #attributes = {};
557
429
  /**
558
430
  * Map the parameters from the public interface to the internal
@@ -651,7 +523,7 @@ export class CertificateBuilder extends KeetaNetClient.lib.Utils.Certificate.Cer
651
523
  }]);
652
524
  }
653
525
  if (certAttributes.length > 0) {
654
- retval.push(KeetaNetClient.lib.Utils.Certificate.CertificateBuilder.extension(oids.keeta.KYC_ATTRIBUTES, certAttributes));
526
+ retval.push(BaseCertificateBuilder.extension(oids.keeta.KYC_ATTRIBUTES, certAttributes));
655
527
  }
656
528
  return (retval);
657
529
  }
@@ -677,7 +549,7 @@ export class CertificateBuilder extends KeetaNetClient.lib.Utils.Certificate.Cer
677
549
  return (certificateObject);
678
550
  }
679
551
  }
680
- export class Certificate extends KeetaNetClient.lib.Utils.Certificate.Certificate {
552
+ export class Certificate extends BaseCertificate {
681
553
  subjectKey;
682
554
  static Builder = CertificateBuilder;
683
555
  static SharableAttributes;
@@ -694,7 +566,7 @@ export class Certificate extends KeetaNetClient.lib.Utils.Certificate.Certificat
694
566
  /* Do nothing, we call the super method in the constructor */
695
567
  }
696
568
  setPlainAttribute(name, value) {
697
- // @ts-expect-error
569
+ // @ts-ignore
698
570
  this.attributes[name] = { sensitive: false, value };
699
571
  }
700
572
  setSensitiveAttribute(name, value) {
@@ -760,6 +632,7 @@ export class Certificate extends KeetaNetClient.lib.Utils.Certificate.Certificat
760
632
  ;
761
633
  export class SharableCertificateAttributes {
762
634
  #certificate;
635
+ #intermediates;
763
636
  #attributes = {};
764
637
  container;
765
638
  populatedFromInit = false;
@@ -821,12 +694,28 @@ export class SharableCertificateAttributes {
821
694
  }
822
695
  this.container = EncryptedContainer.fromEncodedBuffer(containerBuffer, principals);
823
696
  }
824
- /**
825
- * Create a SharableCertificateAttributes from a Certificate
826
- * and a list of attribute names to include -- if no list is
827
- * provided, all attributes are included.
828
- */
829
- static async fromCertificate(certificate, attributeNames) {
697
+ static async fromCertificate(certificate, intermediatesOrAttributeNames, definitelyAttributeNames) {
698
+ let intermediates = undefined;
699
+ let attributeNames = undefined;
700
+ if (definitelyAttributeNames === undefined) {
701
+ if (intermediatesOrAttributeNames !== undefined) {
702
+ if (Array.isArray(intermediatesOrAttributeNames)) {
703
+ attributeNames = intermediatesOrAttributeNames;
704
+ }
705
+ else {
706
+ intermediates = intermediatesOrAttributeNames;
707
+ }
708
+ }
709
+ }
710
+ else {
711
+ if (intermediatesOrAttributeNames !== undefined) {
712
+ if (Array.isArray(intermediatesOrAttributeNames)) {
713
+ throw (new TypeError('Expected Set<BaseCertificate> for intermediates'));
714
+ }
715
+ intermediates = intermediatesOrAttributeNames;
716
+ }
717
+ attributeNames = definitelyAttributeNames;
718
+ }
830
719
  if (attributeNames === undefined) {
831
720
  /*
832
721
  * We know the keys are whatever the Certificate says they are, so
@@ -910,15 +799,28 @@ export class SharableCertificateAttributes {
910
799
  };
911
800
  }
912
801
  }
802
+ let intermediatesJSON;
803
+ intermediates ??= new Set();
804
+ if (intermediates.size === 0) {
805
+ intermediatesJSON = undefined;
806
+ }
807
+ else {
808
+ intermediatesJSON = Array.from(intermediates).map(function (intermediateCertificate) {
809
+ return (intermediateCertificate.toPEM());
810
+ });
811
+ }
913
812
  const contentsString = JSON.stringify({
914
813
  certificate: certificate.toPEM(),
814
+ intermediates: intermediatesJSON,
915
815
  attributes: attributes
916
816
  });
917
817
  const temporaryUser = KeetaNetAccount.fromSeed(KeetaNetAccount.generateRandomSeed(), 0);
918
818
  const contentsBuffer = Buffer.from(contentsString, 'utf-8');
919
819
  const container = EncryptedContainer.fromPlaintext(bufferToArrayBuffer(contentsBuffer), [temporaryUser], true);
920
820
  const containerBuffer = await container.getEncodedBuffer();
921
- const retval = new SharableCertificateAttributes(containerBuffer, { principals: temporaryUser });
821
+ const retval = new SharableCertificateAttributes(containerBuffer, {
822
+ principals: temporaryUser
823
+ });
922
824
  await retval.revokeAccess(temporaryUser);
923
825
  return (retval);
924
826
  }
@@ -954,6 +856,11 @@ export class SharableCertificateAttributes {
954
856
  const contentsString = Buffer.from(contentsBufferDecompressed).toString('utf-8');
955
857
  const contentsJSON = JSON.parse(contentsString);
956
858
  const contents = assertSharableCertificateAttributesContentsSchema(contentsJSON);
859
+ this.#intermediates = new Set();
860
+ for (const intermediatePEM of contents.intermediates ?? []) {
861
+ const intermediateCert = new BaseCertificate(intermediatePEM);
862
+ this.#intermediates.add(intermediateCert);
863
+ }
957
864
  this.#certificate = new Certificate(contents.certificate);
958
865
  const attributePromises = Object.entries(contents.attributes).map(async ([name, attr]) => {
959
866
  /*
@@ -1009,6 +916,20 @@ export class SharableCertificateAttributes {
1009
916
  }
1010
917
  return (this.#certificate);
1011
918
  }
919
+ /**
920
+ * Get the intermediate certificates included in this sharable
921
+ * certificate container
922
+ *
923
+ * @return A set of BaseCertificate objects representing the
924
+ * intermediate certificates attached to this container
925
+ */
926
+ async getIntermediates() {
927
+ await this.#populate();
928
+ if (this.#intermediates && this.#intermediates.size > 0) {
929
+ return (new Set(this.#intermediates));
930
+ }
931
+ return (new Set());
932
+ }
1012
933
  async getAttributeBuffer(name) {
1013
934
  await this.#populate();
1014
935
  const attr = this.#attributes[name];
@@ -1117,10 +1038,6 @@ Certificate.SharableAttributes = SharableCertificateAttributes;
1117
1038
  /** @internal */
1118
1039
  export const _Testing = {
1119
1040
  SensitiveAttributeBuilder,
1120
- SensitiveAttribute,
1121
- ValidateASN1: ASN1.ValidateASN1,
1122
- BufferStorageASN1: ASN1.BufferStorageASN1,
1123
- JStoASN1: ASN1.JStoASN1,
1124
- normalizeDecodedASN1
1041
+ SensitiveAttribute
1125
1042
  };
1126
1043
  //# sourceMappingURL=certificates.js.map