@keetanetwork/anchor 0.0.24 → 0.0.25
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 +1 -4
- package/lib/certificates.d.ts.map +1 -1
- package/lib/certificates.js +14 -148
- package/lib/certificates.js.map +1 -1
- package/lib/utils/asn1.d.ts +13 -0
- package/lib/utils/asn1.d.ts.map +1 -1
- package/lib/utils/asn1.js +1973 -0
- package/lib/utils/asn1.js.map +1 -1
- package/lib/utils/external.d.ts.map +1 -1
- package/lib/utils/external.js +2 -9
- package/lib/utils/external.js.map +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +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 +6 -34
- package/services/kyc/utils/generate-kyc-schema.js.map +1 -1
package/lib/certificates.d.ts
CHANGED
|
@@ -2,15 +2,12 @@ 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
5
|
type AccountKeyAlgorithm = InstanceType<typeof KeetaNetClient.lib.Account>['keyType'];
|
|
10
6
|
/**
|
|
11
7
|
* An alias for the KeetaNetAccount type
|
|
12
8
|
*/
|
|
13
9
|
type KeetaNetAccount = ReturnType<typeof KeetaNetClient.lib.Account.fromSeed<AccountKeyAlgorithm>>;
|
|
10
|
+
declare const KeetaNetAccount: typeof KeetaNetClient.lib.Account;
|
|
14
11
|
declare function assertCertificateAttributeNames(name: string): asserts name is CertificateAttributeNames;
|
|
15
12
|
declare class SensitiveAttribute<T = ArrayBuffer> {
|
|
16
13
|
#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;AAKhE,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;AAa9G,KAAK,mBAAmB,GAAG,YAAY,CAAC,OAAO,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC;AAEtF;;GAEG;AACH,KAAK,eAAe,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC,CAAC;AACnG,QAAA,MAAM,eAAe,EAAE,OAAO,cAAc,CAAC,GAAG,CAAC,OAAoC,CAAC;AA0JtF,iBAAS,+BAA+B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,IAAI,yBAAyB,CAIhG;AAqJD,cAAM,kBAAkB,CAAC,CAAC,GAAG,WAAW;;gBAK3B,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,WAAW,EAAE,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,KAAK,CAAC;IAQ7G,OAAO,CAAC,MAAM;IAqEd;;;;;;;;OAQG;IACG,GAAG,IAAI,OAAO,CAAC,WAAW,CAAC;IAK3B,QAAQ,IAAI,OAAO,CAAC,CAAC,CAAC;IAiB5B;;;;OAI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O,EAAE,IAAI,CAAC,0CAA0C,EAAE,QAAQ,CAAC,GAAG;QAAE,MAAM,EAAE,QAAQ,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IACnH,MAAM,CAAC,OAAO,CAAC,EAAE,0CAA0C,GAAG,OAAO,CAAC,WAAW,GAAG,MAAM,CAAC;CA8B3F"}
|
package/lib/certificates.js
CHANGED
|
@@ -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,7 @@ 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
|
-
*/
|
|
20
18
|
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
19
|
function isBlob(input) {
|
|
139
20
|
if (typeof input !== 'object' || input === null) {
|
|
140
21
|
return (false);
|
|
@@ -254,16 +135,12 @@ function asCertificateAttributeNames(name) {
|
|
|
254
135
|
assertCertificateAttributeNames(name);
|
|
255
136
|
return (name);
|
|
256
137
|
}
|
|
138
|
+
function resolveSchema(name, schema) {
|
|
139
|
+
return (contextualizeStructSchema(schema));
|
|
140
|
+
}
|
|
257
141
|
function encodeAttribute(name, value) {
|
|
258
|
-
const schema = CertificateAttributeSchema[name];
|
|
259
|
-
|
|
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
|
-
}
|
|
142
|
+
const schema = resolveSchema(name, CertificateAttributeSchema[name]);
|
|
143
|
+
const encodedJS = encodeValueBySchema(schema, value, { attributeName: name });
|
|
267
144
|
if (encodedJS === undefined) {
|
|
268
145
|
throw (new Error(`Unsupported attribute value for encoding: ${JSON.stringify(DPO(value))}`));
|
|
269
146
|
}
|
|
@@ -299,18 +176,11 @@ function encodeForSensitive(name, value) {
|
|
|
299
176
|
return (Buffer.from(String(value), 'utf-8'));
|
|
300
177
|
}
|
|
301
178
|
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);
|
|
305
|
-
// 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
|
|
179
|
+
const schema = resolveSchema(name, CertificateAttributeSchema[name]);
|
|
311
180
|
// XXX:TODO Fix depth issue
|
|
312
|
-
// @ts-
|
|
313
|
-
const
|
|
181
|
+
// @ts-ignore
|
|
182
|
+
const decodedUnknown = new ASN1.BufferStorageASN1(value, schema).getASN1();
|
|
183
|
+
const candidate = normalizeDecodedASN1(decodedUnknown, principals);
|
|
314
184
|
return (asAttributeValue(name, candidate));
|
|
315
185
|
}
|
|
316
186
|
class SensitiveAttributeBuilder {
|
|
@@ -411,7 +281,7 @@ class SensitiveAttribute {
|
|
|
411
281
|
decodedAttribute = dataObject.getASN1();
|
|
412
282
|
}
|
|
413
283
|
catch {
|
|
414
|
-
const js =
|
|
284
|
+
const js = ASN1toJS(data);
|
|
415
285
|
throw (new Error(`SensitiveAttribute.decode: unexpected DER shape ${JSON.stringify(DPO(js))}`));
|
|
416
286
|
}
|
|
417
287
|
const decodedVersion = decodedAttribute[0] + 1n;
|
|
@@ -694,7 +564,7 @@ export class Certificate extends KeetaNetClient.lib.Utils.Certificate.Certificat
|
|
|
694
564
|
/* Do nothing, we call the super method in the constructor */
|
|
695
565
|
}
|
|
696
566
|
setPlainAttribute(name, value) {
|
|
697
|
-
// @ts-
|
|
567
|
+
// @ts-ignore
|
|
698
568
|
this.attributes[name] = { sensitive: false, value };
|
|
699
569
|
}
|
|
700
570
|
setSensitiveAttribute(name, value) {
|
|
@@ -1053,7 +923,7 @@ export class SharableCertificateAttributes {
|
|
|
1053
923
|
throw (new Error(`Missing reference value for ID ${referenceID}`));
|
|
1054
924
|
}
|
|
1055
925
|
const referenceData = Buffer.from(referenceValue, 'base64');
|
|
1056
|
-
const referenceDataAB =
|
|
926
|
+
const referenceDataAB = arrayBufferToBuffer(referenceData);
|
|
1057
927
|
/* Verify the hash matches what was certified */
|
|
1058
928
|
const checkHash = await checkHashWithOID(referenceData, parent.digest);
|
|
1059
929
|
if (checkHash !== true) {
|
|
@@ -1117,10 +987,6 @@ Certificate.SharableAttributes = SharableCertificateAttributes;
|
|
|
1117
987
|
/** @internal */
|
|
1118
988
|
export const _Testing = {
|
|
1119
989
|
SensitiveAttributeBuilder,
|
|
1120
|
-
SensitiveAttribute
|
|
1121
|
-
ValidateASN1: ASN1.ValidateASN1,
|
|
1122
|
-
BufferStorageASN1: ASN1.BufferStorageASN1,
|
|
1123
|
-
JStoASN1: ASN1.JStoASN1,
|
|
1124
|
-
normalizeDecodedASN1
|
|
990
|
+
SensitiveAttribute
|
|
1125
991
|
};
|
|
1126
992
|
//# sourceMappingURL=certificates.js.map
|