@keetanetwork/anchor 0.0.82 → 0.0.84
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/anchor-metadata-server.js +1 -1
- package/lib/anchor-metadata-server.js.map +1 -1
- package/lib/anchor-status.d.ts +32 -1
- package/lib/anchor-status.d.ts.map +1 -1
- package/lib/anchor-status.js +62 -1
- package/lib/anchor-status.js.map +1 -1
- package/lib/asset.d.ts +3 -0
- package/lib/asset.d.ts.map +1 -1
- package/lib/asset.js +25 -1
- package/lib/asset.js.map +1 -1
- package/lib/chaining.d.ts.map +1 -1
- package/lib/chaining.js +48 -44
- package/lib/chaining.js.map +1 -1
- package/lib/encrypted-container.d.ts.map +1 -1
- package/lib/encrypted-container.js +22 -7
- package/lib/encrypted-container.js.map +1 -1
- package/lib/history.d.ts +77 -21
- package/lib/history.d.ts.map +1 -1
- package/lib/history.js +951 -70
- package/lib/history.js.map +1 -1
- package/lib/http-server/index.d.ts.map +1 -1
- package/lib/http-server/index.js +20 -1
- package/lib/http-server/index.js.map +1 -1
- package/lib/index.d.ts +4 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/resolver.d.ts.map +1 -1
- package/lib/resolver.js +18 -2
- package/lib/resolver.js.map +1 -1
- package/lib/sensitive-attribute.d.ts.map +1 -1
- package/lib/sensitive-attribute.js +24 -2
- package/lib/sensitive-attribute.js.map +1 -1
- package/npm-shrinkwrap.json +18 -6
- package/package.json +2 -1
- package/services/fx/client.d.ts +18 -4
- package/services/fx/client.d.ts.map +1 -1
- package/services/fx/client.js +52 -6
- package/services/fx/client.js.map +1 -1
- package/services/fx/common.d.ts +35 -0
- package/services/fx/common.d.ts.map +1 -1
- package/services/fx/common.js +5 -5
- package/services/fx/common.js.map +1 -1
- package/services/fx/server.d.ts +17 -1
- package/services/fx/server.d.ts.map +1 -1
- package/services/fx/server.js +236 -18
- package/services/fx/server.js.map +1 -1
- package/services/fx/status-source.d.ts +34 -0
- package/services/fx/status-source.d.ts.map +1 -0
- package/services/fx/status-source.js +99 -0
- package/services/fx/status-source.js.map +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sensitive-attribute.d.ts","sourceRoot":"","sources":["../../src/lib/sensitive-attribute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,cAAc,MAAM,+BAA+B,CAAC;AAGhE,OAAO,EAAgD,MAAM,EAAuB,MAAM,mBAAmB,CAAC;AAE9G,OAAO,KAAK,EAAE,sBAAsB,EAAE,yBAAyB,EAAG,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AAU3I,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;AAEnG;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,MAAM,OAAO,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"sensitive-attribute.d.ts","sourceRoot":"","sources":["../../src/lib/sensitive-attribute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,cAAc,MAAM,+BAA+B,CAAC;AAGhE,OAAO,EAAgD,MAAM,EAAuB,MAAM,mBAAmB,CAAC;AAE9G,OAAO,KAAK,EAAE,sBAAsB,EAAE,yBAAyB,EAAG,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AAU3I,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,CAA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M;IA6Dd;;;;;;;;OAQG;IACG,GAAG,IAAI,OAAO,CAAC,WAAW,CAAC;IAK3B,QAAQ,IAAI,OAAO,CAAC,CAAC,CAAC;IAiB5B;;;;OAIG;IACG,QAAQ,IAAI,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAA;KAAC,CAAC;IAYnE;;OAEG;IACG,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAcnF,MAAM,IAAI,sBAAsB;IAKhC;;OAEG;WACU,MAAM,CAAC,CAAC,SAAS,yBAAyB,EACtD,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,yBAAyB,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,WAAW,GACxD,OAAO,CAAC,kBAAkB,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC,CAAC;CAoE5D"}
|
|
@@ -60,6 +60,28 @@ const sensitiveAttributeOIDDB = {
|
|
|
60
60
|
'aes256-gcm': oids.AES_256_GCM,
|
|
61
61
|
'aes256-cbc': oids.AES_256_CBC
|
|
62
62
|
};
|
|
63
|
+
/**
|
|
64
|
+
* Rewrite every `Date`, at any depth, as an explicit GeneralizedTime value.
|
|
65
|
+
*/
|
|
66
|
+
function preferGeneralizedDates(value) {
|
|
67
|
+
if (value instanceof Date) {
|
|
68
|
+
return ({ type: 'date', kind: 'general', date: value });
|
|
69
|
+
}
|
|
70
|
+
if (Buffer.isBuffer(value) || value instanceof ArrayBuffer) {
|
|
71
|
+
return (value);
|
|
72
|
+
}
|
|
73
|
+
if (Array.isArray(value)) {
|
|
74
|
+
return (value.map(preferGeneralizedDates));
|
|
75
|
+
}
|
|
76
|
+
if (value !== null && typeof value === 'object') {
|
|
77
|
+
const rewritten = {};
|
|
78
|
+
for (const [key, nested] of Object.entries(value)) {
|
|
79
|
+
rewritten[key] = preferGeneralizedDates(nested);
|
|
80
|
+
}
|
|
81
|
+
return (rewritten);
|
|
82
|
+
}
|
|
83
|
+
return (value);
|
|
84
|
+
}
|
|
63
85
|
/**
|
|
64
86
|
* Encode an attribute value using its ASN.1 schema
|
|
65
87
|
*/
|
|
@@ -67,7 +89,7 @@ export function encodeAttribute(name, value) {
|
|
|
67
89
|
const schema = CertificateAttributeSchema[name];
|
|
68
90
|
let encodedJS;
|
|
69
91
|
try {
|
|
70
|
-
encodedJS = new ASN1.ValidateASN1(schema).fromJavaScriptObject(value);
|
|
92
|
+
encodedJS = new ASN1.ValidateASN1(schema).fromJavaScriptObject(preferGeneralizedDates(value));
|
|
71
93
|
}
|
|
72
94
|
catch (err) {
|
|
73
95
|
const message = err instanceof Error ? err.message : String(err);
|
|
@@ -197,7 +219,7 @@ function setGCMAuthTag(decipher, tag) {
|
|
|
197
219
|
*
|
|
198
220
|
* @internal
|
|
199
221
|
*/
|
|
200
|
-
function decodeForSensitive(name, data) {
|
|
222
|
+
export function decodeForSensitive(name, data) {
|
|
201
223
|
const buffer = Buffer.isBuffer(data) ? bufferToArrayBuffer(data) : data;
|
|
202
224
|
const schema = CertificateAttributeSchema[name];
|
|
203
225
|
const plainObject = decodeWithSchema(buffer, schema);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sensitive-attribute.js","sourceRoot":"","sources":["../../src/lib/sensitive-attribute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,cAAc,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,IAAI,MAAM,mCAAmC,CAAC;AAC1D,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC9G,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,EAAE,0BAA0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AAoB;YACpB;gBACC,eAAe;gBACf,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,EAAE;gBAC7D,iBAAiB;gBACjB,KAAK;gBACL,iEAAiE;gBACjE,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC;aACzB;YACD,kBAAkB;YAClB;gBACC,oBAAoB;gBACpB,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC;gBAC1B,uBAAuB;gBACvB,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,CAAC,gBAAgB,EAAE,uBAAuB,CAAC,EAAE;gBACvE,yDAAyD;gBACzD,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC;aACjC;YACD,sDAAsD;YACtD,cAAc;SACd,CAAC;QAEF,MAAM,sBAAsB,GAAG,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;QACjE,MAAM,YAAY,GAAG,sBAAsB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAEzD,MAAM,OAAO,GAAG,UAAS,IAA0B;YAClD,yEAAyE;YACzE,OAAO,kBAAkB,CAAC,IAAI,EAAE,IAAI,CAAkC,CAAC;QACxE,CAAC,CAAC;QAEF,MAAM,MAAM,GAAG,IAAI,kBAAkB,CAA+B,OAAO,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;QACpG,OAAM,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC","sourcesContent":["import * as KeetaNetClient from '@keetanetwork/keetanet-client';\nimport * as oids from '../services/kyc/oids.generated.js';\nimport * as ASN1 from './utils/asn1.js';\nimport { arrayBufferLikeToBuffer, arrayBufferToBuffer, Buffer, bufferToArrayBuffer } from './utils/buffer.js';\nimport crypto from './utils/crypto.js';\nimport type { SensitiveAttributeType, CertificateAttributeValue , CertificateAttributeOIDDB } from '../services/kyc/iso20022.generated.js';\nimport { CertificateAttributeSchema } from '../services/kyc/iso20022.generated.js';\nimport { getOID, lookupByOID } from './utils/oid.js';\n\n/**\n * Short alias for printing a debug representation of an object\n */\nconst DPO = KeetaNetClient.lib.Utils.Helper.debugPrintableObject.bind(KeetaNetClient.lib.Utils.Helper);\n\n/* ENUM */\ntype AccountKeyAlgorithm = InstanceType<typeof KeetaNetClient.lib.Account>['keyType'];\n\n/**\n * An alias for the KeetaNetAccount type\n */\ntype KeetaNetAccount = ReturnType<typeof KeetaNetClient.lib.Account.fromSeed<AccountKeyAlgorithm>>;\n\n/**\n * Type for certificate attribute names (derived from generated OID database)\n */\nexport type CertificateAttributeNames = keyof typeof CertificateAttributeOIDDB;\n\n/**\n * Sensitive Attribute Schema\n *\n * ASN.1 Schema:\n * SensitiveAttributes DEFINITIONS ::= BEGIN\n * SensitiveAttribute ::= SEQUENCE {\n * version INTEGER { v1(0) },\n * cipher SEQUENCE {\n * algorithm OBJECT IDENTIFIER,\n * ivOrNonce OCTET STRING,\n * key OCTET STRING\n * },\n * hashedValue SEQUENCE {\n * encryptedSalt OCTET STRING,\n * algorithm OBJECT IDENTIFIER,\n * value OCTET STRING\n * },\n * encryptedValue OCTET STRING\n * }\n * END\n *\n * https://keeta.notion.site/Keeta-KYC-Certificate-Extensions-13e5da848e588042bdcef81fc40458b7\n *\n * @internal\n */\nconst SensitiveAttributeSchemaInternal: [\n\tversion: 0n,\n\tcipher: [\n\t\talgorithm: typeof ASN1.ValidateASN1.IsOID,\n\t\tiv: typeof ASN1.ValidateASN1.IsOctetString,\n\t\tkey: typeof ASN1.ValidateASN1.IsOctetString\n\t],\n\thashedValue: [\n\t\tencryptedSalt: typeof ASN1.ValidateASN1.IsOctetString,\n\t\talgorithm: typeof ASN1.ValidateASN1.IsOID,\n\t\tvalue: typeof ASN1.ValidateASN1.IsOctetString\n\t],\n\tencryptedValue: typeof ASN1.ValidateASN1.IsOctetString\n] = [\n\t0n,\n\t[\n\t\tASN1.ValidateASN1.IsOID,\n\t\tASN1.ValidateASN1.IsOctetString,\n\t\tASN1.ValidateASN1.IsOctetString\n\t],\n\t[\n\t\tASN1.ValidateASN1.IsOctetString,\n\t\tASN1.ValidateASN1.IsOID,\n\t\tASN1.ValidateASN1.IsOctetString\n\t],\n\tASN1.ValidateASN1.IsOctetString\n];\n\n/**\n * The Sensitive Attribute Schema Internal\n *\n * @internal\n */\ntype SensitiveAttributeSchema = ASN1.SchemaMap<typeof SensitiveAttributeSchemaInternal>;\n\n/*\n * Database of permitted algorithms and their OIDs\n */\nconst sensitiveAttributeOIDDB = {\n\t'aes-256-gcm': oids.AES_256_GCM,\n\t'aes-256-cbc': oids.AES_256_CBC,\n\t'sha2-256': oids.SHA2_256,\n\t'sha3-256': oids.SHA3_256,\n\t'sha256': oids.SHA2_256,\n\t'aes256-gcm': oids.AES_256_GCM,\n\t'aes256-cbc': oids.AES_256_CBC\n};\n\n/**\n * Encode an attribute value using its ASN.1 schema\n */\nexport function encodeAttribute(name: CertificateAttributeNames, value: unknown): ArrayBuffer {\n\tconst schema = CertificateAttributeSchema[name];\n\n\tlet encodedJS;\n\ttry {\n\t\tencodedJS = new ASN1.ValidateASN1(schema).fromJavaScriptObject(value);\n\t} catch (err) {\n\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\tthrow(new Error(`Attribute ${name}: ${message} (value: ${JSON.stringify(DPO(value))})`));\n\t}\n\n\tif (encodedJS === undefined) {\n\t\tthrow(new Error(`Unsupported attribute value for encoding: ${JSON.stringify(DPO(value))}`));\n\t}\n\n\tconst asn1Object = ASN1.JStoASN1(encodedJS);\n\tif (!asn1Object) {\n\t\tthrow(new Error(`Failed to encode value for attribute ${name}`));\n\t}\n\n\treturn(asn1Object.toBER(false));\n}\n\n/**\n * Prepare a value for inclusion in a SensitiveAttribute: pre-encode complex and date types\n */\nexport function encodeForSensitive(\n\tname: CertificateAttributeNames | undefined,\n\tvalue: SensitiveAttributeType | Buffer | ArrayBuffer\n): Buffer {\n\tif (Buffer.isBuffer(value)) { return(value); }\n\tif (value instanceof ArrayBuffer) { return(arrayBufferToBuffer(value)); }\n\tif (typeof value === 'string') {\n\t\tconst asn1 = ASN1.JStoASN1({ type: 'string', kind: 'utf8', value });\n\t\treturn(arrayBufferToBuffer(asn1.toBER(false)));\n\t}\n\n\tif (value instanceof Date) {\n\t\tconst asn1 = ASN1.JStoASN1({ type: 'date', kind: 'general', date: value });\n\t\treturn(arrayBufferToBuffer(asn1.toBER(false)));\n\t}\n\n\tif (typeof value === 'object' && value !== null) {\n\t\tif (!name) { throw(new Error('attributeName required for complex types')); }\n\t\tconst encoded = encodeAttribute(name, value);\n\t\treturn(arrayBufferToBuffer(encoded));\n\t}\n\n\treturn(Buffer.from(String(value), 'utf-8'));\n}\n\n/**\n * Check if value is an ASN.1-like wrapper object\n */\nfunction isASN1Wrapper(obj: object): obj is { type: string; value: unknown } {\n\treturn('type' in obj && 'value' in obj && typeof obj.type === 'string');\n}\n\n/**\n * Normalize the result (unwrap ASN.1-like objects)\n */\nfunction normalizeDecodedValue(input: unknown): unknown {\n\tif (input === undefined || input === null || typeof input !== 'object') {\n\t\treturn(input);\n\t}\n\tif (input instanceof Date || Buffer.isBuffer(input) || input instanceof ArrayBuffer) {\n\t\treturn(input);\n\t}\n\tif (Array.isArray(input)) {\n\t\treturn(input.map(item => normalizeDecodedValue(item)));\n\t}\n\t// Unwrap ASN.1-like objects\n\tif (isASN1Wrapper(input)) {\n\t\tif (input.type === 'string' && typeof input.value === 'string') {\n\t\t\treturn(input.value);\n\t\t}\n\t\tif (input.type === 'date' && input.value instanceof Date) {\n\t\t\treturn(input.value);\n\t\t}\n\t}\n\t// Recursively normalize object properties\n\tconst result: { [key: string]: unknown } = {};\n\tfor (const [key, value] of Object.entries(input)) {\n\t\tresult[key] = normalizeDecodedValue(value);\n\t}\n\treturn(result);\n}\n\n/**\n * Decode ASN.1 data using a schema\n *\n * Note: The ASN1 library uses dynamic typing internally, so we consolidate\n * the unsafe operations here rather than scattering them throughout the code.\n */\nfunction decodeWithSchema(buffer: ArrayBuffer, schema: unknown): unknown {\n\t/* eslint-disable\n @typescript-eslint/no-explicit-any,\n @typescript-eslint/consistent-type-assertions,\n\t\t@typescript-eslint/no-unsafe-member-access,\n @typescript-eslint/no-unsafe-call,\n\t\t@typescript-eslint/no-unsafe-assignment\n */\n\tlet decodedASN1: ASN1.ASN1AnyJS | undefined;\n\ttry {\n\t\tdecodedASN1 = new (ASN1.BufferStorageASN1 as any)(buffer, schema).getASN1() as ASN1.ASN1AnyJS;\n\t} catch {\n\t\tdecodedASN1 = ASN1.ASN1toJS(buffer);\n\t}\n\tif (decodedASN1 === undefined) {\n\t\tthrow(new Error('Failed to decode ASN1 data'));\n\t}\n\n\tconst validator = new (ASN1.ValidateASN1 as any)(schema);\n\treturn(validator.toJavaScriptObject(decodedASN1));\n\t/* eslint-enable */\n}\n\n/**\n * GCM cipher helpers - Node's crypto types don't properly type getAuthTag/setAuthTag\n * when using createCipheriv/createDecipheriv, so we use typed wrappers.\n */\n/* eslint-disable @typescript-eslint/consistent-type-assertions -- Reflect.get returns unknown */\nfunction getGCMAuthTag(cipher: ReturnType<typeof crypto.createCipheriv>): Buffer {\n\tconst getAuthTag = Reflect.get(cipher, 'getAuthTag') as (() => Buffer) | undefined;\n\tif (typeof getAuthTag !== 'function') {\n\t\tthrow(new TypeError('getAuthTag is not available on cipher'));\n\t}\n\treturn(getAuthTag.call(cipher));\n}\n\nfunction setGCMAuthTag(decipher: ReturnType<typeof crypto.createDecipheriv>, tag: Buffer): void {\n\tconst setAuthTag = Reflect.get(decipher, 'setAuthTag') as ((tag: Buffer) => void) | undefined;\n\tif (typeof setAuthTag !== 'function') {\n\t\tthrow(new TypeError('setAuthTag is not available on decipher'));\n\t}\n\tsetAuthTag.call(decipher, tag);\n}\n/* eslint-enable @typescript-eslint/consistent-type-assertions */\n\n/**\n * Decode a value from its ASN.1 representation back to the original type\n *\n * @internal\n */\nfunction decodeForSensitive(\n\tname: CertificateAttributeNames,\n\tdata: Buffer | ArrayBuffer\n): unknown {\n\tconst buffer = Buffer.isBuffer(data) ? bufferToArrayBuffer(data) : data;\n\tconst schema: unknown = CertificateAttributeSchema[name];\n\tconst plainObject = decodeWithSchema(buffer, schema);\n\treturn(normalizeDecodedValue(plainObject));\n}\n\nexport type SensitiveAttributeJSON = {\n\tversion: string;\n\tpublicKey: string;\n\tcipher: {\n\t\talgorithm: string;\n\t\tiv: string;\n\t\tkey: string;\n\t};\n\thashedValue: {\n\t\tencryptedSalt: string;\n\t\talgorithm: string;\n\t\tvalue: string;\n\t};\n\tencryptedValue: string;\n};\n\nexport class SensitiveAttribute<T = ArrayBuffer> {\n\tprivate static readonly SensitiveAttributeObjectTypeID = 'c0cc9591-cebb-4441-babe-23739279e3f2';\n\tprivate readonly SensitiveAttributeObjectTypeID!: string;\n\n\treadonly #account: KeetaNetAccount;\n\treadonly #encryptedDER: ArrayBuffer;\n\treadonly #info: ReturnType<SensitiveAttribute<T>['decode']>;\n\treadonly #decoder?: (data: Buffer | ArrayBuffer) => T | Promise<T>;\n\n\tconstructor(\n\t\taccount: KeetaNetAccount,\n\t\tdata: Buffer | ArrayBuffer,\n\t\tdecoder?: (data: Buffer | ArrayBuffer) => T | Promise<T>\n\t) {\n\t\tObject.defineProperty(this, 'SensitiveAttributeObjectTypeID', {\n\t\t\tvalue: SensitiveAttribute.SensitiveAttributeObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\n\t\tthis.#account = account;\n\t\tthis.#encryptedDER = Buffer.isBuffer(data) ? bufferToArrayBuffer(data) : data;\n\t\tthis.#info = this.decode(data);\n\t\tif (decoder) {\n\t\t\tthis.#decoder = decoder;\n\t\t}\n\t}\n\n\t/**\n\t * Check if a value is a SensitiveAttribute instance\n\t */\n\tstatic isInstance(input: unknown): input is SensitiveAttribute<unknown> {\n\t\tif (typeof input !== 'object' || input === null) {\n\t\t\treturn(false);\n\t\t}\n\n\t\treturn(Reflect.get(input, 'SensitiveAttributeObjectTypeID') === SensitiveAttribute.SensitiveAttributeObjectTypeID);\n\t}\n\n\t/**\n\t * Get the public key this attribute was encrypted for\n\t */\n\tget publicKey(): string {\n\t\treturn(this.#account.publicKeyString.get());\n\t}\n\n\t/**\n\t * Get the raw encrypted DER for certificate embedding\n\t */\n\ttoDER(): ArrayBuffer {\n\t\treturn(this.#encryptedDER);\n\t}\n\n\tprivate decode(data: Buffer | ArrayBuffer) {\n\t\tif (Buffer.isBuffer(data)) {\n\t\t\tdata = bufferToArrayBuffer(data);\n\t\t}\n\n\t\tlet decodedAttribute;\n\t\ttry {\n\t\t\tconst dataObject = new ASN1.BufferStorageASN1(data, SensitiveAttributeSchemaInternal);\n\t\t\tdecodedAttribute = dataObject.getASN1();\n\t\t} catch {\n\t\t\tconst js = ASN1.ASN1toJS(data);\n\t\t\tthrow(new Error(`SensitiveAttribute.decode: unexpected DER shape ${JSON.stringify(DPO(js))}`));\n\t\t}\n\n\t\tconst decodedVersion = decodedAttribute[0] + 1n;\n\t\tif (decodedVersion !== 1n) {\n\t\t\tthrow(new Error(`Unsupported Sensitive Attribute version (${decodedVersion})`));\n\t\t}\n\n\t\treturn({\n\t\t\tversion: decodedVersion,\n\t\t\tpublicKey: this.#account.publicKeyString.get(),\n\t\t\tcipher: {\n\t\t\t\talgorithm: lookupByOID(decodedAttribute[1][0].oid, sensitiveAttributeOIDDB),\n\t\t\t\tiv: decodedAttribute[1][1],\n\t\t\t\tkey: decodedAttribute[1][2]\n\t\t\t},\n\t\t\thashedValue: {\n\t\t\t\tencryptedSalt: decodedAttribute[2][0],\n\t\t\t\talgorithm: lookupByOID(decodedAttribute[2][1].oid, sensitiveAttributeOIDDB),\n\t\t\t\tvalue: decodedAttribute[2][2]\n\t\t\t},\n\t\t\tencryptedValue: decodedAttribute[3]\n\t\t});\n\t}\n\n\tasync #decryptValue(value: Buffer) {\n\t\tconst decryptedKey = await this.#account.decrypt(bufferToArrayBuffer(this.#info.cipher.key));\n\t\tconst algorithm = this.#info.cipher.algorithm;\n\t\tconst iv = this.#info.cipher.iv;\n\n\t\tconst decipher = crypto.createDecipheriv(algorithm, Buffer.from(decryptedKey), iv);\n\n\t\t// For AES-GCM, extract and set the 16-byte authentication tag\n\t\tif (algorithm === 'aes-256-gcm') {\n\t\t\tconst authTag = value.subarray(-16);\n\t\t\tconst ciphertext = value.subarray(0, -16);\n\n\t\t\tsetGCMAuthTag(decipher, authTag);\n\n\t\t\tconst decrypted = decipher.update(ciphertext);\n\t\t\tdecipher.final(); // Verify auth tag\n\t\t\treturn(decrypted);\n\t\t}\n\n\t\t// For other algorithms (like CBC), just decrypt normally\n\t\tconst decrypted = decipher.update(value);\n\t\tdecipher.final();\n\t\treturn(decrypted);\n\t}\n\n\t/**\n\t * Get the value of the sensitive attribute\n\t *\n\t * This will decrypt the value using the account's private key\n\t * and return the value as an ArrayBuffer\n\t *\n\t * Since sensitive attributes are binary blobs, this returns an\n\t * ArrayBuffer\n\t */\n\tasync get(): Promise<ArrayBuffer> {\n\t\tconst decryptedValue = await this.#decryptValue(arrayBufferLikeToBuffer(this.#info.encryptedValue));\n\t\treturn(bufferToArrayBuffer(decryptedValue));\n\t}\n\n\tasync getValue(): Promise<T> {\n\t\tconst value = await this.get();\n\t\tif (!this.#decoder) {\n\t\t\t/**\n\t\t\t * TypeScript complains that T may not be the correct\n\t\t\t * type here, but gives us no tools to enforce that it\n\t\t\t * is -- it should always be ArrayBuffer if no decoder\n\t\t\t * is provided, but someone could always specify a\n\t\t\t * type parameter in that case and we cannot check\n\t\t\t * that at runtime since T is only a compile-time type.\n\t\t\t */\n\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\treturn(value as unknown as T);\n\t\t}\n\t\treturn(await this.#decoder(value));\n\t}\n\n\t/**\n\t * Generate a proof that a sensitive attribute is a given value,\n\t * which can be validated by a third party using the certificate\n\t * and the `validateProof` method\n\t */\n\tasync getProof(): Promise<{ value: string; hash: { salt: string }}> {\n\t\tconst value = await this.get();\n\t\tconst salt = await this.#decryptValue(arrayBufferLikeToBuffer(this.#info.hashedValue.encryptedSalt));\n\n\t\treturn({\n\t\t\tvalue: Buffer.from(value).toString('base64'),\n\t\t\thash: {\n\t\t\t\tsalt: salt.toString('base64')\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Validate the proof that a sensitive attribute is a given value\n\t */\n\tasync validateProof(proof: Awaited<ReturnType<this['getProof']>>): Promise<boolean> {\n\t\tconst plaintextValue = Buffer.from(proof.value, 'base64');\n\t\tconst proofSaltBuffer = Buffer.from(proof.hash.salt, 'base64');\n\n\t\tconst publicKeyBuffer = Buffer.from(this.#account.publicKey.get());\n\t\tconst encryptedValue = this.#info.encryptedValue;\n\n\t\tconst hashInput = Buffer.concat([proofSaltBuffer, publicKeyBuffer, encryptedValue, plaintextValue]);\n\t\tconst hashedAndSaltedValue = KeetaNetClient.lib.Utils.Hash.Hash(hashInput);\n\t\tconst hashedAndSaltedValueBuffer = Buffer.from(hashedAndSaltedValue);\n\n\t\treturn(this.#info.hashedValue.value.equals(hashedAndSaltedValueBuffer));\n\t}\n\n\ttoJSON(): SensitiveAttributeJSON {\n\t\tconst info = KeetaNetClient.lib.Utils.Conversion.toJSONSerializable(this.#info);\n\t\treturn(info);\n\t}\n\n\t/**\n\t * Encrypt a value and create a new SensitiveAttribute\n\t */\n\tstatic async create<K extends CertificateAttributeNames>(\n\t\taccount: KeetaNetAccount,\n\t\tname: K,\n\t\tvalue: CertificateAttributeValue<K> | Buffer | ArrayBuffer\n\t): Promise<SensitiveAttribute<CertificateAttributeValue<K>>> {\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\tconst encodedValue = encodeForSensitive(name, value as SensitiveAttributeType | Buffer | ArrayBuffer);\n\n\t\tconst salt = crypto.randomBytes(32);\n\n\t\tconst hashingAlgorithm = KeetaNetClient.lib.Utils.Hash.HashFunctionName;\n\t\tconst publicKey = Buffer.from(account.publicKey.get());\n\n\t\tconst cipher = 'aes-256-gcm';\n\t\tconst key = crypto.randomBytes(32);\n\t\tconst nonce = crypto.randomBytes(12);\n\t\tconst encryptedKey = await account.encrypt(bufferToArrayBuffer(key));\n\n\t\tfunction encrypt(input: Buffer) {\n\t\t\tconst cipherObject = crypto.createCipheriv(cipher, key, nonce);\n\t\t\tlet retval = Buffer.concat([cipherObject.update(input), cipherObject.final()]);\n\n\t\t\t// For AES-GCM, append the 16-byte authentication tag\n\t\t\tif (cipher === 'aes-256-gcm') {\n\t\t\t\tretval = Buffer.concat([retval, getGCMAuthTag(cipherObject)]);\n\t\t\t}\n\n\t\t\treturn(retval);\n\t\t}\n\n\t\tconst encryptedValue = encrypt(encodedValue);\n\t\tconst encryptedSalt = encrypt(arrayBufferLikeToBuffer(salt));\n\n\t\tconst saltedValue = Buffer.concat([salt, publicKey, encryptedValue, encodedValue]);\n\t\tconst hashedAndSaltedValue = KeetaNetClient.lib.Utils.Hash.Hash(saltedValue);\n\n\t\tconst attributeStructure: SensitiveAttributeSchema = [\n\t\t\t/* Version */\n\t\t\t0n,\n\t\t\t/* Cipher Details */\n\t\t\t[\n\t\t\t\t/* Algorithm */\n\t\t\t\t{ type: 'oid', oid: getOID(cipher, sensitiveAttributeOIDDB) },\n\t\t\t\t/* IV or Nonce */\n\t\t\t\tnonce,\n\t\t\t\t/* Symmetric key, encrypted with the public key of the account */\n\t\t\t\tBuffer.from(encryptedKey)\n\t\t\t],\n\t\t\t/* Hashed Value */\n\t\t\t[\n\t\t\t\t/* Encrypted Salt */\n\t\t\t\tBuffer.from(encryptedSalt),\n\t\t\t\t/* Hashing Algorithm */\n\t\t\t\t{ type: 'oid', oid: getOID(hashingAlgorithm, sensitiveAttributeOIDDB) },\n\t\t\t\t/* Hash of <Encrypted Salt> || <Public Key> || <Value> */\n\t\t\t\tBuffer.from(hashedAndSaltedValue)\n\t\t\t],\n\t\t\t/* Encrypted Value, encrypted with the Cipher above */\n\t\t\tencryptedValue\n\t\t];\n\n\t\tconst encodedAttributeObject = ASN1.JStoASN1(attributeStructure);\n\t\tconst encryptedDER = encodedAttributeObject.toBER(false);\n\n\t\tconst decoder = function(data: Buffer | ArrayBuffer): CertificateAttributeValue<K> {\n\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\treturn(decodeForSensitive(name, data) as CertificateAttributeValue<K>);\n\t\t};\n\n\t\tconst result = new SensitiveAttribute<CertificateAttributeValue<K>>(account, encryptedDER, decoder);\n\t\treturn(result);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sensitive-attribute.js","sourceRoot":"","sources":["../../src/lib/sensitive-attribute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,cAAc,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,IAAI,MAAM,mCAAmC,CAAC;AAC1D,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC9G,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;AACnF,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAErD;;GAEG;AACH,MAAM,GAAG,GAAG,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,oBAAoB,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAevG;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,gCAAgC,GAalC;IACH,EAAE;IACF;QACC,IAAI,CAAC,YAAY,CAAC,KAAK;QACvB,IAAI,CAAC,YAAY,CAAC,aAAa;QAC/B,IAAI,CAAC,YAAY,CAAC,aAAa;KAC/B;IACD;QACC,IAAI,CAAC,YAAY,CAAC,aAAa;QAC/B,IAAI,CAAC,YAAY,CAAC,KAAK;QACvB,IAAI,CAAC,YAAY,CAAC,aAAa;KAC/B;IACD,IAAI,CAAC,YAAY,CAAC,aAAa;CA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-client';\nimport * as oids from '../services/kyc/oids.generated.js';\nimport * as ASN1 from './utils/asn1.js';\nimport { arrayBufferLikeToBuffer, arrayBufferToBuffer, Buffer, bufferToArrayBuffer } from './utils/buffer.js';\nimport crypto from './utils/crypto.js';\nimport type { SensitiveAttributeType, CertificateAttributeValue , CertificateAttributeOIDDB } from '../services/kyc/iso20022.generated.js';\nimport { CertificateAttributeSchema } from '../services/kyc/iso20022.generated.js';\nimport { getOID, lookupByOID } from './utils/oid.js';\n\n/**\n * Short alias for printing a debug representation of an object\n */\nconst DPO = KeetaNetClient.lib.Utils.Helper.debugPrintableObject.bind(KeetaNetClient.lib.Utils.Helper);\n\n/* ENUM */\ntype AccountKeyAlgorithm = InstanceType<typeof KeetaNetClient.lib.Account>['keyType'];\n\n/**\n * An alias for the KeetaNetAccount type\n */\ntype KeetaNetAccount = ReturnType<typeof KeetaNetClient.lib.Account.fromSeed<AccountKeyAlgorithm>>;\n\n/**\n * Type for certificate attribute names (derived from generated OID database)\n */\nexport type CertificateAttributeNames = keyof typeof CertificateAttributeOIDDB;\n\n/**\n * Sensitive Attribute Schema\n *\n * ASN.1 Schema:\n * SensitiveAttributes DEFINITIONS ::= BEGIN\n * SensitiveAttribute ::= SEQUENCE {\n * version INTEGER { v1(0) },\n * cipher SEQUENCE {\n * algorithm OBJECT IDENTIFIER,\n * ivOrNonce OCTET STRING,\n * key OCTET STRING\n * },\n * hashedValue SEQUENCE {\n * encryptedSalt OCTET STRING,\n * algorithm OBJECT IDENTIFIER,\n * value OCTET STRING\n * },\n * encryptedValue OCTET STRING\n * }\n * END\n *\n * https://keeta.notion.site/Keeta-KYC-Certificate-Extensions-13e5da848e588042bdcef81fc40458b7\n *\n * @internal\n */\nconst SensitiveAttributeSchemaInternal: [\n\tversion: 0n,\n\tcipher: [\n\t\talgorithm: typeof ASN1.ValidateASN1.IsOID,\n\t\tiv: typeof ASN1.ValidateASN1.IsOctetString,\n\t\tkey: typeof ASN1.ValidateASN1.IsOctetString\n\t],\n\thashedValue: [\n\t\tencryptedSalt: typeof ASN1.ValidateASN1.IsOctetString,\n\t\talgorithm: typeof ASN1.ValidateASN1.IsOID,\n\t\tvalue: typeof ASN1.ValidateASN1.IsOctetString\n\t],\n\tencryptedValue: typeof ASN1.ValidateASN1.IsOctetString\n] = [\n\t0n,\n\t[\n\t\tASN1.ValidateASN1.IsOID,\n\t\tASN1.ValidateASN1.IsOctetString,\n\t\tASN1.ValidateASN1.IsOctetString\n\t],\n\t[\n\t\tASN1.ValidateASN1.IsOctetString,\n\t\tASN1.ValidateASN1.IsOID,\n\t\tASN1.ValidateASN1.IsOctetString\n\t],\n\tASN1.ValidateASN1.IsOctetString\n];\n\n/**\n * The Sensitive Attribute Schema Internal\n *\n * @internal\n */\ntype SensitiveAttributeSchema = ASN1.SchemaMap<typeof SensitiveAttributeSchemaInternal>;\n\n/*\n * Database of permitted algorithms and their OIDs\n */\nconst sensitiveAttributeOIDDB = {\n\t'aes-256-gcm': oids.AES_256_GCM,\n\t'aes-256-cbc': oids.AES_256_CBC,\n\t'sha2-256': oids.SHA2_256,\n\t'sha3-256': oids.SHA3_256,\n\t'sha256': oids.SHA2_256,\n\t'aes256-gcm': oids.AES_256_GCM,\n\t'aes256-cbc': oids.AES_256_CBC\n};\n\n/**\n * Rewrite every `Date`, at any depth, as an explicit GeneralizedTime value.\n */\nfunction preferGeneralizedDates(value: unknown): unknown {\n\tif (value instanceof Date) {\n\t\treturn({ type: 'date', kind: 'general', date: value });\n\t}\n\tif (Buffer.isBuffer(value) || value instanceof ArrayBuffer) {\n\t\treturn(value);\n\t}\n\tif (Array.isArray(value)) {\n\t\treturn(value.map(preferGeneralizedDates));\n\t}\n\tif (value !== null && typeof value === 'object') {\n\t\tconst rewritten: { [key: string]: unknown } = {};\n\t\tfor (const [key, nested] of Object.entries(value)) {\n\t\t\trewritten[key] = preferGeneralizedDates(nested);\n\t\t}\n\n\t\treturn(rewritten);\n\t}\n\n\treturn(value);\n}\n\n/**\n * Encode an attribute value using its ASN.1 schema\n */\nexport function encodeAttribute(name: CertificateAttributeNames, value: unknown): ArrayBuffer {\n\tconst schema = CertificateAttributeSchema[name];\n\n\tlet encodedJS;\n\ttry {\n\t\tencodedJS = new ASN1.ValidateASN1(schema).fromJavaScriptObject(preferGeneralizedDates(value));\n\t} catch (err) {\n\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\tthrow(new Error(`Attribute ${name}: ${message} (value: ${JSON.stringify(DPO(value))})`));\n\t}\n\n\tif (encodedJS === undefined) {\n\t\tthrow(new Error(`Unsupported attribute value for encoding: ${JSON.stringify(DPO(value))}`));\n\t}\n\n\tconst asn1Object = ASN1.JStoASN1(encodedJS);\n\tif (!asn1Object) {\n\t\tthrow(new Error(`Failed to encode value for attribute ${name}`));\n\t}\n\n\treturn(asn1Object.toBER(false));\n}\n\n/**\n * Prepare a value for inclusion in a SensitiveAttribute: pre-encode complex and date types\n */\nexport function encodeForSensitive(\n\tname: CertificateAttributeNames | undefined,\n\tvalue: SensitiveAttributeType | Buffer | ArrayBuffer\n): Buffer {\n\tif (Buffer.isBuffer(value)) { return(value); }\n\tif (value instanceof ArrayBuffer) { return(arrayBufferToBuffer(value)); }\n\tif (typeof value === 'string') {\n\t\tconst asn1 = ASN1.JStoASN1({ type: 'string', kind: 'utf8', value });\n\t\treturn(arrayBufferToBuffer(asn1.toBER(false)));\n\t}\n\n\tif (value instanceof Date) {\n\t\tconst asn1 = ASN1.JStoASN1({ type: 'date', kind: 'general', date: value });\n\t\treturn(arrayBufferToBuffer(asn1.toBER(false)));\n\t}\n\n\tif (typeof value === 'object' && value !== null) {\n\t\tif (!name) { throw(new Error('attributeName required for complex types')); }\n\t\tconst encoded = encodeAttribute(name, value);\n\t\treturn(arrayBufferToBuffer(encoded));\n\t}\n\n\treturn(Buffer.from(String(value), 'utf-8'));\n}\n\n/**\n * Check if value is an ASN.1-like wrapper object\n */\nfunction isASN1Wrapper(obj: object): obj is { type: string; value: unknown } {\n\treturn('type' in obj && 'value' in obj && typeof obj.type === 'string');\n}\n\n/**\n * Normalize the result (unwrap ASN.1-like objects)\n */\nfunction normalizeDecodedValue(input: unknown): unknown {\n\tif (input === undefined || input === null || typeof input !== 'object') {\n\t\treturn(input);\n\t}\n\tif (input instanceof Date || Buffer.isBuffer(input) || input instanceof ArrayBuffer) {\n\t\treturn(input);\n\t}\n\tif (Array.isArray(input)) {\n\t\treturn(input.map(item => normalizeDecodedValue(item)));\n\t}\n\t// Unwrap ASN.1-like objects\n\tif (isASN1Wrapper(input)) {\n\t\tif (input.type === 'string' && typeof input.value === 'string') {\n\t\t\treturn(input.value);\n\t\t}\n\t\tif (input.type === 'date' && input.value instanceof Date) {\n\t\t\treturn(input.value);\n\t\t}\n\t}\n\t// Recursively normalize object properties\n\tconst result: { [key: string]: unknown } = {};\n\tfor (const [key, value] of Object.entries(input)) {\n\t\tresult[key] = normalizeDecodedValue(value);\n\t}\n\treturn(result);\n}\n\n/**\n * Decode ASN.1 data using a schema\n *\n * Note: The ASN1 library uses dynamic typing internally, so we consolidate\n * the unsafe operations here rather than scattering them throughout the code.\n */\nfunction decodeWithSchema(buffer: ArrayBuffer, schema: unknown): unknown {\n\t/* eslint-disable\n @typescript-eslint/no-explicit-any,\n @typescript-eslint/consistent-type-assertions,\n\t\t@typescript-eslint/no-unsafe-member-access,\n @typescript-eslint/no-unsafe-call,\n\t\t@typescript-eslint/no-unsafe-assignment\n */\n\tlet decodedASN1: ASN1.ASN1AnyJS | undefined;\n\ttry {\n\t\tdecodedASN1 = new (ASN1.BufferStorageASN1 as any)(buffer, schema).getASN1() as ASN1.ASN1AnyJS;\n\t} catch {\n\t\tdecodedASN1 = ASN1.ASN1toJS(buffer);\n\t}\n\tif (decodedASN1 === undefined) {\n\t\tthrow(new Error('Failed to decode ASN1 data'));\n\t}\n\n\tconst validator = new (ASN1.ValidateASN1 as any)(schema);\n\treturn(validator.toJavaScriptObject(decodedASN1));\n\t/* eslint-enable */\n}\n\n/**\n * GCM cipher helpers - Node's crypto types don't properly type getAuthTag/setAuthTag\n * when using createCipheriv/createDecipheriv, so we use typed wrappers.\n */\n/* eslint-disable @typescript-eslint/consistent-type-assertions -- Reflect.get returns unknown */\nfunction getGCMAuthTag(cipher: ReturnType<typeof crypto.createCipheriv>): Buffer {\n\tconst getAuthTag = Reflect.get(cipher, 'getAuthTag') as (() => Buffer) | undefined;\n\tif (typeof getAuthTag !== 'function') {\n\t\tthrow(new TypeError('getAuthTag is not available on cipher'));\n\t}\n\treturn(getAuthTag.call(cipher));\n}\n\nfunction setGCMAuthTag(decipher: ReturnType<typeof crypto.createDecipheriv>, tag: Buffer): void {\n\tconst setAuthTag = Reflect.get(decipher, 'setAuthTag') as ((tag: Buffer) => void) | undefined;\n\tif (typeof setAuthTag !== 'function') {\n\t\tthrow(new TypeError('setAuthTag is not available on decipher'));\n\t}\n\tsetAuthTag.call(decipher, tag);\n}\n/* eslint-enable @typescript-eslint/consistent-type-assertions */\n\n/**\n * Decode a value from its ASN.1 representation back to the original type\n *\n * @internal\n */\nexport function decodeForSensitive(\n\tname: CertificateAttributeNames,\n\tdata: Buffer | ArrayBuffer\n): unknown {\n\tconst buffer = Buffer.isBuffer(data) ? bufferToArrayBuffer(data) : data;\n\tconst schema: unknown = CertificateAttributeSchema[name];\n\tconst plainObject = decodeWithSchema(buffer, schema);\n\treturn(normalizeDecodedValue(plainObject));\n}\n\nexport type SensitiveAttributeJSON = {\n\tversion: string;\n\tpublicKey: string;\n\tcipher: {\n\t\talgorithm: string;\n\t\tiv: string;\n\t\tkey: string;\n\t};\n\thashedValue: {\n\t\tencryptedSalt: string;\n\t\talgorithm: string;\n\t\tvalue: string;\n\t};\n\tencryptedValue: string;\n};\n\nexport class SensitiveAttribute<T = ArrayBuffer> {\n\tprivate static readonly SensitiveAttributeObjectTypeID = 'c0cc9591-cebb-4441-babe-23739279e3f2';\n\tprivate readonly SensitiveAttributeObjectTypeID!: string;\n\n\treadonly #account: KeetaNetAccount;\n\treadonly #encryptedDER: ArrayBuffer;\n\treadonly #info: ReturnType<SensitiveAttribute<T>['decode']>;\n\treadonly #decoder?: (data: Buffer | ArrayBuffer) => T | Promise<T>;\n\n\tconstructor(\n\t\taccount: KeetaNetAccount,\n\t\tdata: Buffer | ArrayBuffer,\n\t\tdecoder?: (data: Buffer | ArrayBuffer) => T | Promise<T>\n\t) {\n\t\tObject.defineProperty(this, 'SensitiveAttributeObjectTypeID', {\n\t\t\tvalue: SensitiveAttribute.SensitiveAttributeObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\n\t\tthis.#account = account;\n\t\tthis.#encryptedDER = Buffer.isBuffer(data) ? bufferToArrayBuffer(data) : data;\n\t\tthis.#info = this.decode(data);\n\t\tif (decoder) {\n\t\t\tthis.#decoder = decoder;\n\t\t}\n\t}\n\n\t/**\n\t * Check if a value is a SensitiveAttribute instance\n\t */\n\tstatic isInstance(input: unknown): input is SensitiveAttribute<unknown> {\n\t\tif (typeof input !== 'object' || input === null) {\n\t\t\treturn(false);\n\t\t}\n\n\t\treturn(Reflect.get(input, 'SensitiveAttributeObjectTypeID') === SensitiveAttribute.SensitiveAttributeObjectTypeID);\n\t}\n\n\t/**\n\t * Get the public key this attribute was encrypted for\n\t */\n\tget publicKey(): string {\n\t\treturn(this.#account.publicKeyString.get());\n\t}\n\n\t/**\n\t * Get the raw encrypted DER for certificate embedding\n\t */\n\ttoDER(): ArrayBuffer {\n\t\treturn(this.#encryptedDER);\n\t}\n\n\tprivate decode(data: Buffer | ArrayBuffer) {\n\t\tif (Buffer.isBuffer(data)) {\n\t\t\tdata = bufferToArrayBuffer(data);\n\t\t}\n\n\t\tlet decodedAttribute;\n\t\ttry {\n\t\t\tconst dataObject = new ASN1.BufferStorageASN1(data, SensitiveAttributeSchemaInternal);\n\t\t\tdecodedAttribute = dataObject.getASN1();\n\t\t} catch {\n\t\t\tconst js = ASN1.ASN1toJS(data);\n\t\t\tthrow(new Error(`SensitiveAttribute.decode: unexpected DER shape ${JSON.stringify(DPO(js))}`));\n\t\t}\n\n\t\tconst decodedVersion = decodedAttribute[0] + 1n;\n\t\tif (decodedVersion !== 1n) {\n\t\t\tthrow(new Error(`Unsupported Sensitive Attribute version (${decodedVersion})`));\n\t\t}\n\n\t\treturn({\n\t\t\tversion: decodedVersion,\n\t\t\tpublicKey: this.#account.publicKeyString.get(),\n\t\t\tcipher: {\n\t\t\t\talgorithm: lookupByOID(decodedAttribute[1][0].oid, sensitiveAttributeOIDDB),\n\t\t\t\tiv: decodedAttribute[1][1],\n\t\t\t\tkey: decodedAttribute[1][2]\n\t\t\t},\n\t\t\thashedValue: {\n\t\t\t\tencryptedSalt: decodedAttribute[2][0],\n\t\t\t\talgorithm: lookupByOID(decodedAttribute[2][1].oid, sensitiveAttributeOIDDB),\n\t\t\t\tvalue: decodedAttribute[2][2]\n\t\t\t},\n\t\t\tencryptedValue: decodedAttribute[3]\n\t\t});\n\t}\n\n\tasync #decryptValue(value: Buffer) {\n\t\tconst decryptedKey = await this.#account.decrypt(bufferToArrayBuffer(this.#info.cipher.key));\n\t\tconst algorithm = this.#info.cipher.algorithm;\n\t\tconst iv = this.#info.cipher.iv;\n\n\t\tconst decipher = crypto.createDecipheriv(algorithm, Buffer.from(decryptedKey), iv);\n\n\t\t// For AES-GCM, extract and set the 16-byte authentication tag\n\t\tif (algorithm === 'aes-256-gcm') {\n\t\t\tconst authTag = value.subarray(-16);\n\t\t\tconst ciphertext = value.subarray(0, -16);\n\n\t\t\tsetGCMAuthTag(decipher, authTag);\n\n\t\t\tconst decrypted = decipher.update(ciphertext);\n\t\t\tdecipher.final(); // Verify auth tag\n\t\t\treturn(decrypted);\n\t\t}\n\n\t\t// For other algorithms (like CBC), just decrypt normally\n\t\tconst decrypted = decipher.update(value);\n\t\tdecipher.final();\n\t\treturn(decrypted);\n\t}\n\n\t/**\n\t * Get the value of the sensitive attribute\n\t *\n\t * This will decrypt the value using the account's private key\n\t * and return the value as an ArrayBuffer\n\t *\n\t * Since sensitive attributes are binary blobs, this returns an\n\t * ArrayBuffer\n\t */\n\tasync get(): Promise<ArrayBuffer> {\n\t\tconst decryptedValue = await this.#decryptValue(arrayBufferLikeToBuffer(this.#info.encryptedValue));\n\t\treturn(bufferToArrayBuffer(decryptedValue));\n\t}\n\n\tasync getValue(): Promise<T> {\n\t\tconst value = await this.get();\n\t\tif (!this.#decoder) {\n\t\t\t/**\n\t\t\t * TypeScript complains that T may not be the correct\n\t\t\t * type here, but gives us no tools to enforce that it\n\t\t\t * is -- it should always be ArrayBuffer if no decoder\n\t\t\t * is provided, but someone could always specify a\n\t\t\t * type parameter in that case and we cannot check\n\t\t\t * that at runtime since T is only a compile-time type.\n\t\t\t */\n\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\treturn(value as unknown as T);\n\t\t}\n\t\treturn(await this.#decoder(value));\n\t}\n\n\t/**\n\t * Generate a proof that a sensitive attribute is a given value,\n\t * which can be validated by a third party using the certificate\n\t * and the `validateProof` method\n\t */\n\tasync getProof(): Promise<{ value: string; hash: { salt: string }}> {\n\t\tconst value = await this.get();\n\t\tconst salt = await this.#decryptValue(arrayBufferLikeToBuffer(this.#info.hashedValue.encryptedSalt));\n\n\t\treturn({\n\t\t\tvalue: Buffer.from(value).toString('base64'),\n\t\t\thash: {\n\t\t\t\tsalt: salt.toString('base64')\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Validate the proof that a sensitive attribute is a given value\n\t */\n\tasync validateProof(proof: Awaited<ReturnType<this['getProof']>>): Promise<boolean> {\n\t\tconst plaintextValue = Buffer.from(proof.value, 'base64');\n\t\tconst proofSaltBuffer = Buffer.from(proof.hash.salt, 'base64');\n\n\t\tconst publicKeyBuffer = Buffer.from(this.#account.publicKey.get());\n\t\tconst encryptedValue = this.#info.encryptedValue;\n\n\t\tconst hashInput = Buffer.concat([proofSaltBuffer, publicKeyBuffer, encryptedValue, plaintextValue]);\n\t\tconst hashedAndSaltedValue = KeetaNetClient.lib.Utils.Hash.Hash(hashInput);\n\t\tconst hashedAndSaltedValueBuffer = Buffer.from(hashedAndSaltedValue);\n\n\t\treturn(this.#info.hashedValue.value.equals(hashedAndSaltedValueBuffer));\n\t}\n\n\ttoJSON(): SensitiveAttributeJSON {\n\t\tconst info = KeetaNetClient.lib.Utils.Conversion.toJSONSerializable(this.#info);\n\t\treturn(info);\n\t}\n\n\t/**\n\t * Encrypt a value and create a new SensitiveAttribute\n\t */\n\tstatic async create<K extends CertificateAttributeNames>(\n\t\taccount: KeetaNetAccount,\n\t\tname: K,\n\t\tvalue: CertificateAttributeValue<K> | Buffer | ArrayBuffer\n\t): Promise<SensitiveAttribute<CertificateAttributeValue<K>>> {\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\tconst encodedValue = encodeForSensitive(name, value as SensitiveAttributeType | Buffer | ArrayBuffer);\n\n\t\tconst salt = crypto.randomBytes(32);\n\n\t\tconst hashingAlgorithm = KeetaNetClient.lib.Utils.Hash.HashFunctionName;\n\t\tconst publicKey = Buffer.from(account.publicKey.get());\n\n\t\tconst cipher = 'aes-256-gcm';\n\t\tconst key = crypto.randomBytes(32);\n\t\tconst nonce = crypto.randomBytes(12);\n\t\tconst encryptedKey = await account.encrypt(bufferToArrayBuffer(key));\n\n\t\tfunction encrypt(input: Buffer) {\n\t\t\tconst cipherObject = crypto.createCipheriv(cipher, key, nonce);\n\t\t\tlet retval = Buffer.concat([cipherObject.update(input), cipherObject.final()]);\n\n\t\t\t// For AES-GCM, append the 16-byte authentication tag\n\t\t\tif (cipher === 'aes-256-gcm') {\n\t\t\t\tretval = Buffer.concat([retval, getGCMAuthTag(cipherObject)]);\n\t\t\t}\n\n\t\t\treturn(retval);\n\t\t}\n\n\t\tconst encryptedValue = encrypt(encodedValue);\n\t\tconst encryptedSalt = encrypt(arrayBufferLikeToBuffer(salt));\n\n\t\tconst saltedValue = Buffer.concat([salt, publicKey, encryptedValue, encodedValue]);\n\t\tconst hashedAndSaltedValue = KeetaNetClient.lib.Utils.Hash.Hash(saltedValue);\n\n\t\tconst attributeStructure: SensitiveAttributeSchema = [\n\t\t\t/* Version */\n\t\t\t0n,\n\t\t\t/* Cipher Details */\n\t\t\t[\n\t\t\t\t/* Algorithm */\n\t\t\t\t{ type: 'oid', oid: getOID(cipher, sensitiveAttributeOIDDB) },\n\t\t\t\t/* IV or Nonce */\n\t\t\t\tnonce,\n\t\t\t\t/* Symmetric key, encrypted with the public key of the account */\n\t\t\t\tBuffer.from(encryptedKey)\n\t\t\t],\n\t\t\t/* Hashed Value */\n\t\t\t[\n\t\t\t\t/* Encrypted Salt */\n\t\t\t\tBuffer.from(encryptedSalt),\n\t\t\t\t/* Hashing Algorithm */\n\t\t\t\t{ type: 'oid', oid: getOID(hashingAlgorithm, sensitiveAttributeOIDDB) },\n\t\t\t\t/* Hash of <Encrypted Salt> || <Public Key> || <Value> */\n\t\t\t\tBuffer.from(hashedAndSaltedValue)\n\t\t\t],\n\t\t\t/* Encrypted Value, encrypted with the Cipher above */\n\t\t\tencryptedValue\n\t\t];\n\n\t\tconst encodedAttributeObject = ASN1.JStoASN1(attributeStructure);\n\t\tconst encryptedDER = encodedAttributeObject.toBER(false);\n\n\t\tconst decoder = function(data: Buffer | ArrayBuffer): CertificateAttributeValue<K> {\n\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\treturn(decodeForSensitive(name, data) as CertificateAttributeValue<K>);\n\t\t};\n\n\t\tconst result = new SensitiveAttribute<CertificateAttributeValue<K>>(account, encryptedDER, decoder);\n\t\treturn(result);\n\t}\n}\n"]}
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keetanetwork/anchor",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.84",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@keetanetwork/anchor",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.84",
|
|
10
10
|
"license": "SEE LICENSE IN LICENSE",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@keetanetwork/currency-info": "1.2.5",
|
|
13
13
|
"@keetanetwork/keetanet-client": "0.18.2",
|
|
14
|
+
"@noble/hashes": "1.5.0",
|
|
14
15
|
"typia": "9.5.0"
|
|
15
16
|
},
|
|
16
17
|
"engines": {
|
|
@@ -196,6 +197,17 @@
|
|
|
196
197
|
"@keetanetwork/asn1-napi-rs": "1.2.3"
|
|
197
198
|
}
|
|
198
199
|
},
|
|
200
|
+
"node_modules/@noble/hashes": {
|
|
201
|
+
"version": "1.5.0",
|
|
202
|
+
"integrity": "sha512-1j6kQFb7QRru7eKN3ZDvRcP13rugwdxZqCjbiAVZfIJwgj2A65UmT4TgARXGlXgnRkORLTDTrO19ZErt7+QXgA==",
|
|
203
|
+
"license": "MIT",
|
|
204
|
+
"engines": {
|
|
205
|
+
"node": "^14.21.3 || >=16"
|
|
206
|
+
},
|
|
207
|
+
"funding": {
|
|
208
|
+
"url": "https://paulmillr.com/funding/"
|
|
209
|
+
}
|
|
210
|
+
},
|
|
199
211
|
"node_modules/@opentelemetry/api": {
|
|
200
212
|
"version": "1.9.0",
|
|
201
213
|
"integrity": "sha512-3giAOQvZiH5F9bMlMiv8+GSPMeqg0dbaeo58/0SlA9sxSqZhnUtxzX9/2FzyhS9sWQf5S0GJE0AKBrFqjpeYcg==",
|
|
@@ -257,8 +269,8 @@
|
|
|
257
269
|
"optional": true
|
|
258
270
|
},
|
|
259
271
|
"node_modules/@protobufjs/utf8": {
|
|
260
|
-
"version": "1.1.
|
|
261
|
-
"integrity": "sha512-
|
|
272
|
+
"version": "1.1.2",
|
|
273
|
+
"integrity": "sha512-b1UQwcEZ4yCnMCD8DAL1VlbvBJE9/IX4FTIp7BG1xYpf29SLazLSrqUkj4w7Y5y7cCVP6E5tcqqcI0xemPkHug==",
|
|
262
274
|
"license": "BSD-3-Clause",
|
|
263
275
|
"optional": true
|
|
264
276
|
},
|
|
@@ -1681,8 +1693,8 @@
|
|
|
1681
1693
|
}
|
|
1682
1694
|
},
|
|
1683
1695
|
"node_modules/protobufjs": {
|
|
1684
|
-
"version": "7.6.
|
|
1685
|
-
"integrity": "sha512
|
|
1696
|
+
"version": "7.6.5",
|
|
1697
|
+
"integrity": "sha512-/FPD0nUc9jH6rfFjji9IBqOz4pcSE3CsT1m7Ep6Mdb0LxSUMj8hgl6GomOvZzpNpAqqGaXA0P3VSrZLFzIhQrw==",
|
|
1686
1698
|
"hasInstallScript": true,
|
|
1687
1699
|
"license": "BSD-3-Clause",
|
|
1688
1700
|
"optional": true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keetanetwork/anchor",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.84",
|
|
4
4
|
"description": "KeetaNetwork Network Anchor",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@keetanetwork/currency-info": "1.2.5",
|
|
27
27
|
"@keetanetwork/keetanet-client": "0.18.2",
|
|
28
|
+
"@noble/hashes": "1.5.0",
|
|
28
29
|
"typia": "9.5.0"
|
|
29
30
|
},
|
|
30
31
|
"engines": {
|
package/services/fx/client.d.ts
CHANGED
|
@@ -6,7 +6,9 @@ import type Resolver from '../../lib/resolver.ts';
|
|
|
6
6
|
import type { ServiceMetadata, SharedLookupCriteria } from '../../lib/resolver.ts';
|
|
7
7
|
import type { BrandedString } from '../../lib/utils/brand.ts';
|
|
8
8
|
import type { ConversionInput, ConversionInputCanonical, KeetaFXAnchorEstimate, KeetaFXAnchorExchange, KeetaFXAnchorQuote, KeetaNetTokenPublicKeyString } from './common.ts';
|
|
9
|
+
import type { AnchorExternalInput } from '../../lib/anchor-external.js';
|
|
9
10
|
import type { AnchorMetadataLegalField, SharedAnchorMetadataLegalExtension } from '../../lib/metadata.types.js';
|
|
11
|
+
import type { AnchorReference } from '../../lib/anchor-status.js';
|
|
10
12
|
/**
|
|
11
13
|
* An opaque type that represents a provider ID.
|
|
12
14
|
*/
|
|
@@ -105,7 +107,9 @@ export declare class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {
|
|
|
105
107
|
quote: KeetaFXAnchorQuote;
|
|
106
108
|
} | {
|
|
107
109
|
estimate: KeetaFXAnchorEstimate;
|
|
108
|
-
}, block?: InstanceType<typeof KeetaNetLib.Block
|
|
110
|
+
}, block?: InstanceType<typeof KeetaNetLib.Block>, options?: {
|
|
111
|
+
inputs?: readonly AnchorExternalInput[];
|
|
112
|
+
}): Promise<KeetaFXAnchorExchange>;
|
|
109
113
|
getExchangeStatus(exchangeID: string): Promise<KeetaFXAnchorExchange>;
|
|
110
114
|
}
|
|
111
115
|
declare class KeetaFXAnchorExchangeWithProvider {
|
|
@@ -117,7 +121,9 @@ declare class KeetaFXAnchorExchangeWithProvider {
|
|
|
117
121
|
interface CanCreateExchange {
|
|
118
122
|
readonly isQuote: boolean;
|
|
119
123
|
get request(): ConversionInputCanonical;
|
|
120
|
-
createExchange(block?: InstanceType<typeof KeetaNetLib.Block
|
|
124
|
+
createExchange(block?: InstanceType<typeof KeetaNetLib.Block>, options?: {
|
|
125
|
+
inputs?: readonly AnchorExternalInput[];
|
|
126
|
+
}): Promise<KeetaFXAnchorExchangeWithProvider>;
|
|
121
127
|
}
|
|
122
128
|
declare class KeetaFXAnchorQuoteWithProvider implements CanCreateExchange {
|
|
123
129
|
readonly provider: KeetaFXAnchorProviderBase;
|
|
@@ -125,7 +131,9 @@ declare class KeetaFXAnchorQuoteWithProvider implements CanCreateExchange {
|
|
|
125
131
|
readonly isQuote: true;
|
|
126
132
|
constructor(provider: KeetaFXAnchorProviderBase, quote: KeetaFXAnchorQuote);
|
|
127
133
|
get request(): ConversionInputCanonical;
|
|
128
|
-
createExchange(block?: InstanceType<typeof KeetaNetLib.Block
|
|
134
|
+
createExchange(block?: InstanceType<typeof KeetaNetLib.Block>, options?: {
|
|
135
|
+
inputs?: readonly AnchorExternalInput[];
|
|
136
|
+
}): Promise<KeetaFXAnchorExchangeWithProvider>;
|
|
129
137
|
/**
|
|
130
138
|
* Re-fetch the quote from the provider.
|
|
131
139
|
*
|
|
@@ -140,7 +148,9 @@ declare class KeetaFXAnchorEstimateWithProvider implements CanCreateExchange {
|
|
|
140
148
|
constructor(provider: KeetaFXAnchorProviderBase, estimate: KeetaFXAnchorEstimate);
|
|
141
149
|
get request(): ConversionInputCanonical;
|
|
142
150
|
getQuote(tolerance?: number): Promise<KeetaFXAnchorQuoteWithProvider>;
|
|
143
|
-
createExchange(block?: InstanceType<typeof KeetaNetLib.Block
|
|
151
|
+
createExchange(block?: InstanceType<typeof KeetaNetLib.Block>, options?: {
|
|
152
|
+
inputs?: readonly AnchorExternalInput[];
|
|
153
|
+
}): Promise<KeetaFXAnchorExchangeWithProvider>;
|
|
144
154
|
/**
|
|
145
155
|
* Re-fetch the estimate from the provider.
|
|
146
156
|
*
|
|
@@ -173,6 +183,10 @@ declare class KeetaFXAnchorClient extends KeetaFXAnchorBase {
|
|
|
173
183
|
conversions: KeetaNetTokenPublicKeyString[];
|
|
174
184
|
} | null>;
|
|
175
185
|
getBaseProvidersForConversion(request: ConversionInput, options?: GetProvidersOptions, sharedCriteria?: SharedLookupCriteria): Promise<KeetaFXAnchorProviderBase[] | null>;
|
|
186
|
+
/**
|
|
187
|
+
* Resolve an FX provider by the account that signs its advertised service metadata.
|
|
188
|
+
*/
|
|
189
|
+
getProviderByAccount(anchor: AnchorReference, requiredOperations?: (keyof KeetaFXAnchorOperations)[]): Promise<KeetaFXAnchorProviderBase | null>;
|
|
176
190
|
getEstimates(request: ConversionInput, options?: Omit<GetProvidersOptions, 'requiredOperations'>, sharedCriteria?: SharedLookupCriteria): Promise<KeetaFXAnchorEstimateWithProvider[] | null>;
|
|
177
191
|
getQuotes(request: ConversionInput, options?: AccountOptions, sharedCriteria?: SharedLookupCriteria): Promise<KeetaFXAnchorQuoteWithProvider[] | null>;
|
|
178
192
|
getQuotesOrEstimates(request: ConversionInput, options?: AccountOptions, sharedCriteria?: SharedLookupCriteria): Promise<(KeetaFXAnchorQuoteWithProvider | KeetaFXAnchorEstimateWithProvider)[] | null>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/services/fx/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EACX,UAAU,IAAI,kBAAkB,EAChC,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,QAAQ,MAAM,uBAAuB,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAyB,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAI1G,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAQ9D,OAAO,KAAK,EACX,eAAe,EACf,wBAAwB,EAExB,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,4BAA4B,EAC5B,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/services/fx/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EACX,UAAU,IAAI,kBAAkB,EAChC,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,QAAQ,MAAM,uBAA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CAAM,EAAE,cAAc,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,iCAAiC,EAAE,GAAG,IAAI,CAAC;IA2DjM,SAAS,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,GAAE,cAAmB,EAAE,cAAc,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,8BAA8B,EAAE,GAAG,IAAI,CAAC;IAkB1J,oBAAoB,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,GAAE,cAAmB,EAAE,cAAc,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,CAAC,8BAA8B,GAAG,iCAAiC,CAAC,EAAE,GAAG,IAAI,CAAC;IAkD3M,SAAS,CAAC,KAAK,SAAS,eAAe,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,yBAAyB,GAAG,IAAI,CAAC,CAAC;IA4CpI,uBAAuB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,wBAAwB,CAAC,aAAa,CAAC,CAAC,GAAG,IAAI,CAAC;CAkCvH;AAED,eAAe,mBAAmB,CAAC"}
|
package/services/fx/client.js
CHANGED
|
@@ -4,6 +4,7 @@ import { Buffer } from '../../lib/utils/buffer.js';
|
|
|
4
4
|
import crypto from '../../lib/utils/crypto.js';
|
|
5
5
|
import { validateURL } from '../../lib/utils/url.js';
|
|
6
6
|
import { assertKeetaNetTokenPublicKeyString, isKeetaFXAnchorEstimateResponse, isKeetaFXAnchorExchangeResponse, isKeetaFXAnchorQuoteResponse, Errors as FXErrors } from './common.js';
|
|
7
|
+
import { AnchorExternalBuilder } from '../../lib/anchor-external.js';
|
|
7
8
|
import { KeetaAnchorError, KeetaAnchorUserError } from '../../lib/error.js';
|
|
8
9
|
import { resolveSharedAnchorMetadataLegalExtension } from '../../lib/metadata.types.js';
|
|
9
10
|
function typedFxServiceEntries(obj) {
|
|
@@ -258,7 +259,7 @@ export class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {
|
|
|
258
259
|
signed: quoteJSON.signed
|
|
259
260
|
});
|
|
260
261
|
}
|
|
261
|
-
async createExchange(input, block) {
|
|
262
|
+
async createExchange(input, block, options) {
|
|
262
263
|
let swapBlock = block;
|
|
263
264
|
if (swapBlock === undefined) {
|
|
264
265
|
/* Liquidity Provider that will complete the swap */
|
|
@@ -313,7 +314,17 @@ export class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {
|
|
|
313
314
|
}
|
|
314
315
|
}
|
|
315
316
|
builder.receive(liquidityProvider, receiveAmount, request.to, request.affinity === 'to');
|
|
316
|
-
|
|
317
|
+
/*
|
|
318
|
+
* Tag the principal send with an anchor external naming the FX
|
|
319
|
+
* provider and a client-chosen correlation id.
|
|
320
|
+
*/
|
|
321
|
+
const correlationId = crypto.randomUUID();
|
|
322
|
+
const externalBuilder = new AnchorExternalBuilder().setAnchor(liquidityProvider, { transactionId: correlationId });
|
|
323
|
+
for (const inputReference of options?.inputs ?? []) {
|
|
324
|
+
externalBuilder.addInput(inputReference.blockHash, inputReference.operationIndex);
|
|
325
|
+
}
|
|
326
|
+
const external = await externalBuilder.build();
|
|
327
|
+
builder.send(liquidityProvider, sendAmount, request.from, external);
|
|
317
328
|
const blocks = await builder.computeBlocks();
|
|
318
329
|
if (blocks.blocks.length !== 1) {
|
|
319
330
|
throw (new Error('Creating Swap Generated more than 1 block'));
|
|
@@ -415,8 +426,8 @@ class KeetaFXAnchorQuoteWithProvider {
|
|
|
415
426
|
get request() {
|
|
416
427
|
return (this.quote.request);
|
|
417
428
|
}
|
|
418
|
-
async createExchange(block) {
|
|
419
|
-
const exchange = await this.provider.createExchange({ quote: this.quote }, block);
|
|
429
|
+
async createExchange(block, options) {
|
|
430
|
+
const exchange = await this.provider.createExchange({ quote: this.quote }, block, options);
|
|
420
431
|
return (new KeetaFXAnchorExchangeWithProvider(this.provider, exchange));
|
|
421
432
|
}
|
|
422
433
|
/**
|
|
@@ -444,8 +455,8 @@ class KeetaFXAnchorEstimateWithProvider {
|
|
|
444
455
|
const quote = await this.provider.getQuote(this.estimate, tolerance);
|
|
445
456
|
return (new KeetaFXAnchorQuoteWithProvider(this.provider, quote));
|
|
446
457
|
}
|
|
447
|
-
async createExchange(block) {
|
|
448
|
-
const exchange = await this.provider.createExchange({ estimate: this.estimate }, block);
|
|
458
|
+
async createExchange(block, options) {
|
|
459
|
+
const exchange = await this.provider.createExchange({ estimate: this.estimate }, block, options);
|
|
449
460
|
return (new KeetaFXAnchorExchangeWithProvider(this.provider, exchange));
|
|
450
461
|
}
|
|
451
462
|
/**
|
|
@@ -596,6 +607,41 @@ class KeetaFXAnchorClient extends KeetaFXAnchorBase {
|
|
|
596
607
|
});
|
|
597
608
|
return (providers);
|
|
598
609
|
}
|
|
610
|
+
/**
|
|
611
|
+
* Resolve an FX provider by the account that signs its advertised service metadata.
|
|
612
|
+
*/
|
|
613
|
+
async getProviderByAccount(anchor, requiredOperations) {
|
|
614
|
+
const request = {};
|
|
615
|
+
if (requiredOperations !== undefined) {
|
|
616
|
+
request.requiredOperations = requiredOperations;
|
|
617
|
+
}
|
|
618
|
+
const providerEndpoints = await getEndpoints(this.resolver, request, this.#account, { accounts: [anchor] }, { logger: this.logger });
|
|
619
|
+
if (providerEndpoints === null) {
|
|
620
|
+
return (null);
|
|
621
|
+
}
|
|
622
|
+
const [entry] = typedFxServiceEntries(providerEndpoints);
|
|
623
|
+
if (entry === undefined) {
|
|
624
|
+
return (null);
|
|
625
|
+
}
|
|
626
|
+
const [providerID, serviceInfo] = entry;
|
|
627
|
+
const pair = serviceInfo.from[0];
|
|
628
|
+
if (pair === undefined) {
|
|
629
|
+
return (null);
|
|
630
|
+
}
|
|
631
|
+
const fromCode = pair.currencyCodes[0];
|
|
632
|
+
const toCode = pair.to[0];
|
|
633
|
+
if (fromCode === undefined || toCode === undefined) {
|
|
634
|
+
return (null);
|
|
635
|
+
}
|
|
636
|
+
const conversion = {
|
|
637
|
+
from: KeetaNetLib.Account.fromPublicKeyString(fromCode),
|
|
638
|
+
to: KeetaNetLib.Account.fromPublicKeyString(toCode),
|
|
639
|
+
amount: 0n,
|
|
640
|
+
affinity: 'from'
|
|
641
|
+
};
|
|
642
|
+
const provider = new KeetaFXAnchorProviderBase(serviceInfo, providerID, conversion, this);
|
|
643
|
+
return (provider);
|
|
644
|
+
}
|
|
599
645
|
async getEstimates(request, options = {}, sharedCriteria) {
|
|
600
646
|
const estimateProviders = await this.getBaseProvidersForConversion(request, {
|
|
601
647
|
...options,
|