@oneaddress/partner-sdk 1.3.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +185 -6
- package/README.md +301 -69
- package/dist/{chunk-O2RSPJVP.mjs → chunk-CE6M64CX.mjs} +331 -14
- package/dist/{chunk-2QGC7BHC.mjs → chunk-TAZD6PFZ.mjs} +307 -40
- package/dist/edge.d.mts +1 -1
- package/dist/edge.d.ts +1 -1
- package/dist/edge.js +571 -72
- package/dist/edge.mjs +12 -2
- package/dist/index.d.mts +490 -33
- package/dist/index.d.ts +490 -33
- package/dist/index.js +685 -72
- package/dist/index.mjs +20 -2
- package/dist/{src-DYGFEKX6.mjs → src-ESYTJ2EY.mjs} +31 -1
- package/package.json +28 -13
package/dist/index.js
CHANGED
|
@@ -6,8 +6,13 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
8
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __esm = (fn, res) => function __init() {
|
|
10
|
-
|
|
9
|
+
var __esm = (fn, res, err) => function __init() {
|
|
10
|
+
if (err) throw err[0];
|
|
11
|
+
try {
|
|
12
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
13
|
+
} catch (e) {
|
|
14
|
+
throw err = [e], e;
|
|
15
|
+
}
|
|
11
16
|
};
|
|
12
17
|
var __export = (target, all) => {
|
|
13
18
|
for (var name in all)
|
|
@@ -32,7 +37,7 @@ var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__
|
|
|
32
37
|
var __toCommonJS = (mod2) => __copyProps(__defProp({}, "__esModule", { value: true }), mod2);
|
|
33
38
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
34
39
|
|
|
35
|
-
//
|
|
40
|
+
// ../../node_modules/@noble/hashes/utils.js
|
|
36
41
|
function isBytes(a) {
|
|
37
42
|
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
|
|
38
43
|
}
|
|
@@ -177,7 +182,7 @@ function randomBytes(bytesLength = 32) {
|
|
|
177
182
|
}
|
|
178
183
|
var isLE, swap32IfBE, hasHexBuiltin, hexes, asciis, oidNist;
|
|
179
184
|
var init_utils = __esm({
|
|
180
|
-
"
|
|
185
|
+
"../../node_modules/@noble/hashes/utils.js"() {
|
|
181
186
|
"use strict";
|
|
182
187
|
isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
|
|
183
188
|
swap32IfBE = isLE ? (u) => u : byteSwap32;
|
|
@@ -195,7 +200,7 @@ var init_utils = __esm({
|
|
|
195
200
|
}
|
|
196
201
|
});
|
|
197
202
|
|
|
198
|
-
//
|
|
203
|
+
// ../../node_modules/@noble/curves/utils.js
|
|
199
204
|
function abool(value, title = "") {
|
|
200
205
|
if (typeof value !== "boolean") {
|
|
201
206
|
const prefix = title && `"${title}" `;
|
|
@@ -303,7 +308,7 @@ function validateObject(object, fields = {}, optFields = {}) {
|
|
|
303
308
|
}
|
|
304
309
|
var abytes2, anumber2, bytesToHex2, concatBytes2, hexToBytes2, isBytes2, randomBytes2, _0n, _1n, isPosBig, bitMask, notImplemented;
|
|
305
310
|
var init_utils2 = __esm({
|
|
306
|
-
"
|
|
311
|
+
"../../node_modules/@noble/curves/utils.js"() {
|
|
307
312
|
"use strict";
|
|
308
313
|
init_utils();
|
|
309
314
|
abytes2 = (value, length, title) => abytes(value, length, title);
|
|
@@ -323,7 +328,7 @@ var init_utils2 = __esm({
|
|
|
323
328
|
}
|
|
324
329
|
});
|
|
325
330
|
|
|
326
|
-
//
|
|
331
|
+
// ../../node_modules/@noble/curves/abstract/modular.js
|
|
327
332
|
function mod(a, b) {
|
|
328
333
|
if (b <= _0n2)
|
|
329
334
|
throw new Error("mod: expected positive modulus, got " + b);
|
|
@@ -550,7 +555,7 @@ function Field(ORDER, opts2 = {}) {
|
|
|
550
555
|
}
|
|
551
556
|
var _0n2, _1n2, _2n, _3n, _4n, _5n, _7n, _8n, _9n, _16n, isNegativeLE, FIELD_FIELDS, FIELD_SQRT, _Field;
|
|
552
557
|
var init_modular = __esm({
|
|
553
|
-
"
|
|
558
|
+
"../../node_modules/@noble/curves/abstract/modular.js"() {
|
|
554
559
|
"use strict";
|
|
555
560
|
init_utils2();
|
|
556
561
|
_0n2 = /* @__PURE__ */ BigInt(0);
|
|
@@ -722,7 +727,7 @@ var init_modular = __esm({
|
|
|
722
727
|
}
|
|
723
728
|
});
|
|
724
729
|
|
|
725
|
-
//
|
|
730
|
+
// ../../node_modules/@noble/curves/abstract/curve.js
|
|
726
731
|
function negateCt(condition, item) {
|
|
727
732
|
const neg = item.negate();
|
|
728
733
|
return condition ? neg : item;
|
|
@@ -806,7 +811,7 @@ function createKeygen(randomSecretKey, getPublicKey) {
|
|
|
806
811
|
}
|
|
807
812
|
var _0n3, _1n3, pointPrecomputes, pointWindowSizes, wNAF;
|
|
808
813
|
var init_curve = __esm({
|
|
809
|
-
"
|
|
814
|
+
"../../node_modules/@noble/curves/abstract/curve.js"() {
|
|
810
815
|
"use strict";
|
|
811
816
|
init_utils2();
|
|
812
817
|
init_modular();
|
|
@@ -949,7 +954,7 @@ var init_curve = __esm({
|
|
|
949
954
|
}
|
|
950
955
|
});
|
|
951
956
|
|
|
952
|
-
//
|
|
957
|
+
// ../../node_modules/@noble/curves/abstract/edwards.js
|
|
953
958
|
function isEdValidXY(Fp2, CURVE, x, y) {
|
|
954
959
|
const x2 = Fp2.sqr(x);
|
|
955
960
|
const y2 = Fp2.sqr(y);
|
|
@@ -1226,7 +1231,7 @@ function edwards(params, extraOpts = {}) {
|
|
|
1226
1231
|
}
|
|
1227
1232
|
var _0n4, _1n4, _2n2, _8n2, PrimeEdwardsPoint;
|
|
1228
1233
|
var init_edwards = __esm({
|
|
1229
|
-
"
|
|
1234
|
+
"../../node_modules/@noble/curves/abstract/edwards.js"() {
|
|
1230
1235
|
"use strict";
|
|
1231
1236
|
init_utils2();
|
|
1232
1237
|
init_curve();
|
|
@@ -1317,7 +1322,7 @@ var init_edwards = __esm({
|
|
|
1317
1322
|
}
|
|
1318
1323
|
});
|
|
1319
1324
|
|
|
1320
|
-
//
|
|
1325
|
+
// ../../node_modules/@noble/curves/abstract/montgomery.js
|
|
1321
1326
|
function validateOpts(curve) {
|
|
1322
1327
|
validateObject(curve, {
|
|
1323
1328
|
P: "bigint",
|
|
@@ -1437,7 +1442,7 @@ function montgomery(curveDef) {
|
|
|
1437
1442
|
}
|
|
1438
1443
|
var _0n5, _1n5, _2n3;
|
|
1439
1444
|
var init_montgomery = __esm({
|
|
1440
|
-
"
|
|
1445
|
+
"../../node_modules/@noble/curves/abstract/montgomery.js"() {
|
|
1441
1446
|
"use strict";
|
|
1442
1447
|
init_utils2();
|
|
1443
1448
|
init_curve();
|
|
@@ -1448,10 +1453,10 @@ var init_montgomery = __esm({
|
|
|
1448
1453
|
}
|
|
1449
1454
|
});
|
|
1450
1455
|
|
|
1451
|
-
//
|
|
1456
|
+
// ../../node_modules/@noble/hashes/_md.js
|
|
1452
1457
|
var HashMD, SHA512_IV;
|
|
1453
1458
|
var init_md = __esm({
|
|
1454
|
-
"
|
|
1459
|
+
"../../node_modules/@noble/hashes/_md.js"() {
|
|
1455
1460
|
"use strict";
|
|
1456
1461
|
init_utils();
|
|
1457
1462
|
HashMD = class {
|
|
@@ -1535,7 +1540,7 @@ var init_md = __esm({
|
|
|
1535
1540
|
return res;
|
|
1536
1541
|
}
|
|
1537
1542
|
_cloneInto(to) {
|
|
1538
|
-
to
|
|
1543
|
+
to ||= new this.constructor();
|
|
1539
1544
|
to.set(...this.get());
|
|
1540
1545
|
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
1541
1546
|
to.destroyed = destroyed;
|
|
@@ -1571,7 +1576,7 @@ var init_md = __esm({
|
|
|
1571
1576
|
}
|
|
1572
1577
|
});
|
|
1573
1578
|
|
|
1574
|
-
//
|
|
1579
|
+
// ../../node_modules/@noble/hashes/_u64.js
|
|
1575
1580
|
function fromBig(n, le = false) {
|
|
1576
1581
|
if (le)
|
|
1577
1582
|
return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
|
|
@@ -1593,7 +1598,7 @@ function add(Ah, Al, Bh, Bl) {
|
|
|
1593
1598
|
}
|
|
1594
1599
|
var U32_MASK64, _32n, shrSH, shrSL, rotrSH, rotrSL, rotrBH, rotrBL, rotlSH, rotlSL, rotlBH, rotlBL, add3L, add3H, add4L, add4H, add5L, add5H;
|
|
1595
1600
|
var init_u64 = __esm({
|
|
1596
|
-
"
|
|
1601
|
+
"../../node_modules/@noble/hashes/_u64.js"() {
|
|
1597
1602
|
"use strict";
|
|
1598
1603
|
U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
1599
1604
|
_32n = /* @__PURE__ */ BigInt(32);
|
|
@@ -1616,10 +1621,10 @@ var init_u64 = __esm({
|
|
|
1616
1621
|
}
|
|
1617
1622
|
});
|
|
1618
1623
|
|
|
1619
|
-
//
|
|
1624
|
+
// ../../node_modules/@noble/hashes/sha2.js
|
|
1620
1625
|
var K512, SHA512_Kh, SHA512_Kl, SHA512_W_H, SHA512_W_L, SHA2_64B, _SHA512, sha512;
|
|
1621
1626
|
var init_sha2 = __esm({
|
|
1622
|
-
"
|
|
1627
|
+
"../../node_modules/@noble/hashes/sha2.js"() {
|
|
1623
1628
|
"use strict";
|
|
1624
1629
|
init_md();
|
|
1625
1630
|
init_u64();
|
|
@@ -1834,7 +1839,7 @@ var init_sha2 = __esm({
|
|
|
1834
1839
|
}
|
|
1835
1840
|
});
|
|
1836
1841
|
|
|
1837
|
-
//
|
|
1842
|
+
// ../../node_modules/@noble/curves/abstract/fft.js
|
|
1838
1843
|
function checkU32(n) {
|
|
1839
1844
|
if (!Number.isSafeInteger(n) || n < 0 || n > 4294967295)
|
|
1840
1845
|
throw new Error("wrong u32 integer:" + n);
|
|
@@ -1874,7 +1879,7 @@ function bitReversalInplace(values) {
|
|
|
1874
1879
|
}
|
|
1875
1880
|
var FFTCore;
|
|
1876
1881
|
var init_fft = __esm({
|
|
1877
|
-
"
|
|
1882
|
+
"../../node_modules/@noble/curves/abstract/fft.js"() {
|
|
1878
1883
|
"use strict";
|
|
1879
1884
|
FFTCore = (F2, coreOpts) => {
|
|
1880
1885
|
const { N: N2, roots, dit, invertButterflies = false, skipStages = 0, brp = true } = coreOpts;
|
|
@@ -1925,7 +1930,7 @@ var init_fft = __esm({
|
|
|
1925
1930
|
}
|
|
1926
1931
|
});
|
|
1927
1932
|
|
|
1928
|
-
//
|
|
1933
|
+
// ../../node_modules/@noble/curves/abstract/hash-to-curve.js
|
|
1929
1934
|
function i2osp(value, length) {
|
|
1930
1935
|
asafenumber(value);
|
|
1931
1936
|
asafenumber(length);
|
|
@@ -1980,14 +1985,14 @@ function expand_message_xmd(msg, DST, lenInBytes, H) {
|
|
|
1980
1985
|
}
|
|
1981
1986
|
var _DST_scalar;
|
|
1982
1987
|
var init_hash_to_curve = __esm({
|
|
1983
|
-
"
|
|
1988
|
+
"../../node_modules/@noble/curves/abstract/hash-to-curve.js"() {
|
|
1984
1989
|
"use strict";
|
|
1985
1990
|
init_utils2();
|
|
1986
1991
|
_DST_scalar = "HashToScalar-";
|
|
1987
1992
|
}
|
|
1988
1993
|
});
|
|
1989
1994
|
|
|
1990
|
-
//
|
|
1995
|
+
// ../../node_modules/@noble/curves/ed25519.js
|
|
1991
1996
|
function ed25519_pow_2_252_3(x) {
|
|
1992
1997
|
const _10n = BigInt(10), _20n = BigInt(20), _40n = BigInt(40), _80n = BigInt(80);
|
|
1993
1998
|
const P = ed25519_CURVE_p;
|
|
@@ -2057,7 +2062,7 @@ function calcElligatorRistrettoMap(r0) {
|
|
|
2057
2062
|
}
|
|
2058
2063
|
var _0n6, _1n6, _2n4, _3n2, _5n2, _8n3, ed25519_CURVE_p, ed25519_CURVE, ED25519_SQRT_M1, ed25519_Point, Fp, Fn, x25519, SQRT_M1, SQRT_AD_MINUS_ONE, INVSQRT_A_MINUS_D, ONE_MINUS_D_SQ, D_MINUS_ONE_SQ, invertSqrt, MAX_255B, bytes255ToNumberLE, __RistrettoPoint, _RistrettoPoint, ristretto255_hasher;
|
|
2059
2064
|
var init_ed25519 = __esm({
|
|
2060
|
-
"
|
|
2065
|
+
"../../node_modules/@noble/curves/ed25519.js"() {
|
|
2061
2066
|
"use strict";
|
|
2062
2067
|
init_sha2();
|
|
2063
2068
|
init_utils();
|
|
@@ -2270,7 +2275,7 @@ var init_ed25519 = __esm({
|
|
|
2270
2275
|
}
|
|
2271
2276
|
});
|
|
2272
2277
|
|
|
2273
|
-
//
|
|
2278
|
+
// ../../node_modules/@noble/hashes/sha3.js
|
|
2274
2279
|
function keccakP(s, rounds = 24) {
|
|
2275
2280
|
anumber(rounds, "rounds");
|
|
2276
2281
|
if (rounds < 1 || rounds > 24)
|
|
@@ -2323,7 +2328,7 @@ function keccakP(s, rounds = 24) {
|
|
|
2323
2328
|
}
|
|
2324
2329
|
var _0n7, _1n7, _2n5, _7n2, _256n, _0x71n, SHA3_PI, SHA3_ROTL, _SHA3_IOTA, IOTAS, SHA3_IOTA_H, SHA3_IOTA_L, rotlH, rotlL, Keccak, genKeccak, sha3_256, sha3_512, genShake, shake128, shake256;
|
|
2325
2330
|
var init_sha3 = __esm({
|
|
2326
|
-
"
|
|
2331
|
+
"../../node_modules/@noble/hashes/sha3.js"() {
|
|
2327
2332
|
"use strict";
|
|
2328
2333
|
init_u64();
|
|
2329
2334
|
init_utils();
|
|
@@ -2458,7 +2463,7 @@ var init_sha3 = __esm({
|
|
|
2458
2463
|
}
|
|
2459
2464
|
_cloneInto(to) {
|
|
2460
2465
|
const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
|
|
2461
|
-
to
|
|
2466
|
+
to ||= new _Keccak(blockLen, suffix, outputLen, enableXOF, rounds);
|
|
2462
2467
|
to.blockLen = blockLen;
|
|
2463
2468
|
to.state32.set(this.state32);
|
|
2464
2469
|
to.pos = this.pos;
|
|
@@ -2492,7 +2497,7 @@ var init_sha3 = __esm({
|
|
|
2492
2497
|
}
|
|
2493
2498
|
});
|
|
2494
2499
|
|
|
2495
|
-
//
|
|
2500
|
+
// ../../node_modules/@noble/post-quantum/utils.js
|
|
2496
2501
|
function equalBytes2(a, b) {
|
|
2497
2502
|
if (a.length !== b.length)
|
|
2498
2503
|
return false;
|
|
@@ -2578,7 +2583,7 @@ function getMask(bits) {
|
|
|
2578
2583
|
}
|
|
2579
2584
|
var abytesDoc, randomBytes3;
|
|
2580
2585
|
var init_utils3 = __esm({
|
|
2581
|
-
"
|
|
2586
|
+
"../../node_modules/@noble/post-quantum/utils.js"() {
|
|
2582
2587
|
"use strict";
|
|
2583
2588
|
init_utils();
|
|
2584
2589
|
abytesDoc = abytes;
|
|
@@ -2586,10 +2591,10 @@ var init_utils3 = __esm({
|
|
|
2586
2591
|
}
|
|
2587
2592
|
});
|
|
2588
2593
|
|
|
2589
|
-
//
|
|
2594
|
+
// ../../node_modules/@noble/post-quantum/_crystals.js
|
|
2590
2595
|
var genCrystals, createXofShake, XOF128;
|
|
2591
2596
|
var init_crystals = __esm({
|
|
2592
|
-
"
|
|
2597
|
+
"../../node_modules/@noble/post-quantum/_crystals.js"() {
|
|
2593
2598
|
"use strict";
|
|
2594
2599
|
init_fft();
|
|
2595
2600
|
init_sha3();
|
|
@@ -2714,7 +2719,7 @@ var init_crystals = __esm({
|
|
|
2714
2719
|
}
|
|
2715
2720
|
});
|
|
2716
2721
|
|
|
2717
|
-
//
|
|
2722
|
+
// ../../node_modules/@noble/post-quantum/ml-kem.js
|
|
2718
2723
|
function polyAdd(a_, b_) {
|
|
2719
2724
|
const a = a_;
|
|
2720
2725
|
const b = b_;
|
|
@@ -2843,7 +2848,7 @@ function shakePRF(dkLen, key, nonce) {
|
|
|
2843
2848
|
}
|
|
2844
2849
|
var N, Q, F, ROOT_OF_UNITY, crystals, PARAMS, compress, byteCoder, polyCoder, sampleCBDBytes, genKPKE, opts, mk, ml_kem768;
|
|
2845
2850
|
var init_ml_kem = __esm({
|
|
2846
|
-
"
|
|
2851
|
+
"../../node_modules/@noble/post-quantum/ml-kem.js"() {
|
|
2847
2852
|
"use strict";
|
|
2848
2853
|
init_sha3();
|
|
2849
2854
|
init_utils();
|
|
@@ -3006,7 +3011,7 @@ var init_ml_kem = __esm({
|
|
|
3006
3011
|
}
|
|
3007
3012
|
});
|
|
3008
3013
|
|
|
3009
|
-
//
|
|
3014
|
+
// ../../node_modules/@noble/post-quantum/hybrid.js
|
|
3010
3015
|
function ecKeygen(curve, allowZeroKey = false) {
|
|
3011
3016
|
const lengths = curve.lengths;
|
|
3012
3017
|
let keygen = curve.keygen;
|
|
@@ -3177,7 +3182,7 @@ function combineKEMS(realSeedLen, realMsgLen, expandSeed, combiner, ...kems) {
|
|
|
3177
3182
|
}
|
|
3178
3183
|
var x25519kem, ml_kem768_x25519, XWing;
|
|
3179
3184
|
var init_hybrid = __esm({
|
|
3180
|
-
"
|
|
3185
|
+
"../../node_modules/@noble/post-quantum/hybrid.js"() {
|
|
3181
3186
|
"use strict";
|
|
3182
3187
|
init_ed25519();
|
|
3183
3188
|
init_utils2();
|
|
@@ -3217,11 +3222,48 @@ var init_replay_window = __esm({
|
|
|
3217
3222
|
});
|
|
3218
3223
|
|
|
3219
3224
|
// ../crypto/src/safe-url.ts
|
|
3225
|
+
function parseIPv4Component(raw) {
|
|
3226
|
+
if (raw.length === 0) return null;
|
|
3227
|
+
let value;
|
|
3228
|
+
if (/^0[xX][0-9a-fA-F]+$/.test(raw)) value = Number.parseInt(raw.slice(2), 16);
|
|
3229
|
+
else if (/^0[0-7]+$/.test(raw)) value = Number.parseInt(raw.slice(1), 8);
|
|
3230
|
+
else if (/^\d+$/.test(raw)) value = Number.parseInt(raw, 10);
|
|
3231
|
+
else return null;
|
|
3232
|
+
return Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
3233
|
+
}
|
|
3234
|
+
function canonicalIPv4Octets(host) {
|
|
3235
|
+
const raw = host.split(".");
|
|
3236
|
+
if (raw.length < 1 || raw.length > 4) return null;
|
|
3237
|
+
const vals = [];
|
|
3238
|
+
for (const part of raw) {
|
|
3239
|
+
const v = parseIPv4Component(part);
|
|
3240
|
+
if (v === null) return null;
|
|
3241
|
+
vals.push(v);
|
|
3242
|
+
}
|
|
3243
|
+
const n = vals.length;
|
|
3244
|
+
for (let i = 0; i < n - 1; i++) if (vals[i] > 255) return null;
|
|
3245
|
+
const remainingBytes = 4 - (n - 1);
|
|
3246
|
+
const max = remainingBytes >= 4 ? 4294967295 : 256 ** remainingBytes - 1;
|
|
3247
|
+
if (vals[n - 1] > max) return null;
|
|
3248
|
+
let value = 0;
|
|
3249
|
+
for (let i = 0; i < n - 1; i++) value += vals[i] * 256 ** (3 - i);
|
|
3250
|
+
value += vals[n - 1];
|
|
3251
|
+
if (value > 4294967295) return null;
|
|
3252
|
+
return [value >>> 24 & 255, value >>> 16 & 255, value >>> 8 & 255, value & 255];
|
|
3253
|
+
}
|
|
3254
|
+
function looksLikeNumericLiteral(host) {
|
|
3255
|
+
return /^[\d.]+$/.test(host) || /^0[xX][0-9a-fA-F.]+$/.test(host);
|
|
3256
|
+
}
|
|
3257
|
+
function isIpLiteralHost(host) {
|
|
3258
|
+
const clean2 = host.toLowerCase();
|
|
3259
|
+
if (clean2.includes(":")) return true;
|
|
3260
|
+
return canonicalIPv4Octets(clean2) !== null || looksLikeNumericLiteral(clean2);
|
|
3261
|
+
}
|
|
3220
3262
|
function isBlockedIPv4(host) {
|
|
3221
|
-
const
|
|
3222
|
-
if (
|
|
3223
|
-
|
|
3224
|
-
|
|
3263
|
+
const octets = canonicalIPv4Octets(host);
|
|
3264
|
+
if (!octets) {
|
|
3265
|
+
return looksLikeNumericLiteral(host);
|
|
3266
|
+
}
|
|
3225
3267
|
const [a, b] = octets;
|
|
3226
3268
|
if (a === 0) return true;
|
|
3227
3269
|
if (a === 127) return true;
|
|
@@ -3322,10 +3364,212 @@ var init_safe_url = __esm({
|
|
|
3322
3364
|
}
|
|
3323
3365
|
});
|
|
3324
3366
|
|
|
3367
|
+
// ../crypto/src/partner-key-attestation.ts
|
|
3368
|
+
function assertNoDelimiter(field, value) {
|
|
3369
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
3370
|
+
throw new Error(`[partner-key-attestation] ${field} must be a non-empty string`);
|
|
3371
|
+
}
|
|
3372
|
+
if (value.includes("\n") || value.includes("\r")) {
|
|
3373
|
+
throw new Error(`[partner-key-attestation] ${field} must not contain a line break`);
|
|
3374
|
+
}
|
|
3375
|
+
}
|
|
3376
|
+
function buildPartnerKeyAttestation(input) {
|
|
3377
|
+
assertNoDelimiter("partnerId", input.partnerId);
|
|
3378
|
+
assertNoDelimiter("keyId", input.keyId);
|
|
3379
|
+
assertNoDelimiter("algorithm", input.algorithm);
|
|
3380
|
+
assertNoDelimiter("publicKeyB64", input.publicKeyB64);
|
|
3381
|
+
return [
|
|
3382
|
+
PARTNER_KEY_ATTESTATION_V1,
|
|
3383
|
+
`partner_id:${input.partnerId.toLowerCase()}`,
|
|
3384
|
+
`key_id:${input.keyId.toLowerCase()}`,
|
|
3385
|
+
`algorithm:${input.algorithm}`,
|
|
3386
|
+
`public_key:${input.publicKeyB64}`
|
|
3387
|
+
].join("\n");
|
|
3388
|
+
}
|
|
3389
|
+
function b64ToBytes(b64) {
|
|
3390
|
+
const normalised = b64.replace(/-/g, "+").replace(/_/g, "/");
|
|
3391
|
+
const binary = atob(normalised);
|
|
3392
|
+
const out = new Uint8Array(binary.length);
|
|
3393
|
+
for (let i = 0; i < binary.length; i++) out[i] = binary.charCodeAt(i);
|
|
3394
|
+
return out;
|
|
3395
|
+
}
|
|
3396
|
+
function hexToBytes3(hex) {
|
|
3397
|
+
if (hex.length % 2 !== 0) throw new Error("[partner-key-attestation] hex string has odd length");
|
|
3398
|
+
const out = new Uint8Array(hex.length / 2);
|
|
3399
|
+
for (let i = 0; i < out.length; i++) {
|
|
3400
|
+
const byte = Number.parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
3401
|
+
if (Number.isNaN(byte)) throw new Error("[partner-key-attestation] invalid hex");
|
|
3402
|
+
out[i] = byte;
|
|
3403
|
+
}
|
|
3404
|
+
return out;
|
|
3405
|
+
}
|
|
3406
|
+
function bytesToHex3(bytes) {
|
|
3407
|
+
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
3408
|
+
}
|
|
3409
|
+
async function rootKeyIdFromSpki(spki) {
|
|
3410
|
+
const digest = await crypto.subtle.digest("SHA-256", spki);
|
|
3411
|
+
return `rk1_${bytesToHex3(new Uint8Array(digest)).slice(0, 16)}`;
|
|
3412
|
+
}
|
|
3413
|
+
async function rootKeyIdFromSpkiB64(spkiB64) {
|
|
3414
|
+
return rootKeyIdFromSpki(b64ToBytes(spkiB64));
|
|
3415
|
+
}
|
|
3416
|
+
async function verifyPartnerKeyAttestation(input, signatureHex, rootPublicKeyB64) {
|
|
3417
|
+
try {
|
|
3418
|
+
if (typeof signatureHex !== "string" || !/^[0-9a-f]{128}$/i.test(signatureHex)) return false;
|
|
3419
|
+
const statement = buildPartnerKeyAttestation(input);
|
|
3420
|
+
const rootKey = await crypto.subtle.importKey(
|
|
3421
|
+
"spki",
|
|
3422
|
+
b64ToBytes(rootPublicKeyB64),
|
|
3423
|
+
{ name: "ECDSA", namedCurve: "P-256" },
|
|
3424
|
+
false,
|
|
3425
|
+
["verify"]
|
|
3426
|
+
);
|
|
3427
|
+
return await crypto.subtle.verify(
|
|
3428
|
+
{ name: "ECDSA", hash: "SHA-256" },
|
|
3429
|
+
rootKey,
|
|
3430
|
+
hexToBytes3(signatureHex),
|
|
3431
|
+
new TextEncoder().encode(statement)
|
|
3432
|
+
);
|
|
3433
|
+
} catch {
|
|
3434
|
+
return false;
|
|
3435
|
+
}
|
|
3436
|
+
}
|
|
3437
|
+
async function verifyPartnerKeyAttestationWithRoots(input, signatureHex, rootKeyId, roots) {
|
|
3438
|
+
const root = roots.find((r) => r.root_key_id === rootKeyId);
|
|
3439
|
+
if (!root) return false;
|
|
3440
|
+
if (root.algorithm !== PARTNER_KEY_ATTESTATION_ALG) return false;
|
|
3441
|
+
return verifyPartnerKeyAttestation(input, signatureHex, root.public_key_b64);
|
|
3442
|
+
}
|
|
3443
|
+
var PARTNER_KEY_ATTESTATION_V1, PARTNER_KEY_ATTESTATION_ALG;
|
|
3444
|
+
var init_partner_key_attestation = __esm({
|
|
3445
|
+
"../crypto/src/partner-key-attestation.ts"() {
|
|
3446
|
+
"use strict";
|
|
3447
|
+
PARTNER_KEY_ATTESTATION_V1 = "oneaddress-partner-key-attestation:v1";
|
|
3448
|
+
PARTNER_KEY_ATTESTATION_ALG = "ECDSA-P256";
|
|
3449
|
+
}
|
|
3450
|
+
});
|
|
3451
|
+
|
|
3452
|
+
// ../crypto/src/registry-head.ts
|
|
3453
|
+
function assertNoLineBreak(field, value) {
|
|
3454
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
3455
|
+
throw new Error(`[registry-head] ${field} must be a non-empty string`);
|
|
3456
|
+
}
|
|
3457
|
+
if (value.includes("\n") || value.includes("\r")) {
|
|
3458
|
+
throw new Error(`[registry-head] ${field} must not contain a line break`);
|
|
3459
|
+
}
|
|
3460
|
+
}
|
|
3461
|
+
function assertMapSafe(field, value) {
|
|
3462
|
+
assertNoLineBreak(field, value);
|
|
3463
|
+
if (value.includes(":")) {
|
|
3464
|
+
throw new Error(`[registry-head] ${field} must not contain a colon`);
|
|
3465
|
+
}
|
|
3466
|
+
}
|
|
3467
|
+
function buildRegistryHeadStatement(payload) {
|
|
3468
|
+
assertNoLineBreak("issued_at", payload.issued_at);
|
|
3469
|
+
assertNoLineBreak("expires_at", payload.expires_at);
|
|
3470
|
+
assertMapSafe("root_key_id", payload.root_key_id);
|
|
3471
|
+
const entries = Object.entries(payload.heads).map(([partnerId, keyId]) => {
|
|
3472
|
+
assertMapSafe("partner_id", partnerId);
|
|
3473
|
+
assertMapSafe("key_id", keyId);
|
|
3474
|
+
return [partnerId.toLowerCase(), keyId.toLowerCase()];
|
|
3475
|
+
});
|
|
3476
|
+
entries.sort((a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0);
|
|
3477
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3478
|
+
for (const [partnerId] of entries) {
|
|
3479
|
+
if (seen.has(partnerId)) {
|
|
3480
|
+
throw new Error(`[registry-head] duplicate partner_id in heads: ${partnerId}`);
|
|
3481
|
+
}
|
|
3482
|
+
seen.add(partnerId);
|
|
3483
|
+
}
|
|
3484
|
+
return [
|
|
3485
|
+
REGISTRY_HEAD_V1,
|
|
3486
|
+
`issued_at:${payload.issued_at}`,
|
|
3487
|
+
`expires_at:${payload.expires_at}`,
|
|
3488
|
+
`root_key_id:${payload.root_key_id}`,
|
|
3489
|
+
`heads:${entries.length}`,
|
|
3490
|
+
...entries.map(([partnerId, keyId]) => `${partnerId}:${keyId}`)
|
|
3491
|
+
].join("\n");
|
|
3492
|
+
}
|
|
3493
|
+
function b64ToBytes2(b64) {
|
|
3494
|
+
const normalised = b64.replace(/-/g, "+").replace(/_/g, "/");
|
|
3495
|
+
const binary = atob(normalised);
|
|
3496
|
+
const out = new Uint8Array(binary.length);
|
|
3497
|
+
for (let i = 0; i < binary.length; i++) out[i] = binary.charCodeAt(i);
|
|
3498
|
+
return out;
|
|
3499
|
+
}
|
|
3500
|
+
function hexToBytes4(hex) {
|
|
3501
|
+
if (hex.length % 2 !== 0) throw new Error("[registry-head] hex string has odd length");
|
|
3502
|
+
const out = new Uint8Array(hex.length / 2);
|
|
3503
|
+
for (let i = 0; i < out.length; i++) {
|
|
3504
|
+
const byte = Number.parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
3505
|
+
if (Number.isNaN(byte)) throw new Error("[registry-head] invalid hex");
|
|
3506
|
+
out[i] = byte;
|
|
3507
|
+
}
|
|
3508
|
+
return out;
|
|
3509
|
+
}
|
|
3510
|
+
async function verifyRegistryHead(doc, roots, now = /* @__PURE__ */ new Date()) {
|
|
3511
|
+
try {
|
|
3512
|
+
if (doc?.version !== REGISTRY_HEAD_V1) return "malformed";
|
|
3513
|
+
if (doc.algorithm !== REGISTRY_HEAD_ALG) return "malformed";
|
|
3514
|
+
if (typeof doc.signature !== "string" || !/^[0-9a-f]{128}$/i.test(doc.signature)) return "malformed";
|
|
3515
|
+
if (!doc.heads || typeof doc.heads !== "object") return "malformed";
|
|
3516
|
+
const expires = Date.parse(doc.expires_at);
|
|
3517
|
+
const issued = Date.parse(doc.issued_at);
|
|
3518
|
+
if (Number.isNaN(expires) || Number.isNaN(issued)) return "malformed";
|
|
3519
|
+
const root = roots.find((r) => r.root_key_id === doc.root_key_id);
|
|
3520
|
+
if (!root) return "unknown-root";
|
|
3521
|
+
if (root.algorithm !== REGISTRY_HEAD_ALG) return "malformed";
|
|
3522
|
+
const statement = buildRegistryHeadStatement({
|
|
3523
|
+
version: doc.version,
|
|
3524
|
+
issued_at: doc.issued_at,
|
|
3525
|
+
expires_at: doc.expires_at,
|
|
3526
|
+
root_key_id: doc.root_key_id,
|
|
3527
|
+
heads: doc.heads
|
|
3528
|
+
});
|
|
3529
|
+
const rootKey = await crypto.subtle.importKey(
|
|
3530
|
+
"spki",
|
|
3531
|
+
b64ToBytes2(root.public_key_b64),
|
|
3532
|
+
{ name: "ECDSA", namedCurve: "P-256" },
|
|
3533
|
+
false,
|
|
3534
|
+
["verify"]
|
|
3535
|
+
);
|
|
3536
|
+
const valid = await crypto.subtle.verify(
|
|
3537
|
+
{ name: "ECDSA", hash: "SHA-256" },
|
|
3538
|
+
rootKey,
|
|
3539
|
+
hexToBytes4(doc.signature),
|
|
3540
|
+
new TextEncoder().encode(statement)
|
|
3541
|
+
);
|
|
3542
|
+
if (!valid) return "bad-signature";
|
|
3543
|
+
if (now.getTime() >= expires) return "expired";
|
|
3544
|
+
return "ok";
|
|
3545
|
+
} catch {
|
|
3546
|
+
return "malformed";
|
|
3547
|
+
}
|
|
3548
|
+
}
|
|
3549
|
+
function headNamesKey(doc, partnerId, keyId) {
|
|
3550
|
+
const named = doc.heads?.[partnerId.toLowerCase()];
|
|
3551
|
+
return typeof named === "string" && named.toLowerCase() === keyId.toLowerCase();
|
|
3552
|
+
}
|
|
3553
|
+
var REGISTRY_HEAD_V1, REGISTRY_HEAD_ALG;
|
|
3554
|
+
var init_registry_head = __esm({
|
|
3555
|
+
"../crypto/src/registry-head.ts"() {
|
|
3556
|
+
"use strict";
|
|
3557
|
+
REGISTRY_HEAD_V1 = "oneaddress-partner-key-registry-head:v1";
|
|
3558
|
+
REGISTRY_HEAD_ALG = "ECDSA-P256";
|
|
3559
|
+
}
|
|
3560
|
+
});
|
|
3561
|
+
|
|
3325
3562
|
// ../crypto/src/index.ts
|
|
3326
3563
|
var src_exports = {};
|
|
3327
3564
|
__export(src_exports, {
|
|
3328
3565
|
DEFAULT_REPLAY_WINDOW_SECS: () => DEFAULT_REPLAY_WINDOW_SECS,
|
|
3566
|
+
PARTNER_KEY_ATTESTATION_ALG: () => PARTNER_KEY_ATTESTATION_ALG,
|
|
3567
|
+
PARTNER_KEY_ATTESTATION_V1: () => PARTNER_KEY_ATTESTATION_V1,
|
|
3568
|
+
REGISTRY_HEAD_ALG: () => REGISTRY_HEAD_ALG,
|
|
3569
|
+
REGISTRY_HEAD_V1: () => REGISTRY_HEAD_V1,
|
|
3570
|
+
buildPartnerKeyAttestation: () => buildPartnerKeyAttestation,
|
|
3571
|
+
buildRegistryHeadStatement: () => buildRegistryHeadStatement,
|
|
3572
|
+
cleanNameAliases: () => cleanNameAliases,
|
|
3329
3573
|
computeBlindIndex: () => computeBlindIndex,
|
|
3330
3574
|
computeCustomerBlindIndex: () => computeCustomerBlindIndex,
|
|
3331
3575
|
decryptAddress: () => decryptAddress,
|
|
@@ -3338,19 +3582,37 @@ __export(src_exports, {
|
|
|
3338
3582
|
encryptSessionForPartner: () => encryptSessionForPartner,
|
|
3339
3583
|
generateHybridPartnerKeyPair: () => generateHybridPartnerKeyPair,
|
|
3340
3584
|
generatePartnerKeyPair: () => generatePartnerKeyPair,
|
|
3585
|
+
headNamesKey: () => headNamesKey,
|
|
3586
|
+
isEmailLike: () => isEmailLike,
|
|
3341
3587
|
isFreshTimestamp: () => isFreshTimestamp,
|
|
3588
|
+
isIpLiteralHost: () => isIpLiteralHost,
|
|
3342
3589
|
isSafeWebhookUrl: () => isSafeWebhookUrl,
|
|
3343
3590
|
normaliseAddress: () => normaliseAddress,
|
|
3344
3591
|
normalizeForBlindIndex: () => normalizeForBlindIndex,
|
|
3592
|
+
rootKeyIdFromSpki: () => rootKeyIdFromSpki,
|
|
3593
|
+
rootKeyIdFromSpkiB64: () => rootKeyIdFromSpkiB64,
|
|
3345
3594
|
signWebhookPayload: () => signWebhookPayload,
|
|
3595
|
+
verifyPartnerKeyAttestation: () => verifyPartnerKeyAttestation,
|
|
3596
|
+
verifyPartnerKeyAttestationWithRoots: () => verifyPartnerKeyAttestationWithRoots,
|
|
3597
|
+
verifyRegistryHead: () => verifyRegistryHead,
|
|
3346
3598
|
verifyWebhookSignature: () => verifyWebhookSignature
|
|
3347
3599
|
});
|
|
3348
|
-
function
|
|
3600
|
+
function b64ToBytes3(b64) {
|
|
3349
3601
|
const binary = atob(b64);
|
|
3350
3602
|
const bytes = new Uint8Array(binary.length);
|
|
3351
3603
|
for (let i = 0; i < binary.length; i++) bytes[i] = binary.codePointAt(i) ?? 0;
|
|
3352
3604
|
return bytes;
|
|
3353
3605
|
}
|
|
3606
|
+
function keyB64ToBytes(key) {
|
|
3607
|
+
const begin = key.indexOf("-----BEGIN");
|
|
3608
|
+
if (begin === -1) return b64ToBytes3(key.replace(/\s+/g, ""));
|
|
3609
|
+
const armourEnd = key.indexOf("-----", begin + "-----BEGIN".length);
|
|
3610
|
+
if (armourEnd === -1) return b64ToBytes3(key.replace(/\s+/g, ""));
|
|
3611
|
+
const bodyStart = armourEnd + "-----".length;
|
|
3612
|
+
const end = key.indexOf("-----END", bodyStart);
|
|
3613
|
+
const body = end === -1 ? key.slice(bodyStart) : key.slice(bodyStart, end);
|
|
3614
|
+
return b64ToBytes3(body.replace(/\s+/g, ""));
|
|
3615
|
+
}
|
|
3354
3616
|
function bytesToB64(bytes) {
|
|
3355
3617
|
return btoa(String.fromCodePoint(...bytes));
|
|
3356
3618
|
}
|
|
@@ -3433,7 +3695,7 @@ function generateHybridPartnerKeyPair() {
|
|
|
3433
3695
|
}
|
|
3434
3696
|
async function encryptAddressForPartner(address, partner) {
|
|
3435
3697
|
const address_ = normaliseAddress(address);
|
|
3436
|
-
const partnerPubKey = await importP256PublicKey(
|
|
3698
|
+
const partnerPubKey = await importP256PublicKey(b64ToBytes3(partner.publicKeyB64));
|
|
3437
3699
|
const ephemeral = await subtle().generateKey(
|
|
3438
3700
|
{ name: "ECDH", namedCurve: "P-256" },
|
|
3439
3701
|
true,
|
|
@@ -3481,7 +3743,7 @@ async function encryptAddressForPartner(address, partner) {
|
|
|
3481
3743
|
};
|
|
3482
3744
|
}
|
|
3483
3745
|
async function encryptPayloadForPartner(payload, partner) {
|
|
3484
|
-
const partnerPubKey = await importP256PublicKey(
|
|
3746
|
+
const partnerPubKey = await importP256PublicKey(b64ToBytes3(partner.publicKeyB64));
|
|
3485
3747
|
const ephemeral = await subtle().generateKey(
|
|
3486
3748
|
{ name: "ECDH", namedCurve: "P-256" },
|
|
3487
3749
|
true,
|
|
@@ -3527,14 +3789,14 @@ async function encryptAddressForAll(address, partners) {
|
|
|
3527
3789
|
async function decryptAddress(encrypted, privateKeyB64) {
|
|
3528
3790
|
const privateKey = await subtle().importKey(
|
|
3529
3791
|
"pkcs8",
|
|
3530
|
-
|
|
3792
|
+
keyB64ToBytes(privateKeyB64),
|
|
3531
3793
|
{ name: "ECDH", namedCurve: "P-256" },
|
|
3532
3794
|
false,
|
|
3533
3795
|
["deriveBits"]
|
|
3534
3796
|
);
|
|
3535
3797
|
const ephemeralPub = await subtle().importKey(
|
|
3536
3798
|
"raw",
|
|
3537
|
-
|
|
3799
|
+
b64ToBytes3(encrypted.ephemeralPublicKey),
|
|
3538
3800
|
{ name: "ECDH", namedCurve: "P-256" },
|
|
3539
3801
|
false,
|
|
3540
3802
|
[]
|
|
@@ -3544,7 +3806,7 @@ async function decryptAddress(encrypted, privateKeyB64) {
|
|
|
3544
3806
|
privateKey,
|
|
3545
3807
|
256
|
|
3546
3808
|
);
|
|
3547
|
-
const hkdfSalt = encrypted.hkdfSalt ?
|
|
3809
|
+
const hkdfSalt = encrypted.hkdfSalt ? b64ToBytes3(encrypted.hkdfSalt) : new Uint8Array(32);
|
|
3548
3810
|
const aesKey = await subtle().importKey(
|
|
3549
3811
|
"raw",
|
|
3550
3812
|
await subtle().deriveBits(
|
|
@@ -3562,9 +3824,9 @@ async function decryptAddress(encrypted, privateKeyB64) {
|
|
|
3562
3824
|
["decrypt"]
|
|
3563
3825
|
);
|
|
3564
3826
|
const plainBuf = await subtle().decrypt(
|
|
3565
|
-
{ name: "AES-GCM", iv:
|
|
3827
|
+
{ name: "AES-GCM", iv: b64ToBytes3(encrypted.iv) },
|
|
3566
3828
|
aesKey,
|
|
3567
|
-
|
|
3829
|
+
b64ToBytes3(encrypted.ciphertext)
|
|
3568
3830
|
);
|
|
3569
3831
|
return JSON.parse(new TextDecoder().decode(plainBuf));
|
|
3570
3832
|
}
|
|
@@ -3589,7 +3851,7 @@ function bytesToB64Url(bytes) {
|
|
|
3589
3851
|
}
|
|
3590
3852
|
function b64UrlToBytes(b64url) {
|
|
3591
3853
|
const pad = b64url.length % 4 === 0 ? "" : "=".repeat(4 - b64url.length % 4);
|
|
3592
|
-
return
|
|
3854
|
+
return b64ToBytes3(b64url.replace(/-/g, "+").replace(/_/g, "/") + pad);
|
|
3593
3855
|
}
|
|
3594
3856
|
async function encryptSessionForPartner(session_data, partner) {
|
|
3595
3857
|
return encryptEnvelopeForPartner(session_data, partner);
|
|
@@ -3608,7 +3870,7 @@ async function encryptEnvelopeForPartner(payload, partner) {
|
|
|
3608
3870
|
const session_envelope = bytesToB64Url(concat(sessionIv, sessionCt));
|
|
3609
3871
|
const skRawForWrap = new Uint8Array(await subtle().exportKey("raw", sk));
|
|
3610
3872
|
if (isHybridScheme(partner.algorithm)) {
|
|
3611
|
-
const { cipherText: kemCt, sharedSecret: sharedSecret2 } = XWing.encapsulate(
|
|
3873
|
+
const { cipherText: kemCt, sharedSecret: sharedSecret2 } = XWing.encapsulate(b64ToBytes3(partner.public_key_b64));
|
|
3612
3874
|
const wrapSalt2 = globalThis.crypto.getRandomValues(new Uint8Array(WRAP_SALT_LENGTH));
|
|
3613
3875
|
const wrapKeyRaw2 = await subtle().deriveBits(
|
|
3614
3876
|
{ name: "HKDF", hash: "SHA-256", salt: wrapSalt2, info: sessionWrapInfoPq(partner.partner_id) },
|
|
@@ -3635,7 +3897,7 @@ async function encryptEnvelopeForPartner(payload, partner) {
|
|
|
3635
3897
|
};
|
|
3636
3898
|
}
|
|
3637
3899
|
if (isRsaScheme(partner.algorithm)) {
|
|
3638
|
-
const partnerRsaPub = await importRsaOaepPublicKey(
|
|
3900
|
+
const partnerRsaPub = await importRsaOaepPublicKey(b64ToBytes3(partner.public_key_b64));
|
|
3639
3901
|
const rsaWrapped = new Uint8Array(
|
|
3640
3902
|
await subtle().encrypt({ name: "RSA-OAEP" }, partnerRsaPub, skRawForWrap)
|
|
3641
3903
|
);
|
|
@@ -3652,7 +3914,7 @@ async function encryptEnvelopeForPartner(payload, partner) {
|
|
|
3652
3914
|
}
|
|
3653
3915
|
};
|
|
3654
3916
|
}
|
|
3655
|
-
const partnerPub = await importP256PublicKey(
|
|
3917
|
+
const partnerPub = await importP256PublicKey(b64ToBytes3(partner.public_key_b64));
|
|
3656
3918
|
const ephemeral = await subtle().generateKey(
|
|
3657
3919
|
{ name: "ECDH", namedCurve: "P-256" },
|
|
3658
3920
|
true,
|
|
@@ -3719,7 +3981,7 @@ async function decryptSession(share, envelopeB64, privateKeyB64, partnerId) {
|
|
|
3719
3981
|
if (!share.epk) {
|
|
3720
3982
|
throw new Error("decryptSession: hybrid share missing epk (KEM ciphertext)");
|
|
3721
3983
|
}
|
|
3722
|
-
const sharedSecret = XWing.decapsulate(b64UrlToBytes(share.epk),
|
|
3984
|
+
const sharedSecret = XWing.decapsulate(b64UrlToBytes(share.epk), b64ToBytes3(privateKeyB64));
|
|
3723
3985
|
const wrappedBytes = b64UrlToBytes(share.wrapped_key);
|
|
3724
3986
|
if (wrappedBytes.length < WRAP_SALT_LENGTH + WRAP_IV_LENGTH + 16) {
|
|
3725
3987
|
throw new Error("decryptSession: wrapped_key too short");
|
|
@@ -3737,7 +3999,7 @@ async function decryptSession(share, envelopeB64, privateKeyB64, partnerId) {
|
|
|
3737
3999
|
} else if (share.alg === "RSA-OAEP-256+A256GCM") {
|
|
3738
4000
|
const rsaPrivateKey = await subtle().importKey(
|
|
3739
4001
|
"pkcs8",
|
|
3740
|
-
|
|
4002
|
+
keyB64ToBytes(privateKeyB64),
|
|
3741
4003
|
{ name: "RSA-OAEP", hash: "SHA-256" },
|
|
3742
4004
|
false,
|
|
3743
4005
|
["decrypt"]
|
|
@@ -3753,7 +4015,7 @@ async function decryptSession(share, envelopeB64, privateKeyB64, partnerId) {
|
|
|
3753
4015
|
}
|
|
3754
4016
|
const privateKey = await subtle().importKey(
|
|
3755
4017
|
"pkcs8",
|
|
3756
|
-
|
|
4018
|
+
keyB64ToBytes(privateKeyB64),
|
|
3757
4019
|
{ name: "ECDH", namedCurve: "P-256" },
|
|
3758
4020
|
false,
|
|
3759
4021
|
["deriveBits"]
|
|
@@ -3820,6 +4082,28 @@ async function decryptSession(share, envelopeB64, privateKeyB64, partnerId) {
|
|
|
3820
4082
|
);
|
|
3821
4083
|
return JSON.parse(new TextDecoder().decode(plainBuf));
|
|
3822
4084
|
}
|
|
4085
|
+
function isEmailLike(value) {
|
|
4086
|
+
return value.includes("@");
|
|
4087
|
+
}
|
|
4088
|
+
function cleanNameAliases(primaryName, aliases, limit = 10) {
|
|
4089
|
+
const out = [];
|
|
4090
|
+
if (!Array.isArray(aliases)) return out;
|
|
4091
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4092
|
+
const primary = (primaryName ?? "").trim().toLowerCase();
|
|
4093
|
+
if (primary) seen.add(primary);
|
|
4094
|
+
for (const raw of aliases) {
|
|
4095
|
+
if (typeof raw !== "string") continue;
|
|
4096
|
+
const trimmed = raw.trim();
|
|
4097
|
+
if (!trimmed) continue;
|
|
4098
|
+
if (isEmailLike(trimmed)) continue;
|
|
4099
|
+
const key = trimmed.toLowerCase();
|
|
4100
|
+
if (seen.has(key)) continue;
|
|
4101
|
+
seen.add(key);
|
|
4102
|
+
out.push(trimmed);
|
|
4103
|
+
if (out.length >= limit) break;
|
|
4104
|
+
}
|
|
4105
|
+
return out;
|
|
4106
|
+
}
|
|
3823
4107
|
function normalizeForBlindIndex(field, value) {
|
|
3824
4108
|
const base = value.normalize("NFKC").trim();
|
|
3825
4109
|
switch (field) {
|
|
@@ -3853,15 +4137,15 @@ async function computeCustomerBlindIndex(secret, fields) {
|
|
|
3853
4137
|
out.account_number = await computeBlindIndex(secret, "account_number", fields.account_number);
|
|
3854
4138
|
}
|
|
3855
4139
|
const nameValues = [];
|
|
3856
|
-
if (fields.name && fields.name.trim()) nameValues.push(fields.name);
|
|
4140
|
+
if (fields.name && fields.name.trim() && !isEmailLike(fields.name)) nameValues.push(fields.name);
|
|
3857
4141
|
for (const n of fields.known_names ?? []) {
|
|
3858
|
-
if (n && n.trim()) nameValues.push(n);
|
|
4142
|
+
if (n && n.trim() && !isEmailLike(n)) nameValues.push(n);
|
|
3859
4143
|
}
|
|
3860
4144
|
const seen = /* @__PURE__ */ new Set();
|
|
3861
4145
|
for (const v of nameValues) {
|
|
3862
|
-
const
|
|
3863
|
-
if (seen.has(
|
|
3864
|
-
seen.add(
|
|
4146
|
+
const norm2 = normalizeForBlindIndex("name", v);
|
|
4147
|
+
if (seen.has(norm2)) continue;
|
|
4148
|
+
seen.add(norm2);
|
|
3865
4149
|
out.names.push(await computeBlindIndex(secret, "name", v));
|
|
3866
4150
|
}
|
|
3867
4151
|
return out;
|
|
@@ -3898,6 +4182,8 @@ var init_src = __esm({
|
|
|
3898
4182
|
init_hybrid();
|
|
3899
4183
|
init_replay_window();
|
|
3900
4184
|
init_safe_url();
|
|
4185
|
+
init_partner_key_attestation();
|
|
4186
|
+
init_registry_head();
|
|
3901
4187
|
subtle = () => globalThis.crypto.subtle;
|
|
3902
4188
|
AU_STATE_FULL = {
|
|
3903
4189
|
"new south wales": "NSW",
|
|
@@ -3934,15 +4220,24 @@ __export(index_exports, {
|
|
|
3934
4220
|
canonicalD5LoaForm: () => canonicalD5LoaForm,
|
|
3935
4221
|
compareAddresses: () => compareAddresses,
|
|
3936
4222
|
computeBlindIndex: () => computeBlindIndex,
|
|
4223
|
+
confirmUpdate: () => confirmUpdate,
|
|
3937
4224
|
createOneAddressHandler: () => createOneAddressHandler,
|
|
4225
|
+
createSqlIdempotencyStore: () => createSqlIdempotencyStore,
|
|
3938
4226
|
d5LoaRef: () => d5LoaRef,
|
|
3939
4227
|
decrypt: () => decryptAddress2,
|
|
3940
4228
|
decryptAddress: () => decryptAddress2,
|
|
3941
4229
|
decryptLoaEncrypted: () => decryptLoaEncrypted,
|
|
3942
4230
|
decryptSession: () => decryptSession2,
|
|
3943
4231
|
fetchLoaPublicKey: () => fetchLoaPublicKey,
|
|
4232
|
+
findMatchingStoredName: () => findMatchingStoredName,
|
|
4233
|
+
formatAddressParts: () => formatAddressParts,
|
|
4234
|
+
isEmailLike: () => isEmailLike2,
|
|
3944
4235
|
isFreshTimestamp: () => isFreshTimestamp,
|
|
4236
|
+
namePoolMatches: () => namePoolMatches,
|
|
3945
4237
|
normalizeForBlindIndex: () => normalizeForBlindIndex,
|
|
4238
|
+
readAddressParts: () => readAddressParts,
|
|
4239
|
+
sendVerifyResult: () => sendVerifyResult,
|
|
4240
|
+
toExpressHandler: () => toExpressHandler,
|
|
3946
4241
|
transform: () => transformAddress,
|
|
3947
4242
|
transformAddress: () => transformAddress,
|
|
3948
4243
|
transformSession: () => transformSession,
|
|
@@ -3965,6 +4260,93 @@ var SUPPORTED_VERSIONS = ["2026.1"];
|
|
|
3965
4260
|
// src/index.ts
|
|
3966
4261
|
init_src();
|
|
3967
4262
|
init_src();
|
|
4263
|
+
|
|
4264
|
+
// ../name-match/src/index.ts
|
|
4265
|
+
function isEmailLike2(value) {
|
|
4266
|
+
return value.includes("@");
|
|
4267
|
+
}
|
|
4268
|
+
function stripDiacritics(s) {
|
|
4269
|
+
return s.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
|
4270
|
+
}
|
|
4271
|
+
function norm(s) {
|
|
4272
|
+
return stripDiacritics(s).toLowerCase().replaceAll(".", "").trim().replaceAll(/\s+/g, " ");
|
|
4273
|
+
}
|
|
4274
|
+
function tokenize(name) {
|
|
4275
|
+
return norm(name).split(" ").filter(Boolean);
|
|
4276
|
+
}
|
|
4277
|
+
function surnameVariants(token) {
|
|
4278
|
+
if (!token.includes("-")) return [token];
|
|
4279
|
+
return [token, ...token.split("-").filter(Boolean)];
|
|
4280
|
+
}
|
|
4281
|
+
function namePoolMatches(providedNames, storedName) {
|
|
4282
|
+
if (isEmailLike2(storedName)) return false;
|
|
4283
|
+
const provided = providedNames.filter((n) => Boolean(n) && !isEmailLike2(n));
|
|
4284
|
+
const primary = tokenize(provided[0] ?? "");
|
|
4285
|
+
if (primary.length === 0) return false;
|
|
4286
|
+
const surnames = new Set(surnameVariants(primary[primary.length - 1]));
|
|
4287
|
+
for (let i = 1; i < provided.length; i++) {
|
|
4288
|
+
const t = tokenize(provided[i]);
|
|
4289
|
+
if (t.length >= 2) for (const v of surnameVariants(t[t.length - 1])) surnames.add(v);
|
|
4290
|
+
}
|
|
4291
|
+
const all = /* @__PURE__ */ new Set();
|
|
4292
|
+
for (const n of provided) for (const t of tokenize(n)) all.add(t);
|
|
4293
|
+
const given = [...all].filter((t) => !surnames.has(t));
|
|
4294
|
+
const stored = tokenize(storedName);
|
|
4295
|
+
if (stored.length === 0) return false;
|
|
4296
|
+
const storedSurname = stored[stored.length - 1];
|
|
4297
|
+
const storedGiven = stored.slice(0, -1);
|
|
4298
|
+
if (!surnameVariants(storedSurname).some((v) => surnames.has(v))) return false;
|
|
4299
|
+
const covered = (tok) => given.includes(tok) || tok.length === 1 && given.some((g) => g[0] === tok) || given.some((g) => g.length === 1 && g === tok[0]);
|
|
4300
|
+
return storedGiven.every(covered);
|
|
4301
|
+
}
|
|
4302
|
+
function findMatchingStoredName(providedNames, storedCandidates) {
|
|
4303
|
+
return storedCandidates.find((candidate) => namePoolMatches(providedNames, candidate));
|
|
4304
|
+
}
|
|
4305
|
+
|
|
4306
|
+
// src/index.ts
|
|
4307
|
+
function createSqlIdempotencyStore(opts2) {
|
|
4308
|
+
const table = opts2.table ?? "oneaddress_dispatches";
|
|
4309
|
+
const ph = opts2.placeholder ?? ((n) => `$${n}`);
|
|
4310
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(table)) {
|
|
4311
|
+
throw new Error(`[OneAddress SDK] invalid table name: ${table}`);
|
|
4312
|
+
}
|
|
4313
|
+
const completedOf = (row) => row?.completed_at ?? row?.completedAt ?? null;
|
|
4314
|
+
return {
|
|
4315
|
+
async claim(dispatchId) {
|
|
4316
|
+
const inserted = await opts2.query(
|
|
4317
|
+
`INSERT INTO ${table} (dispatch_id) VALUES (${ph(1)}) ON CONFLICT (dispatch_id) DO NOTHING RETURNING dispatch_id`,
|
|
4318
|
+
[dispatchId]
|
|
4319
|
+
);
|
|
4320
|
+
if (inserted.length > 0) return "fresh";
|
|
4321
|
+
const rows = await opts2.query(
|
|
4322
|
+
`SELECT completed_at FROM ${table} WHERE dispatch_id = ${ph(1)}`,
|
|
4323
|
+
[dispatchId]
|
|
4324
|
+
);
|
|
4325
|
+
return completedOf(rows[0]) ? "duplicate" : "retry-after-incomplete";
|
|
4326
|
+
},
|
|
4327
|
+
async complete(dispatchId) {
|
|
4328
|
+
await opts2.query(
|
|
4329
|
+
`UPDATE ${table} SET completed_at = CURRENT_TIMESTAMP WHERE dispatch_id = ${ph(1)}`,
|
|
4330
|
+
[dispatchId]
|
|
4331
|
+
);
|
|
4332
|
+
},
|
|
4333
|
+
// Legacy surface, implemented over the same table so a store built here
|
|
4334
|
+
// still satisfies callers (or SDK versions) that only know has/set.
|
|
4335
|
+
async has(dispatchId) {
|
|
4336
|
+
const rows = await opts2.query(
|
|
4337
|
+
`SELECT completed_at FROM ${table} WHERE dispatch_id = ${ph(1)}`,
|
|
4338
|
+
[dispatchId]
|
|
4339
|
+
);
|
|
4340
|
+
return rows.length > 0 && Boolean(completedOf(rows[0]));
|
|
4341
|
+
},
|
|
4342
|
+
async set(dispatchId) {
|
|
4343
|
+
await opts2.query(
|
|
4344
|
+
`INSERT INTO ${table} (dispatch_id, completed_at) VALUES (${ph(1)}, CURRENT_TIMESTAMP) ON CONFLICT (dispatch_id) DO UPDATE SET completed_at = CURRENT_TIMESTAMP`,
|
|
4345
|
+
[dispatchId]
|
|
4346
|
+
);
|
|
4347
|
+
}
|
|
4348
|
+
};
|
|
4349
|
+
}
|
|
3968
4350
|
function verifySignature(rawBody, signature, timestamp, secret) {
|
|
3969
4351
|
if (!/^[0-9a-f]{64}$/i.test(signature)) return false;
|
|
3970
4352
|
const sigPayload = `${timestamp}.${rawBody}`;
|
|
@@ -3987,8 +4369,17 @@ function verifyWithGrace(rawBody, timestamp, signature, currentSecret, previousS
|
|
|
3987
4369
|
function base64urlToBuffer(b64) {
|
|
3988
4370
|
return Buffer.from(b64.replace(/-/g, "+").replace(/_/g, "/"), "base64");
|
|
3989
4371
|
}
|
|
4372
|
+
function pemToBase64(pem) {
|
|
4373
|
+
const begin = pem.indexOf("-----BEGIN");
|
|
4374
|
+
if (begin === -1) return pem.replace(/\s/g, "");
|
|
4375
|
+
const armourEnd = pem.indexOf("-----", begin + "-----BEGIN".length);
|
|
4376
|
+
if (armourEnd === -1) return pem.replace(/\s/g, "");
|
|
4377
|
+
const bodyStart = armourEnd + "-----".length;
|
|
4378
|
+
const end = pem.indexOf("-----END", bodyStart);
|
|
4379
|
+
return (end === -1 ? pem.slice(bodyStart) : pem.slice(bodyStart, end)).replace(/\s/g, "");
|
|
4380
|
+
}
|
|
3990
4381
|
function pemToBuffer(pem) {
|
|
3991
|
-
return Buffer.from(pem
|
|
4382
|
+
return Buffer.from(pemToBase64(pem), "base64");
|
|
3992
4383
|
}
|
|
3993
4384
|
async function decryptAddress2(payload, privateKeyPem, partnerId) {
|
|
3994
4385
|
const { ephemeralPublicKey, iv, ciphertext, hkdfSalt } = payload;
|
|
@@ -4040,8 +4431,7 @@ async function decryptAddress2(payload, privateKeyPem, partnerId) {
|
|
|
4040
4431
|
}
|
|
4041
4432
|
async function decryptSession2(share, envelopeB64, privateKeyPem, partnerId) {
|
|
4042
4433
|
const { decryptSession: decryptSessionCrypto } = await Promise.resolve().then(() => (init_src(), src_exports));
|
|
4043
|
-
|
|
4044
|
-
return decryptSessionCrypto(share, envelopeB64, privateKeyB64, partnerId);
|
|
4434
|
+
return decryptSessionCrypto(share, envelopeB64, pemToBase64(privateKeyPem), partnerId);
|
|
4045
4435
|
}
|
|
4046
4436
|
async function transformAddress(payload, privateKeyPem, partnerId, recipientSpkiPem) {
|
|
4047
4437
|
const plaintext = await decryptAddress2(payload, privateKeyPem, partnerId);
|
|
@@ -4102,7 +4492,72 @@ async function transformSession(share, envelopeB64, privateKeyPem, partnerId, re
|
|
|
4102
4492
|
);
|
|
4103
4493
|
}
|
|
4104
4494
|
var OA_APP_BASE_URL = "https://oneaddress.io";
|
|
4105
|
-
|
|
4495
|
+
async function confirmUpdate(opts2) {
|
|
4496
|
+
const {
|
|
4497
|
+
partnerId,
|
|
4498
|
+
secret,
|
|
4499
|
+
dispatchId,
|
|
4500
|
+
status = "confirmed",
|
|
4501
|
+
note,
|
|
4502
|
+
loaRef,
|
|
4503
|
+
memberName,
|
|
4504
|
+
appBaseUrl = OA_APP_BASE_URL,
|
|
4505
|
+
fetchImpl = fetch
|
|
4506
|
+
} = opts2;
|
|
4507
|
+
if (!partnerId) return { ok: false, status: 0, error: "partnerId is required" };
|
|
4508
|
+
if (!secret) return { ok: false, status: 0, error: "secret is required" };
|
|
4509
|
+
const id = typeof dispatchId === "string" ? Number(dispatchId) : dispatchId;
|
|
4510
|
+
if (!Number.isInteger(id) || id <= 0) {
|
|
4511
|
+
return {
|
|
4512
|
+
ok: false,
|
|
4513
|
+
status: 0,
|
|
4514
|
+
error: `dispatchId must be a positive integer, received ${JSON.stringify(dispatchId)} \u2014 it comes from the X-OneAddress-Dispatch header on the webhook you are confirming`
|
|
4515
|
+
};
|
|
4516
|
+
}
|
|
4517
|
+
const body = JSON.stringify({
|
|
4518
|
+
dispatch_id: id,
|
|
4519
|
+
partner_id: partnerId,
|
|
4520
|
+
status,
|
|
4521
|
+
...note !== void 0 ? { note } : {},
|
|
4522
|
+
...loaRef !== void 0 ? { loa_ref: loaRef } : {},
|
|
4523
|
+
...memberName !== void 0 ? { member_name: memberName } : {}
|
|
4524
|
+
});
|
|
4525
|
+
const timestamp = String(Math.floor(Date.now() / 1e3));
|
|
4526
|
+
const signature = import_crypto.default.createHmac("sha256", secret).update(`${timestamp}.${body}`).digest("hex");
|
|
4527
|
+
let base = appBaseUrl;
|
|
4528
|
+
while (base.endsWith("/")) base = base.slice(0, -1);
|
|
4529
|
+
let res;
|
|
4530
|
+
try {
|
|
4531
|
+
res = await fetchImpl(`${base}/api/confirm`, {
|
|
4532
|
+
method: "POST",
|
|
4533
|
+
headers: {
|
|
4534
|
+
"Content-Type": "application/json",
|
|
4535
|
+
"Authorization": `Bearer ${secret}`,
|
|
4536
|
+
"X-OneAddress-Timestamp": timestamp,
|
|
4537
|
+
"X-OneAddress-Signature": signature
|
|
4538
|
+
},
|
|
4539
|
+
// The SAME string that was signed. Not an object, and not re-stringified.
|
|
4540
|
+
body
|
|
4541
|
+
});
|
|
4542
|
+
} catch (err) {
|
|
4543
|
+
return { ok: false, status: 0, error: err instanceof Error ? err.message : String(err) };
|
|
4544
|
+
}
|
|
4545
|
+
if (res.ok) return { ok: true, status: res.status };
|
|
4546
|
+
let error;
|
|
4547
|
+
try {
|
|
4548
|
+
const parsed = await res.json();
|
|
4549
|
+
if (typeof parsed?.error === "string") error = parsed.error;
|
|
4550
|
+
} catch {
|
|
4551
|
+
}
|
|
4552
|
+
return { ok: false, status: res.status, error };
|
|
4553
|
+
}
|
|
4554
|
+
function allowedLoaHosts() {
|
|
4555
|
+
const hosts = ["oneaddress.io", "app.oneaddress.io"];
|
|
4556
|
+
if (typeof process !== "undefined" && process.env?.NODE_ENV !== "production") {
|
|
4557
|
+
hosts.push("localhost", "127.0.0.1");
|
|
4558
|
+
}
|
|
4559
|
+
return new Set(hosts);
|
|
4560
|
+
}
|
|
4106
4561
|
async function fetchLoaPublicKey(appBaseUrl = OA_APP_BASE_URL) {
|
|
4107
4562
|
let parsedBase;
|
|
4108
4563
|
try {
|
|
@@ -4110,9 +4565,10 @@ async function fetchLoaPublicKey(appBaseUrl = OA_APP_BASE_URL) {
|
|
|
4110
4565
|
} catch {
|
|
4111
4566
|
throw new Error("[OneAddress SDK] fetchLoaPublicKey: appBaseUrl is not a valid URL");
|
|
4112
4567
|
}
|
|
4113
|
-
|
|
4568
|
+
const allowedHosts = allowedLoaHosts();
|
|
4569
|
+
if (!allowedHosts.has(parsedBase.hostname)) {
|
|
4114
4570
|
throw new Error(
|
|
4115
|
-
`[OneAddress SDK] fetchLoaPublicKey: appBaseUrl host must be one of: ${[...
|
|
4571
|
+
`[OneAddress SDK] fetchLoaPublicKey: appBaseUrl host must be one of: ${[...allowedHosts].join(", ")}`
|
|
4116
4572
|
);
|
|
4117
4573
|
}
|
|
4118
4574
|
const url = `${parsedBase.origin}/.well-known/oneaddress-loa-key.pem`;
|
|
@@ -4221,6 +4677,34 @@ function validateAddress(raw) {
|
|
|
4221
4677
|
}
|
|
4222
4678
|
return obj;
|
|
4223
4679
|
}
|
|
4680
|
+
var ADDRESS_ALIASES = {
|
|
4681
|
+
line1: ["line1", "address_line1", "street", "streetAddress"],
|
|
4682
|
+
suburb: ["suburb", "city", "locality", "town"],
|
|
4683
|
+
state: ["state", "region", "province"],
|
|
4684
|
+
postcode: ["postcode", "postalCode", "postal_code", "zip"],
|
|
4685
|
+
country: ["country"]
|
|
4686
|
+
};
|
|
4687
|
+
function readAddressParts(raw) {
|
|
4688
|
+
const a = raw && typeof raw === "object" ? raw : {};
|
|
4689
|
+
const read = (part) => {
|
|
4690
|
+
for (const key of ADDRESS_ALIASES[part]) {
|
|
4691
|
+
const v = a[key];
|
|
4692
|
+
if (typeof v === "string" && v.trim() !== "") return v.trim();
|
|
4693
|
+
if (typeof v === "number" && Number.isFinite(v)) return String(v);
|
|
4694
|
+
}
|
|
4695
|
+
return "";
|
|
4696
|
+
};
|
|
4697
|
+
return {
|
|
4698
|
+
line1: read("line1"),
|
|
4699
|
+
suburb: read("suburb"),
|
|
4700
|
+
state: read("state"),
|
|
4701
|
+
postcode: read("postcode"),
|
|
4702
|
+
country: read("country") || "AU"
|
|
4703
|
+
};
|
|
4704
|
+
}
|
|
4705
|
+
function formatAddressParts(parts) {
|
|
4706
|
+
return [parts.line1, parts.suburb, parts.state, parts.postcode].filter(Boolean).join(", ");
|
|
4707
|
+
}
|
|
4224
4708
|
var STREET_SUFFIX_MAP = {
|
|
4225
4709
|
st: "street",
|
|
4226
4710
|
str: "street",
|
|
@@ -4278,6 +4762,30 @@ function compareAddresses(a, b) {
|
|
|
4278
4762
|
if (aCountry && bCountry && aCountry !== bCountry) return false;
|
|
4279
4763
|
return true;
|
|
4280
4764
|
}
|
|
4765
|
+
async function sendVerifyResult(params) {
|
|
4766
|
+
const { callbackUrl, callbackToken, batchId, partnerId, match, note } = params;
|
|
4767
|
+
const safe = isSafeWebhookUrl(callbackUrl);
|
|
4768
|
+
if (!safe.ok) {
|
|
4769
|
+
throw new Error(`[OneAddress SDK] refusing verify-result callback to unsafe URL: ${safe.reason}`);
|
|
4770
|
+
}
|
|
4771
|
+
const res = await fetch(callbackUrl, {
|
|
4772
|
+
method: "POST",
|
|
4773
|
+
headers: { "Content-Type": "application/json" },
|
|
4774
|
+
body: JSON.stringify({
|
|
4775
|
+
batch_id: batchId,
|
|
4776
|
+
partner_id: partnerId,
|
|
4777
|
+
result: match ? "match" : "mismatch",
|
|
4778
|
+
address_match: match,
|
|
4779
|
+
...note ? { note } : {},
|
|
4780
|
+
token: callbackToken
|
|
4781
|
+
})
|
|
4782
|
+
});
|
|
4783
|
+
if (!res.ok) {
|
|
4784
|
+
throw new Error(`[OneAddress SDK] verify-result callback to ${callbackUrl} failed: HTTP ${res.status}`);
|
|
4785
|
+
}
|
|
4786
|
+
}
|
|
4787
|
+
var HANDLED_EVENTS = ["address.updated", "address.verify", "account.verify", "address.test"];
|
|
4788
|
+
var warnedUnhandledEvents = /* @__PURE__ */ new Set();
|
|
4281
4789
|
function createOneAddressHandler(options) {
|
|
4282
4790
|
const {
|
|
4283
4791
|
webhookSecret,
|
|
@@ -4288,6 +4796,7 @@ function createOneAddressHandler(options) {
|
|
|
4288
4796
|
onUpdate,
|
|
4289
4797
|
onVerify,
|
|
4290
4798
|
onAccountVerify,
|
|
4799
|
+
onTest,
|
|
4291
4800
|
timestampToleranceSecs = 300,
|
|
4292
4801
|
idempotencyStore
|
|
4293
4802
|
} = options;
|
|
@@ -4369,6 +4878,14 @@ function createOneAddressHandler(options) {
|
|
|
4369
4878
|
"[OneAddress SDK] idempotencyStore is required in test mode when X-OneAddress-Dispatch is present. Wire up an idempotencyStore to prevent double-processing on retry."
|
|
4370
4879
|
);
|
|
4371
4880
|
}
|
|
4881
|
+
} else if (idempotencyStore.claim) {
|
|
4882
|
+
const claim = await idempotencyStore.claim(dispatchId);
|
|
4883
|
+
if (claim === "duplicate") {
|
|
4884
|
+
return new Response(JSON.stringify({ ok: true, duplicate: true }), {
|
|
4885
|
+
status: 200,
|
|
4886
|
+
headers: { "Content-Type": "application/json" }
|
|
4887
|
+
});
|
|
4888
|
+
}
|
|
4372
4889
|
} else {
|
|
4373
4890
|
const alreadySeen = await idempotencyStore.has(dispatchId);
|
|
4374
4891
|
if (alreadySeen) {
|
|
@@ -4443,8 +4960,9 @@ function createOneAddressHandler(options) {
|
|
|
4443
4960
|
}
|
|
4444
4961
|
const result = await onUpdate(event);
|
|
4445
4962
|
if (dispatchId && idempotencyStore) {
|
|
4446
|
-
|
|
4447
|
-
|
|
4963
|
+
const record = idempotencyStore.complete ? idempotencyStore.complete(dispatchId) : idempotencyStore.set(dispatchId);
|
|
4964
|
+
await record.catch(
|
|
4965
|
+
(err) => console.error("[OneAddress SDK] idempotency completion failed:", err)
|
|
4448
4966
|
// NOSONAR
|
|
4449
4967
|
);
|
|
4450
4968
|
}
|
|
@@ -4479,7 +4997,28 @@ function createOneAddressHandler(options) {
|
|
|
4479
4997
|
raw: rawAddress
|
|
4480
4998
|
};
|
|
4481
4999
|
const result = await onVerify(event);
|
|
4482
|
-
|
|
5000
|
+
const matched = result && typeof result.match === "boolean" ? result.match : void 0;
|
|
5001
|
+
const callbackUrl = typeof body.callback_url === "string" ? body.callback_url : "";
|
|
5002
|
+
const callbackToken = typeof body.callback_token === "string" ? body.callback_token : "";
|
|
5003
|
+
if (matched === void 0) {
|
|
5004
|
+
console.error("[OneAddress SDK] onVerify must return { match: boolean } to close the verify loop; result dropped.");
|
|
5005
|
+
} else if (!callbackUrl || !callbackToken) {
|
|
5006
|
+
console.error("[OneAddress SDK] address.verify webhook is missing callback_url/callback_token; cannot report the result.");
|
|
5007
|
+
} else {
|
|
5008
|
+
try {
|
|
5009
|
+
await sendVerifyResult({
|
|
5010
|
+
callbackUrl,
|
|
5011
|
+
callbackToken,
|
|
5012
|
+
batchId: body.batch_id ?? 0,
|
|
5013
|
+
partnerId,
|
|
5014
|
+
match: matched,
|
|
5015
|
+
note: result && typeof result.note === "string" ? result.note : void 0
|
|
5016
|
+
});
|
|
5017
|
+
} catch (err) {
|
|
5018
|
+
console.error("[OneAddress SDK] verify-result callback failed:", err);
|
|
5019
|
+
}
|
|
5020
|
+
}
|
|
5021
|
+
return new Response(JSON.stringify({ ok: true, match: matched }), {
|
|
4483
5022
|
status: 200,
|
|
4484
5023
|
headers: { "Content-Type": "application/json" }
|
|
4485
5024
|
});
|
|
@@ -4518,7 +5057,39 @@ function createOneAddressHandler(options) {
|
|
|
4518
5057
|
headers: { "Content-Type": "application/json" }
|
|
4519
5058
|
});
|
|
4520
5059
|
}
|
|
4521
|
-
|
|
5060
|
+
if (body.event === "address.test" && onTest) {
|
|
5061
|
+
if (!isD5Body(body)) {
|
|
5062
|
+
return new Response(JSON.stringify({ error: "address.test requires a session envelope" }), {
|
|
5063
|
+
status: 400,
|
|
5064
|
+
headers: { "Content-Type": "application/json" }
|
|
5065
|
+
});
|
|
5066
|
+
}
|
|
5067
|
+
const d5 = await buildD5Pieces(body, partnerId);
|
|
5068
|
+
await onTest({
|
|
5069
|
+
event: "address.test",
|
|
5070
|
+
index: typeof body.index === "number" ? body.index : void 0,
|
|
5071
|
+
total: typeof body.total === "number" ? body.total : void 0,
|
|
5072
|
+
verification_id: typeof body.verification_id === "string" ? body.verification_id : void 0,
|
|
5073
|
+
timestamp: tsNum,
|
|
5074
|
+
partner_id: partnerId,
|
|
5075
|
+
customer: d5.customer,
|
|
5076
|
+
address: d5.address,
|
|
5077
|
+
raw: d5.raw
|
|
5078
|
+
});
|
|
5079
|
+
return new Response(JSON.stringify({ ok: true, test: true }), {
|
|
5080
|
+
status: 200,
|
|
5081
|
+
headers: { "Content-Type": "application/json" }
|
|
5082
|
+
});
|
|
5083
|
+
}
|
|
5084
|
+
const evt = typeof body.event === "string" ? body.event : "(none)";
|
|
5085
|
+
if (!warnedUnhandledEvents.has(evt)) {
|
|
5086
|
+
warnedUnhandledEvents.add(evt);
|
|
5087
|
+
console.warn(
|
|
5088
|
+
`[OneAddress SDK] Event "${evt}" is not handled by this build and was SKIPPED. It was acknowledged with 200 so OneAddress does not retry, but your onUpdate callback did NOT run. This build handles: ${HANDLED_EVENTS.join(", ")}. If you expected this event to be processed, update @oneaddress/partner-sdk.`
|
|
5089
|
+
// NOSONAR
|
|
5090
|
+
);
|
|
5091
|
+
}
|
|
5092
|
+
return new Response(JSON.stringify({ ok: true, skipped: true, event: evt }), {
|
|
4522
5093
|
status: 200,
|
|
4523
5094
|
headers: { "Content-Type": "application/json" }
|
|
4524
5095
|
});
|
|
@@ -4532,6 +5103,39 @@ function createOneAddressHandler(options) {
|
|
|
4532
5103
|
}
|
|
4533
5104
|
};
|
|
4534
5105
|
}
|
|
5106
|
+
function toExpressHandler(handler) {
|
|
5107
|
+
return async function expressHandler(req, res) {
|
|
5108
|
+
const raw = req.body;
|
|
5109
|
+
const isBuffer = typeof raw === "object" && raw !== null && typeof raw.copy === "function" && typeof raw.toString === "function";
|
|
5110
|
+
if (!isBuffer && typeof raw !== "string") {
|
|
5111
|
+
const detail = raw === void 0 ? "the body was not read at all" : `the body arrived as ${raw === null ? "null" : typeof raw}, already parsed`;
|
|
5112
|
+
console.error(
|
|
5113
|
+
`[OneAddress SDK] toExpressHandler: raw request body required, but ${detail}. Add express.raw({ type: 'application/json' }) to THIS route, before the handler, and make sure no global express.json() runs first. The webhook signature is computed over the raw bytes, so a parsed body cannot be verified.`
|
|
5114
|
+
// NOSONAR
|
|
5115
|
+
);
|
|
5116
|
+
res.status(500).send(JSON.stringify({ error: "Receiver misconfigured: raw body required" }));
|
|
5117
|
+
return;
|
|
5118
|
+
}
|
|
5119
|
+
const text = typeof raw === "string" ? raw : String(raw);
|
|
5120
|
+
const fetchLike = {
|
|
5121
|
+
text: async () => text,
|
|
5122
|
+
headers: {
|
|
5123
|
+
get(name) {
|
|
5124
|
+
const v = req.headers[name.toLowerCase()];
|
|
5125
|
+
if (v === void 0) return null;
|
|
5126
|
+
return Array.isArray(v) ? v.join(", ") : v;
|
|
5127
|
+
}
|
|
5128
|
+
}
|
|
5129
|
+
};
|
|
5130
|
+
const out = await handler(fetchLike);
|
|
5131
|
+
const bodyText = await out.text();
|
|
5132
|
+
res.status(out.status);
|
|
5133
|
+
out.headers.forEach((value, key) => {
|
|
5134
|
+
res.setHeader(key, value);
|
|
5135
|
+
});
|
|
5136
|
+
res.send(bodyText);
|
|
5137
|
+
};
|
|
5138
|
+
}
|
|
4535
5139
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4536
5140
|
0 && (module.exports = {
|
|
4537
5141
|
CURRENT_VERSION,
|
|
@@ -4540,15 +5144,24 @@ function createOneAddressHandler(options) {
|
|
|
4540
5144
|
canonicalD5LoaForm,
|
|
4541
5145
|
compareAddresses,
|
|
4542
5146
|
computeBlindIndex,
|
|
5147
|
+
confirmUpdate,
|
|
4543
5148
|
createOneAddressHandler,
|
|
5149
|
+
createSqlIdempotencyStore,
|
|
4544
5150
|
d5LoaRef,
|
|
4545
5151
|
decrypt,
|
|
4546
5152
|
decryptAddress,
|
|
4547
5153
|
decryptLoaEncrypted,
|
|
4548
5154
|
decryptSession,
|
|
4549
5155
|
fetchLoaPublicKey,
|
|
5156
|
+
findMatchingStoredName,
|
|
5157
|
+
formatAddressParts,
|
|
5158
|
+
isEmailLike,
|
|
4550
5159
|
isFreshTimestamp,
|
|
5160
|
+
namePoolMatches,
|
|
4551
5161
|
normalizeForBlindIndex,
|
|
5162
|
+
readAddressParts,
|
|
5163
|
+
sendVerifyResult,
|
|
5164
|
+
toExpressHandler,
|
|
4552
5165
|
transform,
|
|
4553
5166
|
transformAddress,
|
|
4554
5167
|
transformSession,
|