@keetanetwork/anchor 0.0.26 → 0.0.28
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/lib/certificates.d.ts +9 -6
- package/lib/certificates.d.ts.map +1 -1
- package/lib/certificates.js +213 -16
- package/lib/certificates.js.map +1 -1
- package/lib/utils/asn1.d.ts +0 -13
- package/lib/utils/asn1.d.ts.map +1 -1
- package/lib/utils/asn1.js +0 -1973
- package/lib/utils/asn1.js.map +1 -1
- package/lib/utils/external.d.ts.map +1 -1
- package/lib/utils/external.js +9 -2
- package/lib/utils/external.js.map +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/services/asset-movement/common.d.ts +12 -4
- package/services/asset-movement/common.d.ts.map +1 -1
- package/services/asset-movement/common.js +56 -16
- package/services/asset-movement/common.js.map +1 -1
- package/services/kyc/iso20022.generated.js +54 -54
- package/services/kyc/iso20022.generated.js.map +1 -1
- package/services/kyc/utils/generate-kyc-schema.js +34 -6
- package/services/kyc/utils/generate-kyc-schema.js.map +1 -1
package/lib/certificates.d.ts
CHANGED
|
@@ -2,18 +2,21 @@ 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;
|
|
9
|
+
type AccountKeyAlgorithm = InstanceType<typeof KeetaNetClient.lib.Account>['keyType'];
|
|
10
|
+
/**
|
|
11
|
+
* An alias for the KeetaNetAccount type
|
|
12
|
+
*/
|
|
13
|
+
type KeetaNetAccount = ReturnType<typeof KeetaNetClient.lib.Account.fromSeed<AccountKeyAlgorithm>>;
|
|
5
14
|
type BaseCertificateClass = typeof KeetaNetClient.lib.Utils.Certificate.Certificate;
|
|
6
15
|
type BaseCertificate = InstanceType<BaseCertificateClass>;
|
|
7
16
|
declare const BaseCertificate: BaseCertificateClass;
|
|
8
17
|
type BaseCertificateBuilderClass = typeof KeetaNetClient.lib.Utils.Certificate.CertificateBuilder;
|
|
9
18
|
type BaseCertificateBuilder = InstanceType<BaseCertificateBuilderClass>;
|
|
10
19
|
declare const BaseCertificateBuilder: BaseCertificateBuilderClass;
|
|
11
|
-
type AccountKeyAlgorithm = InstanceType<typeof KeetaNetClient.lib.Account>['keyType'];
|
|
12
|
-
/**
|
|
13
|
-
* An alias for the KeetaNetAccount type
|
|
14
|
-
*/
|
|
15
|
-
type KeetaNetAccount = ReturnType<typeof KeetaNetClient.lib.Account.fromSeed<AccountKeyAlgorithm>>;
|
|
16
|
-
declare const KeetaNetAccount: typeof KeetaNetClient.lib.Account;
|
|
17
20
|
declare function assertCertificateAttributeNames(name: string): asserts name is CertificateAttributeNames;
|
|
18
21
|
declare class SensitiveAttribute<T = ArrayBuffer> {
|
|
19
22
|
#private;
|
|
@@ -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;
|
|
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;AAC/G,OAAO,EAAE,yBAAyB,EAA8B,MAAM,uCAAuC,CAAC;AAY9G;;GAEG;AACH,QAAA,MAAM,eAAe,EAAE,OAAO,cAAc,CAAC,GAAG,CAAC,OAAoC,CAAC;AAGtF,KAAK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
|
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';
|
|
5
4
|
import { arrayBufferLikeToBuffer, arrayBufferToBuffer, Buffer, bufferToArrayBuffer } from './utils/buffer.js';
|
|
6
5
|
import crypto from './utils/crypto.js';
|
|
7
6
|
import { assertNever } from './utils/never.js';
|
|
@@ -15,9 +14,129 @@ import { checkHashWithOID } from './utils/external.js';
|
|
|
15
14
|
* Short alias for printing a debug representation of an object
|
|
16
15
|
*/
|
|
17
16
|
const DPO = KeetaNetClient.lib.Utils.Helper.debugPrintableObject.bind(KeetaNetClient.lib.Utils.Helper);
|
|
17
|
+
/**
|
|
18
|
+
* Short alias for the KeetaNetAccount type
|
|
19
|
+
*/
|
|
20
|
+
const KeetaNetAccount = KeetaNetClient.lib.Account;
|
|
18
21
|
const BaseCertificate = KeetaNetClient.lib.Utils.Certificate.Certificate;
|
|
19
22
|
const BaseCertificateBuilder = KeetaNetClient.lib.Utils.Certificate.CertificateBuilder;
|
|
20
|
-
|
|
23
|
+
function isPlainObject(value) {
|
|
24
|
+
return (typeof value === 'object' && value !== null && !Array.isArray(value));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Recursively normalize object properties
|
|
28
|
+
*/
|
|
29
|
+
function normalizeDecodedASN1Object(obj, principals) {
|
|
30
|
+
const result = {};
|
|
31
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
33
|
+
result[key] = normalizeDecodedASN1(value, principals);
|
|
34
|
+
}
|
|
35
|
+
return (result);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Post-process the output from toJavaScriptObject() to:
|
|
39
|
+
* 1. Unwrap any remaining ASN.1-like objects (from IsAnyString/IsAnyDate)
|
|
40
|
+
* 2. Add domain-specific $blob function to Reference objects
|
|
41
|
+
*/
|
|
42
|
+
function normalizeDecodedASN1(input, principals) {
|
|
43
|
+
// Handle primitives
|
|
44
|
+
if (input === undefined || input === null || typeof input !== 'object') {
|
|
45
|
+
return (input);
|
|
46
|
+
}
|
|
47
|
+
if (input instanceof Date || Buffer.isBuffer(input) || input instanceof ArrayBuffer) {
|
|
48
|
+
return (input);
|
|
49
|
+
}
|
|
50
|
+
// Handle arrays
|
|
51
|
+
if (Array.isArray(input)) {
|
|
52
|
+
return (input.map(item => normalizeDecodedASN1(item, principals)));
|
|
53
|
+
}
|
|
54
|
+
// Unwrap ASN.1-like objects from ambiguous schemas (IsAnyString, IsAnyDate, IsBitString)
|
|
55
|
+
// These are plain objects like { type: 'string', kind: 'utf8', value: 'text' }
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
57
|
+
const obj = input;
|
|
58
|
+
if (obj.type === 'string' && 'value' in obj && typeof obj.value === 'string') {
|
|
59
|
+
return (obj.value);
|
|
60
|
+
}
|
|
61
|
+
if (obj.type === 'date' && 'value' in obj && obj.value instanceof Date) {
|
|
62
|
+
return (obj.value);
|
|
63
|
+
}
|
|
64
|
+
if (obj.type === 'bitstring' && 'value' in obj && Buffer.isBuffer(obj.value)) {
|
|
65
|
+
return (obj.value);
|
|
66
|
+
}
|
|
67
|
+
// Check if this is a Reference object (has external.url and digest fields)
|
|
68
|
+
if ('external' in obj && 'digest' in obj && isPlainObject(obj.external) && isPlainObject(obj.digest)) {
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
70
|
+
const ref = obj;
|
|
71
|
+
const url = ref.external.url;
|
|
72
|
+
const mimeType = ref.external.contentType;
|
|
73
|
+
// After toJavaScriptObject(), OIDs are strings, not {oid: string}
|
|
74
|
+
const encryptionAlgoOID = typeof ref.encryptionAlgorithm === 'string'
|
|
75
|
+
? ref.encryptionAlgorithm
|
|
76
|
+
: ref.encryptionAlgorithm?.oid;
|
|
77
|
+
const digestInfo = ref.digest;
|
|
78
|
+
if (typeof url === 'string' && typeof mimeType === 'string' && digestInfo) {
|
|
79
|
+
let cachedValue = null;
|
|
80
|
+
return ({
|
|
81
|
+
...normalizeDecodedASN1Object(obj, principals),
|
|
82
|
+
$blob: async function (additionalPrincipals) {
|
|
83
|
+
if (cachedValue) {
|
|
84
|
+
return (cachedValue);
|
|
85
|
+
}
|
|
86
|
+
const fetchResult = await fetch(url);
|
|
87
|
+
if (!fetchResult.ok) {
|
|
88
|
+
throw (new Error(`Failed to fetch remote data from ${url}: ${fetchResult.status} ${fetchResult.statusText}`));
|
|
89
|
+
}
|
|
90
|
+
const dataBlob = await fetchResult.blob();
|
|
91
|
+
let data = await dataBlob.arrayBuffer();
|
|
92
|
+
// Handle JSON base64 encoding
|
|
93
|
+
if (dataBlob.type === 'application/json') {
|
|
94
|
+
try {
|
|
95
|
+
const asJSON = JSON.parse(Buffer.from(data).toString('utf-8'));
|
|
96
|
+
if (isPlainObject(asJSON) && Object.keys(asJSON).length === 2) {
|
|
97
|
+
if ('data' in asJSON && typeof asJSON.data === 'string' && 'mimeType' in asJSON && typeof asJSON.mimeType === 'string') {
|
|
98
|
+
data = bufferToArrayBuffer(Buffer.from(asJSON.data, 'base64'));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
/* Ignored */
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Decrypt if needed
|
|
107
|
+
if (encryptionAlgoOID) {
|
|
108
|
+
switch (encryptionAlgoOID) {
|
|
109
|
+
case '1.3.6.1.4.1.62675.2':
|
|
110
|
+
case 'KeetaEncryptedContainerV1': {
|
|
111
|
+
const container = EncryptedContainer.fromEncryptedBuffer(data, [
|
|
112
|
+
...principals,
|
|
113
|
+
...(additionalPrincipals ?? [])
|
|
114
|
+
]);
|
|
115
|
+
data = await container.getPlaintext();
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
default:
|
|
119
|
+
throw (new Error(`Unsupported encryption algorithm OID: ${encryptionAlgoOID}`));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// Verify hash (checkHashWithOID now accepts string OIDs directly)
|
|
123
|
+
if (!Buffer.isBuffer(digestInfo.digest)) {
|
|
124
|
+
throw (new TypeError('Digest value is not a buffer'));
|
|
125
|
+
}
|
|
126
|
+
const validHash = await checkHashWithOID(data, digestInfo);
|
|
127
|
+
if (validHash !== true) {
|
|
128
|
+
throw (validHash);
|
|
129
|
+
}
|
|
130
|
+
const blob = new Blob([data], { type: mimeType });
|
|
131
|
+
cachedValue = blob;
|
|
132
|
+
return (blob);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Recursively process plain objects
|
|
138
|
+
return (normalizeDecodedASN1Object(obj, principals));
|
|
139
|
+
}
|
|
21
140
|
function isBlob(input) {
|
|
22
141
|
if (typeof input !== 'object' || input === null) {
|
|
23
142
|
return (false);
|
|
@@ -137,12 +256,16 @@ function asCertificateAttributeNames(name) {
|
|
|
137
256
|
assertCertificateAttributeNames(name);
|
|
138
257
|
return (name);
|
|
139
258
|
}
|
|
140
|
-
function resolveSchema(name, schema) {
|
|
141
|
-
return (contextualizeStructSchema(schema));
|
|
142
|
-
}
|
|
143
259
|
function encodeAttribute(name, value) {
|
|
144
|
-
const schema =
|
|
145
|
-
|
|
260
|
+
const schema = CertificateAttributeSchema[name];
|
|
261
|
+
let encodedJS;
|
|
262
|
+
try {
|
|
263
|
+
encodedJS = new ASN1.ValidateASN1(schema).fromJavaScriptObject(value);
|
|
264
|
+
}
|
|
265
|
+
catch (err) {
|
|
266
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
267
|
+
throw (new Error(`Attribute ${name}: ${message} (value: ${JSON.stringify(DPO(value))})`));
|
|
268
|
+
}
|
|
146
269
|
if (encodedJS === undefined) {
|
|
147
270
|
throw (new Error(`Unsupported attribute value for encoding: ${JSON.stringify(DPO(value))}`));
|
|
148
271
|
}
|
|
@@ -177,12 +300,70 @@ function encodeForSensitive(name, value) {
|
|
|
177
300
|
}
|
|
178
301
|
return (Buffer.from(String(value), 'utf-8'));
|
|
179
302
|
}
|
|
303
|
+
function unwrapSingleLayer(schema) {
|
|
304
|
+
if (typeof schema === 'object' && schema !== null && 'type' in schema && schema.type === 'context') {
|
|
305
|
+
return (schema.contains);
|
|
306
|
+
}
|
|
307
|
+
return (schema);
|
|
308
|
+
}
|
|
309
|
+
function unwrapFieldSchema(fieldSchema) {
|
|
310
|
+
if (typeof fieldSchema === 'object' && fieldSchema !== null && 'optional' in fieldSchema) {
|
|
311
|
+
const unwrapped = unwrapSingleLayer(fieldSchema.optional);
|
|
312
|
+
return ({ optional: unwrapped });
|
|
313
|
+
}
|
|
314
|
+
return (unwrapSingleLayer(fieldSchema));
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Create a backwards-compatible version of a schema by removing context tag wrappers from struct fields.
|
|
318
|
+
*/
|
|
319
|
+
function unwrapContextTagsFromSchema(schema) {
|
|
320
|
+
// If it's a struct, unwrap context tags from its fields
|
|
321
|
+
if (typeof schema === 'object' && schema !== null && 'type' in schema && schema.type === 'struct') {
|
|
322
|
+
const unwrappedContains = {};
|
|
323
|
+
for (const [fieldName, fieldSchema] of Object.entries(schema.contains)) {
|
|
324
|
+
unwrappedContains[fieldName] = unwrapFieldSchema(fieldSchema);
|
|
325
|
+
}
|
|
326
|
+
return ({
|
|
327
|
+
type: 'struct',
|
|
328
|
+
fieldNames: schema.fieldNames,
|
|
329
|
+
contains: unwrappedContains
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
return (schema);
|
|
333
|
+
}
|
|
180
334
|
async function decodeAttribute(name, value, principals) {
|
|
181
|
-
const schema =
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
335
|
+
const schema = CertificateAttributeSchema[name];
|
|
336
|
+
let decodedASN1;
|
|
337
|
+
let usedSchema = schema;
|
|
338
|
+
try {
|
|
339
|
+
// Try with current schema (includes context tags for structs with optional fields)
|
|
340
|
+
// @ts-expect-error
|
|
341
|
+
decodedASN1 = new ASN1.BufferStorageASN1(value, schema).getASN1();
|
|
342
|
+
}
|
|
343
|
+
catch (firstError) {
|
|
344
|
+
// Fallback: try with backwards-compatible schema (context tags stripped)
|
|
345
|
+
// This supports old certificates encoded before context tags were added
|
|
346
|
+
try {
|
|
347
|
+
const backwardsCompatSchema = unwrapContextTagsFromSchema(schema);
|
|
348
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
349
|
+
decodedASN1 = new ASN1.BufferStorageASN1(value, backwardsCompatSchema).getASN1();
|
|
350
|
+
usedSchema = backwardsCompatSchema;
|
|
351
|
+
}
|
|
352
|
+
catch {
|
|
353
|
+
// If both fail, throw the original error
|
|
354
|
+
throw (firstError);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
if (!decodedASN1) {
|
|
358
|
+
throw (new Error('Failed to decode ASN1 data'));
|
|
359
|
+
}
|
|
360
|
+
const validator = new ASN1.ValidateASN1(usedSchema);
|
|
361
|
+
const plainObject = validator.toJavaScriptObject(decodedASN1);
|
|
362
|
+
// Post-process to:
|
|
363
|
+
// 1. Unwrap any remaining ASN.1-like objects
|
|
364
|
+
// 2. Add domain-specific $blob function to Reference objects
|
|
365
|
+
// @ts-expect-error
|
|
366
|
+
const candidate = normalizeDecodedASN1(plainObject, principals);
|
|
186
367
|
return (asAttributeValue(name, candidate));
|
|
187
368
|
}
|
|
188
369
|
class SensitiveAttributeBuilder {
|
|
@@ -283,7 +464,7 @@ class SensitiveAttribute {
|
|
|
283
464
|
decodedAttribute = dataObject.getASN1();
|
|
284
465
|
}
|
|
285
466
|
catch {
|
|
286
|
-
const js = ASN1toJS(data);
|
|
467
|
+
const js = ASN1.ASN1toJS(data);
|
|
287
468
|
throw (new Error(`SensitiveAttribute.decode: unexpected DER shape ${JSON.stringify(DPO(js))}`));
|
|
288
469
|
}
|
|
289
470
|
const decodedVersion = decodedAttribute[0] + 1n;
|
|
@@ -782,8 +963,15 @@ export class SharableCertificateAttributes {
|
|
|
782
963
|
}
|
|
783
964
|
}));
|
|
784
965
|
};
|
|
785
|
-
|
|
786
|
-
|
|
966
|
+
/*
|
|
967
|
+
* Decode the attribute value to extract $blob references.
|
|
968
|
+
* Skip for entityType which has schema compatibility issues
|
|
969
|
+
* with old certificates and has no external references anyway.
|
|
970
|
+
*/
|
|
971
|
+
if (name !== 'entityType') {
|
|
972
|
+
const attrValue = await certificate.getAttributeValue(name);
|
|
973
|
+
await walkResultAndReplaceReferences(attrValue);
|
|
974
|
+
}
|
|
787
975
|
if (attr.sensitive) {
|
|
788
976
|
attributes[name] = {
|
|
789
977
|
sensitive: true,
|
|
@@ -1038,6 +1226,15 @@ Certificate.SharableAttributes = SharableCertificateAttributes;
|
|
|
1038
1226
|
/** @internal */
|
|
1039
1227
|
export const _Testing = {
|
|
1040
1228
|
SensitiveAttributeBuilder,
|
|
1041
|
-
SensitiveAttribute
|
|
1229
|
+
SensitiveAttribute,
|
|
1230
|
+
ValidateASN1: ASN1.ValidateASN1,
|
|
1231
|
+
BufferStorageASN1: ASN1.BufferStorageASN1,
|
|
1232
|
+
JStoASN1: ASN1.JStoASN1,
|
|
1233
|
+
normalizeDecodedASN1,
|
|
1234
|
+
decodeAttribute,
|
|
1235
|
+
unwrapSingleLayer,
|
|
1236
|
+
unwrapFieldSchema,
|
|
1237
|
+
unwrapContextTagsFromSchema,
|
|
1238
|
+
CertificateAttributeSchema
|
|
1042
1239
|
};
|
|
1043
1240
|
//# sourceMappingURL=certificates.js.map
|