@oneaddress/partner-sdk 2.9.0 → 2.10.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 +45 -1
- package/README.md +35 -0
- package/dist/{chunk-PP2TM7HN.mjs → chunk-JJ2B5VFO.mjs} +147 -25
- package/dist/{chunk-OKPEOGR5.mjs → chunk-NJGZ6ISS.mjs} +193 -11
- package/dist/edge.d.mts +1 -1
- package/dist/edge.d.ts +1 -1
- package/dist/edge.js +254 -35
- package/dist/edge.mjs +12 -2
- package/dist/index.d.mts +186 -1
- package/dist/index.d.ts +186 -1
- package/dist/index.js +360 -35
- package/dist/index.mjs +32 -2
- package/dist/{src-P3LR7F4A.mjs → src-XBG2QHG4.mjs} +11 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4095,6 +4095,16 @@ var init_replay_window = __esm({
|
|
|
4095
4095
|
}
|
|
4096
4096
|
});
|
|
4097
4097
|
|
|
4098
|
+
// ../crypto/src/refund-review-notify.ts
|
|
4099
|
+
function refundReviewNotifySigningString(timestamp, rawBody) {
|
|
4100
|
+
return `oneaddress.refund-review-notify.v1.${timestamp}.${rawBody}`;
|
|
4101
|
+
}
|
|
4102
|
+
var init_refund_review_notify = __esm({
|
|
4103
|
+
"../crypto/src/refund-review-notify.ts"() {
|
|
4104
|
+
"use strict";
|
|
4105
|
+
}
|
|
4106
|
+
});
|
|
4107
|
+
|
|
4098
4108
|
// ../crypto/src/safe-url.ts
|
|
4099
4109
|
function parseIPv4Component(raw) {
|
|
4100
4110
|
if (raw.length === 0) return null;
|
|
@@ -4476,11 +4486,29 @@ var init_partner_key_attestation = __esm({
|
|
|
4476
4486
|
});
|
|
4477
4487
|
|
|
4478
4488
|
// ../crypto/src/registry-root-pin.ts
|
|
4489
|
+
function registryEnvironmentForOrigin(origin) {
|
|
4490
|
+
let o = origin ?? "";
|
|
4491
|
+
if (!o) {
|
|
4492
|
+
const loc = globalThis.location;
|
|
4493
|
+
o = loc?.origin ?? "";
|
|
4494
|
+
}
|
|
4495
|
+
if (!o) return "preview";
|
|
4496
|
+
try {
|
|
4497
|
+
const host = new URL(o).hostname.toLowerCase().replace(/\.$/, "");
|
|
4498
|
+
return PRODUCTION_REGISTRY_HOSTS.includes(host) ? "production" : "preview";
|
|
4499
|
+
} catch {
|
|
4500
|
+
return "preview";
|
|
4501
|
+
}
|
|
4502
|
+
}
|
|
4479
4503
|
function __setPinnedRegistryRootsForTests(pins) {
|
|
4480
4504
|
overrideForTests = pins;
|
|
4481
4505
|
}
|
|
4482
|
-
function pinnedRegistryRoots() {
|
|
4483
|
-
|
|
4506
|
+
function pinnedRegistryRoots(env = "production") {
|
|
4507
|
+
if (overrideForTests) {
|
|
4508
|
+
if (Array.isArray(overrideForTests)) return overrideForTests;
|
|
4509
|
+
return overrideForTests[env] ?? [];
|
|
4510
|
+
}
|
|
4511
|
+
return REGISTRY_ROOT_PINS[env];
|
|
4484
4512
|
}
|
|
4485
4513
|
function b64ToBytes2(b64) {
|
|
4486
4514
|
const normalised = b64.replace(/-/g, "+").replace(/_/g, "/");
|
|
@@ -4493,34 +4521,47 @@ async function spkiSha256HexFromB64(spkiB64) {
|
|
|
4493
4521
|
const digest = await crypto.subtle.digest("SHA-256", b64ToBytes2(spkiB64));
|
|
4494
4522
|
return bytesToHex3(new Uint8Array(digest));
|
|
4495
4523
|
}
|
|
4496
|
-
async function rootIsPinned(root) {
|
|
4524
|
+
async function rootIsPinned(root, env = "production") {
|
|
4497
4525
|
try {
|
|
4498
4526
|
const digest = await spkiSha256HexFromB64(root.public_key_b64);
|
|
4499
|
-
return pinnedRegistryRoots().some(
|
|
4527
|
+
return pinnedRegistryRoots(env).some(
|
|
4500
4528
|
(p) => p.root_key_id === root.root_key_id && p.spki_sha256 === digest
|
|
4501
4529
|
);
|
|
4502
4530
|
} catch {
|
|
4503
4531
|
return false;
|
|
4504
4532
|
}
|
|
4505
4533
|
}
|
|
4506
|
-
async function unpinnedRootIds(roots) {
|
|
4534
|
+
async function unpinnedRootIds(roots, env = "production") {
|
|
4507
4535
|
const out = [];
|
|
4508
4536
|
for (const root of roots) {
|
|
4509
|
-
if (!await rootIsPinned(root)) out.push(String(root?.root_key_id ?? "(no id)"));
|
|
4537
|
+
if (!await rootIsPinned(root, env)) out.push(String(root?.root_key_id ?? "(no id)"));
|
|
4510
4538
|
}
|
|
4511
4539
|
return out;
|
|
4512
4540
|
}
|
|
4513
|
-
var PINNED_REGISTRY_ROOTS, overrideForTests;
|
|
4541
|
+
var PRODUCTION_REGISTRY_HOSTS, PRODUCTION_ROOT, REGISTRY_ROOT_PINS, PINNED_REGISTRY_ROOTS, overrideForTests;
|
|
4514
4542
|
var init_registry_root_pin = __esm({
|
|
4515
4543
|
"../crypto/src/registry-root-pin.ts"() {
|
|
4516
4544
|
"use strict";
|
|
4517
4545
|
init_partner_key_attestation();
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
})
|
|
4546
|
+
PRODUCTION_REGISTRY_HOSTS = Object.freeze([
|
|
4547
|
+
"oneaddress.io",
|
|
4548
|
+
"www.oneaddress.io",
|
|
4549
|
+
"app.oneaddress.io"
|
|
4523
4550
|
]);
|
|
4551
|
+
PRODUCTION_ROOT = Object.freeze({
|
|
4552
|
+
root_key_id: "rk1_251368ec9b0a84ae",
|
|
4553
|
+
spki_sha256: "251368ec9b0a84ae9881533bd1687efb7d439edd927aef47c1bb3bb069b3dc1d"
|
|
4554
|
+
});
|
|
4555
|
+
REGISTRY_ROOT_PINS = Object.freeze({
|
|
4556
|
+
production: Object.freeze([PRODUCTION_ROOT]),
|
|
4557
|
+
preview: Object.freeze([
|
|
4558
|
+
Object.freeze({
|
|
4559
|
+
root_key_id: "rk1_4690d67464893d48",
|
|
4560
|
+
spki_sha256: "4690d67464893d48ebb335bcd29f3203fbacefbc69afd8a047b639521296bfab"
|
|
4561
|
+
})
|
|
4562
|
+
])
|
|
4563
|
+
});
|
|
4564
|
+
PINNED_REGISTRY_ROOTS = REGISTRY_ROOT_PINS.production;
|
|
4524
4565
|
overrideForTests = null;
|
|
4525
4566
|
}
|
|
4526
4567
|
});
|
|
@@ -4711,6 +4752,30 @@ var init_registry_head = __esm({
|
|
|
4711
4752
|
});
|
|
4712
4753
|
|
|
4713
4754
|
// ../crypto/src/verify-partner-keys.ts
|
|
4755
|
+
function localStorageHeadHighWater(key = "oa-registry-head-issued-at") {
|
|
4756
|
+
return {
|
|
4757
|
+
read() {
|
|
4758
|
+
try {
|
|
4759
|
+
return globalThis.localStorage?.getItem(key) ?? null;
|
|
4760
|
+
} catch {
|
|
4761
|
+
return null;
|
|
4762
|
+
}
|
|
4763
|
+
},
|
|
4764
|
+
write(issuedAt) {
|
|
4765
|
+
try {
|
|
4766
|
+
globalThis.localStorage?.setItem(key, issuedAt);
|
|
4767
|
+
} catch {
|
|
4768
|
+
}
|
|
4769
|
+
}
|
|
4770
|
+
};
|
|
4771
|
+
}
|
|
4772
|
+
function isOlderThan(candidate, mark) {
|
|
4773
|
+
if (!mark) return false;
|
|
4774
|
+
const m = Date.parse(mark);
|
|
4775
|
+
const c = Date.parse(candidate);
|
|
4776
|
+
if (Number.isNaN(m)) return false;
|
|
4777
|
+
return Number.isNaN(c) || c < m;
|
|
4778
|
+
}
|
|
4714
4779
|
async function saysRootNotConfigured(res) {
|
|
4715
4780
|
if (res.status !== 503) return false;
|
|
4716
4781
|
try {
|
|
@@ -4746,19 +4811,61 @@ async function crossoverOutcomeFor(partnerId, crossover, reg) {
|
|
|
4746
4811
|
if (!reg.head) return "head-unusable";
|
|
4747
4812
|
return await headNamesStagedKey(reg.head, partnerId, crossover.key_id, crossover.public_key_b64) ? "ok" : "not-authorised";
|
|
4748
4813
|
}
|
|
4814
|
+
function refuseAll(keys, outcome) {
|
|
4815
|
+
const blocked = {};
|
|
4816
|
+
const crossoverBlocked = {};
|
|
4817
|
+
try {
|
|
4818
|
+
for (const [partnerId, key] of Object.entries(keys ?? {})) {
|
|
4819
|
+
blocked[partnerId] = outcome;
|
|
4820
|
+
if (key?.crossover) crossoverBlocked[partnerId] = "head-unusable";
|
|
4821
|
+
}
|
|
4822
|
+
} catch {
|
|
4823
|
+
}
|
|
4824
|
+
return { blocked, crossoverBlocked };
|
|
4825
|
+
}
|
|
4749
4826
|
function createPartnerKeyVerifier(env = {}) {
|
|
4750
4827
|
const baseUrl = env.baseUrl ?? "";
|
|
4751
|
-
const report =
|
|
4752
|
-
|
|
4828
|
+
const report = (context, detail) => {
|
|
4829
|
+
try {
|
|
4830
|
+
env.report?.(context, detail);
|
|
4831
|
+
} catch {
|
|
4832
|
+
}
|
|
4833
|
+
};
|
|
4753
4834
|
let registryPromise = null;
|
|
4754
4835
|
function worthCaching(load) {
|
|
4755
4836
|
return load.ok && load.registry.head !== null;
|
|
4756
4837
|
}
|
|
4838
|
+
async function readMark() {
|
|
4839
|
+
try {
|
|
4840
|
+
const v = await env.headHighWater?.read();
|
|
4841
|
+
return typeof v === "string" ? v : null;
|
|
4842
|
+
} catch {
|
|
4843
|
+
return null;
|
|
4844
|
+
}
|
|
4845
|
+
}
|
|
4846
|
+
async function writeMark(issuedAt) {
|
|
4847
|
+
try {
|
|
4848
|
+
await env.headHighWater?.write(issuedAt);
|
|
4849
|
+
} catch {
|
|
4850
|
+
}
|
|
4851
|
+
}
|
|
4852
|
+
async function judgeHead(headRes, roots) {
|
|
4853
|
+
if (!headRes.ok) return { head: null, headVerdict: "absent" };
|
|
4854
|
+
let head;
|
|
4855
|
+
try {
|
|
4856
|
+
head = await headRes.json();
|
|
4857
|
+
} catch {
|
|
4858
|
+
return { head: null, headVerdict: "unreadable" };
|
|
4859
|
+
}
|
|
4860
|
+
const headVerdict = await verifyRegistryHead(head, roots);
|
|
4861
|
+
return headVerdict === "ok" ? { head, headVerdict } : { head: null, headVerdict };
|
|
4862
|
+
}
|
|
4757
4863
|
async function loadRegistry() {
|
|
4758
4864
|
try {
|
|
4865
|
+
const headUrl = baseUrl + "/.well-known/oneaddress-key-registry-head.json";
|
|
4759
4866
|
const [rootsRes, headRes] = await Promise.all([
|
|
4760
4867
|
fetch(baseUrl + "/.well-known/oneaddress-key-registry.json", { cache: "no-cache" }),
|
|
4761
|
-
fetch(
|
|
4868
|
+
fetch(headUrl, { cache: "no-cache" })
|
|
4762
4869
|
]);
|
|
4763
4870
|
if (!rootsRes.ok) {
|
|
4764
4871
|
const configured = await saysRootNotConfigured(rootsRes);
|
|
@@ -4780,16 +4887,30 @@ function createPartnerKeyVerifier(env = {}) {
|
|
|
4780
4887
|
if (roots.length === 0) {
|
|
4781
4888
|
return { ok: false, failure: { reason: "roots-empty", status: rootsRes.status } };
|
|
4782
4889
|
}
|
|
4783
|
-
const unpinnedRoots = await unpinnedRootIds(roots);
|
|
4890
|
+
const unpinnedRoots = await unpinnedRootIds(roots, registryEnvironmentForOrigin(baseUrl));
|
|
4784
4891
|
if (unpinnedRoots.length > 0) {
|
|
4785
4892
|
return { ok: true, registry: { roots: [], head: null, headVerdict: "root-unpinned", unpinnedRoots } };
|
|
4786
4893
|
}
|
|
4787
|
-
let head =
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
head
|
|
4791
|
-
|
|
4792
|
-
|
|
4894
|
+
let { head, headVerdict } = await judgeHead(headRes, roots);
|
|
4895
|
+
if (head) {
|
|
4896
|
+
const mark = await readMark();
|
|
4897
|
+
if (isOlderThan(head.issued_at, mark)) {
|
|
4898
|
+
let fresh = { head: null, headVerdict: "absent" };
|
|
4899
|
+
try {
|
|
4900
|
+
fresh = await judgeHead(
|
|
4901
|
+
await fetch(`${headUrl}?fresh=${Date.now()}`, { cache: "reload" }),
|
|
4902
|
+
roots
|
|
4903
|
+
);
|
|
4904
|
+
} catch {
|
|
4905
|
+
}
|
|
4906
|
+
if (fresh.head && !isOlderThan(fresh.head.issued_at, mark)) {
|
|
4907
|
+
({ head, headVerdict } = fresh);
|
|
4908
|
+
} else {
|
|
4909
|
+
head = null;
|
|
4910
|
+
headVerdict = "rolled-back";
|
|
4911
|
+
}
|
|
4912
|
+
}
|
|
4913
|
+
if (head && head.issued_at !== mark) await writeMark(head.issued_at);
|
|
4793
4914
|
}
|
|
4794
4915
|
return { ok: true, registry: { roots, head, headVerdict, unpinnedRoots: [] } };
|
|
4795
4916
|
} catch {
|
|
@@ -4802,8 +4923,8 @@ function createPartnerKeyVerifier(env = {}) {
|
|
|
4802
4923
|
const load = await pending;
|
|
4803
4924
|
if (!worthCaching(load)) registryPromise = null;
|
|
4804
4925
|
if (!load.ok) {
|
|
4805
|
-
report(context, { registry: "unavailable", enforced:
|
|
4806
|
-
return
|
|
4926
|
+
report(context, { registry: "unavailable", enforced: true, ...load.failure });
|
|
4927
|
+
return refuseAll(keys, "registry-unavailable");
|
|
4807
4928
|
}
|
|
4808
4929
|
const reg = load.registry;
|
|
4809
4930
|
let bound = EMPTY_BOUND;
|
|
@@ -4824,6 +4945,7 @@ function createPartnerKeyVerifier(env = {}) {
|
|
|
4824
4945
|
"not-in-head": [],
|
|
4825
4946
|
"head-unusable": [],
|
|
4826
4947
|
"root-unpinned": [],
|
|
4948
|
+
"registry-unavailable": [],
|
|
4827
4949
|
"error": []
|
|
4828
4950
|
};
|
|
4829
4951
|
const blocked = {};
|
|
@@ -4875,8 +4997,8 @@ function createPartnerKeyVerifier(env = {}) {
|
|
|
4875
4997
|
}
|
|
4876
4998
|
return { blocked, crossoverBlocked };
|
|
4877
4999
|
} catch {
|
|
4878
|
-
report(context, { registry: "verifier-error", enforced:
|
|
4879
|
-
return
|
|
5000
|
+
report(context, { registry: "verifier-error", enforced: true });
|
|
5001
|
+
return refuseAll(keys, "error");
|
|
4880
5002
|
}
|
|
4881
5003
|
}
|
|
4882
5004
|
function __resetRegistryCacheForTests() {
|
|
@@ -5077,9 +5199,11 @@ __export(src_exports, {
|
|
|
5077
5199
|
PARTNER_KEY_REFUSED_MESSAGE: () => PARTNER_KEY_REFUSED_MESSAGE,
|
|
5078
5200
|
PINNED_REGISTRY_ROOTS: () => PINNED_REGISTRY_ROOTS,
|
|
5079
5201
|
PIN_HARDENING_VERSION: () => PIN_HARDENING_VERSION,
|
|
5202
|
+
PRODUCTION_REGISTRY_HOSTS: () => PRODUCTION_REGISTRY_HOSTS,
|
|
5080
5203
|
REGISTRY_HEAD_ALG: () => REGISTRY_HEAD_ALG,
|
|
5081
5204
|
REGISTRY_HEAD_V1: () => REGISTRY_HEAD_V1,
|
|
5082
5205
|
REGISTRY_HEAD_V2: () => REGISTRY_HEAD_V2,
|
|
5206
|
+
REGISTRY_ROOT_PINS: () => REGISTRY_ROOT_PINS,
|
|
5083
5207
|
SENDER_HELD_KEY_ALGORITHM: () => SENDER_HELD_KEY_ALGORITHM,
|
|
5084
5208
|
__setPinnedRegistryRootsForTests: () => __setPinnedRegistryRootsForTests,
|
|
5085
5209
|
blockedPublicKeyReason: () => blockedPublicKeyReason,
|
|
@@ -5113,6 +5237,7 @@ __export(src_exports, {
|
|
|
5113
5237
|
isIpLiteralHost: () => isIpLiteralHost,
|
|
5114
5238
|
isSafeWebhookUrl: () => isSafeWebhookUrl,
|
|
5115
5239
|
keyIdForPublicKey: () => keyIdForPublicKey,
|
|
5240
|
+
localStorageHeadHighWater: () => localStorageHeadHighWater,
|
|
5116
5241
|
memorySenderHeldKeyStore: () => memorySenderHeldKeyStore,
|
|
5117
5242
|
normaliseAddress: () => normaliseAddress,
|
|
5118
5243
|
normalizeForBlindIndex: () => normalizeForBlindIndex,
|
|
@@ -5120,6 +5245,8 @@ __export(src_exports, {
|
|
|
5120
5245
|
parseOprfSeed: () => parseOprfSeed,
|
|
5121
5246
|
partnerKeyFingerprint: () => partnerKeyFingerprint,
|
|
5122
5247
|
pinnedRegistryRoots: () => pinnedRegistryRoots,
|
|
5248
|
+
refundReviewNotifySigningString: () => refundReviewNotifySigningString,
|
|
5249
|
+
registryEnvironmentForOrigin: () => registryEnvironmentForOrigin,
|
|
5123
5250
|
rootIsPinned: () => rootIsPinned,
|
|
5124
5251
|
rootKeyIdFromSpki: () => rootKeyIdFromSpki,
|
|
5125
5252
|
rootKeyIdFromSpkiB64: () => rootKeyIdFromSpkiB64,
|
|
@@ -5752,6 +5879,7 @@ var init_src = __esm({
|
|
|
5752
5879
|
"use strict";
|
|
5753
5880
|
init_hybrid();
|
|
5754
5881
|
init_replay_window();
|
|
5882
|
+
init_refund_review_notify();
|
|
5755
5883
|
init_safe_url();
|
|
5756
5884
|
init_blocked_public_keys();
|
|
5757
5885
|
init_endpoint_health();
|
|
@@ -5812,7 +5940,11 @@ __export(index_exports, {
|
|
|
5812
5940
|
LoaV2RefusedError: () => LoaV2RefusedError,
|
|
5813
5941
|
MAX_ADDRESS_FIELD_CHARS: () => MAX_ADDRESS_FIELD_CHARS,
|
|
5814
5942
|
OUTBOX_LEASE_COLUMNS: () => OUTBOX_LEASE_COLUMNS,
|
|
5943
|
+
PRODUCT_CODE_PATTERN: () => PRODUCT_CODE_PATTERN,
|
|
5944
|
+
SDK_VERSION: () => SDK_VERSION,
|
|
5815
5945
|
SUPPORTED_VERSIONS: () => SUPPORTED_VERSIONS,
|
|
5946
|
+
UPDATE_GUIDE_URL: () => UPDATE_GUIDE_URL,
|
|
5947
|
+
VERIFICATION_COMMITMENT_VERSION: () => VERIFICATION_COMMITMENT_VERSION,
|
|
5816
5948
|
_resetLoaKeyCacheForTests: () => _resetLoaKeyCacheForTests,
|
|
5817
5949
|
_resetOnceWarningsForTests: () => _resetOnceWarningsForTests,
|
|
5818
5950
|
acceptTypedAliases: () => acceptTypedAliases,
|
|
@@ -5821,10 +5953,12 @@ __export(index_exports, {
|
|
|
5821
5953
|
cachedLoaPublicKey: () => cachedLoaPublicKey,
|
|
5822
5954
|
canonicalD5LoaForm: () => canonicalD5LoaForm,
|
|
5823
5955
|
canonicalD5LoaFormV2: () => canonicalD5LoaFormV2,
|
|
5956
|
+
checkForUpdate: () => checkForUpdate,
|
|
5824
5957
|
checkLoaV2: () => checkLoaV2,
|
|
5825
5958
|
checkRegistryHead: () => checkRegistryHead,
|
|
5826
5959
|
compareAddresses: () => compareAddresses,
|
|
5827
5960
|
computeBlindIndex: () => computeBlindIndex,
|
|
5961
|
+
computeVerificationCommitment: () => computeVerificationCommitment,
|
|
5828
5962
|
confirmUpdate: () => confirmUpdate,
|
|
5829
5963
|
createOneAddressHandler: () => createOneAddressHandler,
|
|
5830
5964
|
createOutboxConsumer: () => createOutboxConsumer,
|
|
@@ -5842,24 +5976,33 @@ __export(index_exports, {
|
|
|
5842
5976
|
isAcceptableAlias: () => isAcceptableAlias,
|
|
5843
5977
|
isEmailLike: () => isEmailLike2,
|
|
5844
5978
|
isFreshTimestamp: () => isFreshTimestamp,
|
|
5979
|
+
isNewerVersion: () => isNewerVersion,
|
|
5845
5980
|
loaEnvelopeSha256: () => loaEnvelopeSha256,
|
|
5846
5981
|
loaFirstName: () => loaFirstName,
|
|
5847
5982
|
loaNamesMatch: () => loaNamesMatch,
|
|
5848
5983
|
loaSurname: () => loaSurname,
|
|
5984
|
+
matchingWebhookSecret: () => matchingWebhookSecret,
|
|
5849
5985
|
namePoolMatches: () => namePoolMatches,
|
|
5986
|
+
normaliseCommitmentField: () => normaliseCommitmentField,
|
|
5850
5987
|
normaliseLoaName: () => normaliseLoaName,
|
|
5851
5988
|
normalizeForBlindIndex: () => normalizeForBlindIndex,
|
|
5852
5989
|
parsePinnedRegistryRoots: () => parsePinnedRegistryRoots,
|
|
5853
5990
|
readAddressParts: () => readAddressParts,
|
|
5991
|
+
readSessionProduct: () => readSessionProduct,
|
|
5854
5992
|
sendVerifyResult: () => sendVerifyResult,
|
|
5855
5993
|
signPullRequest: () => signPullRequest,
|
|
5994
|
+
startUpdateCheck: () => startUpdateCheck,
|
|
5856
5995
|
toExpressHandler: () => toExpressHandler,
|
|
5857
5996
|
toOutboxTimestamp: () => toOutboxTimestamp,
|
|
5858
5997
|
transform: () => transformAddress,
|
|
5859
5998
|
transformAddress: () => transformAddress,
|
|
5860
5999
|
transformSession: () => transformSession,
|
|
5861
6000
|
typedAliasesOf: () => typedAliasesOf,
|
|
6001
|
+
updateAvailableLine: () => updateAvailableLine,
|
|
6002
|
+
updateCheckEnabled: () => updateCheckEnabled,
|
|
6003
|
+
updateCheckMetric: () => updateCheckMetric,
|
|
5862
6004
|
validateAddress: () => validateAddress,
|
|
6005
|
+
verificationCommitmentString: () => verificationCommitmentString,
|
|
5863
6006
|
verify: () => verifySignature,
|
|
5864
6007
|
verifyD5LOA: () => verifyD5LOA,
|
|
5865
6008
|
verifyD5LOAv2: () => verifyD5LOAv2,
|
|
@@ -6068,6 +6211,33 @@ var LOA_V2_REFUSALS = [
|
|
|
6068
6211
|
"loa_v2_name_mismatch"
|
|
6069
6212
|
];
|
|
6070
6213
|
|
|
6214
|
+
// ../protocol/src/verification-commitment.ts
|
|
6215
|
+
var VERIFICATION_COMMITMENT_VERSION = "oa-verify.v1";
|
|
6216
|
+
var ASCII_WHITESPACE_RUN = /[\t\n\v\f\r ]+/g;
|
|
6217
|
+
function normaliseCommitmentField(value) {
|
|
6218
|
+
if (typeof value !== "string") return "";
|
|
6219
|
+
const collapsed = value.replace(ASCII_WHITESPACE_RUN, " ");
|
|
6220
|
+
const start = collapsed.startsWith(" ") ? 1 : 0;
|
|
6221
|
+
const end = collapsed.length > start && collapsed.endsWith(" ") ? collapsed.length - 1 : collapsed.length;
|
|
6222
|
+
return collapsed.slice(start, end);
|
|
6223
|
+
}
|
|
6224
|
+
function verificationCommitmentString(verificationId, index, record) {
|
|
6225
|
+
if (!Number.isInteger(index) || index <= 0) {
|
|
6226
|
+
throw new RangeError(`verification commitment index must be a positive integer, got ${String(index)}`);
|
|
6227
|
+
}
|
|
6228
|
+
return [
|
|
6229
|
+
VERIFICATION_COMMITMENT_VERSION,
|
|
6230
|
+
normaliseCommitmentField(verificationId),
|
|
6231
|
+
String(index),
|
|
6232
|
+
normaliseCommitmentField(record.name),
|
|
6233
|
+
normaliseCommitmentField(record.street),
|
|
6234
|
+
normaliseCommitmentField(record.suburb),
|
|
6235
|
+
normaliseCommitmentField(record.state),
|
|
6236
|
+
normaliseCommitmentField(record.postcode),
|
|
6237
|
+
normaliseCommitmentField(record.country)
|
|
6238
|
+
].join("\n");
|
|
6239
|
+
}
|
|
6240
|
+
|
|
6071
6241
|
// src/app-hosts.ts
|
|
6072
6242
|
function allowedAppHosts() {
|
|
6073
6243
|
const hosts = ["oneaddress.io", "app.oneaddress.io"];
|
|
@@ -6101,6 +6271,96 @@ function resolveAppOrigin(baseUrl, label, extraHosts) {
|
|
|
6101
6271
|
return parsed.origin;
|
|
6102
6272
|
}
|
|
6103
6273
|
|
|
6274
|
+
// src/update-check.ts
|
|
6275
|
+
var SDK_VERSION = "2.10.0";
|
|
6276
|
+
var UPDATE_GUIDE_URL = "https://partners.oneaddress.io/#updating-safely";
|
|
6277
|
+
var REGISTRY_URL = "https://registry.npmjs.org/@oneaddress/partner-sdk/latest";
|
|
6278
|
+
var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
|
|
6279
|
+
var TIMEOUT_MS = 5e3;
|
|
6280
|
+
function updateCheckEnabled(setting) {
|
|
6281
|
+
const s = (setting ?? "").trim().toLowerCase();
|
|
6282
|
+
return !(s === "off" || s === "never" || s === "0" || s === "false");
|
|
6283
|
+
}
|
|
6284
|
+
function parseVersion(v) {
|
|
6285
|
+
if (typeof v !== "string") return null;
|
|
6286
|
+
const m = /^(\d{1,6})\.(\d{1,6})\.(\d{1,6})$/.exec(v.trim());
|
|
6287
|
+
return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;
|
|
6288
|
+
}
|
|
6289
|
+
function isNewerVersion(latest, running) {
|
|
6290
|
+
const a = parseVersion(latest);
|
|
6291
|
+
const b = parseVersion(running);
|
|
6292
|
+
if (!a || !b) return false;
|
|
6293
|
+
for (let i = 0; i < 3; i++) {
|
|
6294
|
+
if (a[i] !== b[i]) return a[i] > b[i];
|
|
6295
|
+
}
|
|
6296
|
+
return false;
|
|
6297
|
+
}
|
|
6298
|
+
function updateAvailableLine(running, latest) {
|
|
6299
|
+
return `update available: ${running} -> ${latest}, see ${UPDATE_GUIDE_URL}`;
|
|
6300
|
+
}
|
|
6301
|
+
function updateCheckMetric(result, product = "partner-sdk-ts") {
|
|
6302
|
+
const latest = result.latest ?? "unknown";
|
|
6303
|
+
const value = result.state === "available" ? 1 : 0;
|
|
6304
|
+
return `oneaddress_update_available{product="${product}",running="${result.running}",latest="${latest}"} ${value}`;
|
|
6305
|
+
}
|
|
6306
|
+
async function checkForUpdate(opts2 = {}) {
|
|
6307
|
+
const running = opts2.running ?? SDK_VERSION;
|
|
6308
|
+
const env = opts2.env ?? (typeof process !== "undefined" ? process.env : {});
|
|
6309
|
+
if (!updateCheckEnabled(env.ONEADDRESS_UPDATE_CHECK)) return { state: "disabled", running };
|
|
6310
|
+
const fetchImpl = opts2.fetchImpl ?? globalThis.fetch;
|
|
6311
|
+
const now = opts2.now ?? Date.now;
|
|
6312
|
+
if (typeof fetchImpl !== "function") return { state: "unknown", running };
|
|
6313
|
+
const abort = new AbortController();
|
|
6314
|
+
const timer = setTimeout(() => abort.abort(), opts2.timeoutMs ?? TIMEOUT_MS);
|
|
6315
|
+
try {
|
|
6316
|
+
const res = await fetchImpl(opts2.registryUrl ?? REGISTRY_URL, { signal: abort.signal });
|
|
6317
|
+
const checkedAt = now();
|
|
6318
|
+
if (!res.ok) return { state: "unknown", running, checkedAt };
|
|
6319
|
+
const body = await res.json();
|
|
6320
|
+
if (!parseVersion(body?.version)) return { state: "unknown", running, checkedAt };
|
|
6321
|
+
const latest = body.version.trim();
|
|
6322
|
+
return {
|
|
6323
|
+
state: isNewerVersion(latest, running) ? "available" : "current",
|
|
6324
|
+
running,
|
|
6325
|
+
latest,
|
|
6326
|
+
checkedAt
|
|
6327
|
+
};
|
|
6328
|
+
} catch {
|
|
6329
|
+
return { state: "unknown", running };
|
|
6330
|
+
} finally {
|
|
6331
|
+
clearTimeout(timer);
|
|
6332
|
+
}
|
|
6333
|
+
}
|
|
6334
|
+
function startUpdateCheck(opts2 = {}) {
|
|
6335
|
+
const running = opts2.running ?? SDK_VERSION;
|
|
6336
|
+
let last = { state: "unknown", running };
|
|
6337
|
+
let announced = null;
|
|
6338
|
+
const log = opts2.log ?? ((line) => console.warn(line));
|
|
6339
|
+
const env = opts2.env ?? (typeof process !== "undefined" ? process.env : {});
|
|
6340
|
+
if (!updateCheckEnabled(env.ONEADDRESS_UPDATE_CHECK)) {
|
|
6341
|
+
last = { state: "disabled", running };
|
|
6342
|
+
opts2.onResult?.(last);
|
|
6343
|
+
return { current: () => last, stop: () => {
|
|
6344
|
+
} };
|
|
6345
|
+
}
|
|
6346
|
+
const run = async () => {
|
|
6347
|
+
const result = await checkForUpdate({ ...opts2, running, env });
|
|
6348
|
+
if (result.state !== "unknown" || last.state === "unknown") last = result;
|
|
6349
|
+
if (last.state === "available" && last.latest && last.latest !== announced) {
|
|
6350
|
+
announced = last.latest;
|
|
6351
|
+
log(updateAvailableLine(running, last.latest));
|
|
6352
|
+
}
|
|
6353
|
+
opts2.onResult?.(last);
|
|
6354
|
+
};
|
|
6355
|
+
void run();
|
|
6356
|
+
const every = Math.max(opts2.intervalMs ?? ONE_DAY_MS, 60 * 60 * 1e3);
|
|
6357
|
+
const timer = setInterval(() => {
|
|
6358
|
+
void run();
|
|
6359
|
+
}, every);
|
|
6360
|
+
timer.unref?.();
|
|
6361
|
+
return { current: () => last, stop: () => clearInterval(timer) };
|
|
6362
|
+
}
|
|
6363
|
+
|
|
6104
6364
|
// src/index.ts
|
|
6105
6365
|
init_src();
|
|
6106
6366
|
init_src();
|
|
@@ -6756,14 +7016,21 @@ function signPullRequest(opts2) {
|
|
|
6756
7016
|
};
|
|
6757
7017
|
}
|
|
6758
7018
|
function verifyWithGrace(rawBody, timestamp, signature, currentSecret, previousSecret, graceUntil) {
|
|
6759
|
-
|
|
7019
|
+
return matchingWebhookSecret(rawBody, timestamp, signature, currentSecret, previousSecret, graceUntil) !== null;
|
|
7020
|
+
}
|
|
7021
|
+
function matchingWebhookSecret(rawBody, timestamp, signature, currentSecret, previousSecret, graceUntil) {
|
|
7022
|
+
if (verifySignature(rawBody, signature, timestamp, currentSecret)) return currentSecret;
|
|
6760
7023
|
if (previousSecret && previousSecret !== currentSecret && graceUntil) {
|
|
6761
7024
|
const until = typeof graceUntil === "number" ? graceUntil : Date.parse(graceUntil);
|
|
6762
|
-
if (!Number.isNaN(until) && Date.now() < until) {
|
|
6763
|
-
return
|
|
7025
|
+
if (!Number.isNaN(until) && Date.now() < until && verifySignature(rawBody, signature, timestamp, previousSecret)) {
|
|
7026
|
+
return previousSecret;
|
|
6764
7027
|
}
|
|
6765
7028
|
}
|
|
6766
|
-
return
|
|
7029
|
+
return null;
|
|
7030
|
+
}
|
|
7031
|
+
function computeVerificationCommitment(secret, verificationId, index, record) {
|
|
7032
|
+
if (!secret) throw new Error("[OneAddress SDK] a verification commitment needs the webhook secret");
|
|
7033
|
+
return import_crypto2.default.createHmac("sha256", secret).update(verificationCommitmentString(verificationId, index, record), "utf8").digest("hex");
|
|
6767
7034
|
}
|
|
6768
7035
|
function base64urlToBuffer(b64) {
|
|
6769
7036
|
return Buffer.from(b64.replace(/-/g, "+").replace(/_/g, "/"), "base64");
|
|
@@ -6829,15 +7096,34 @@ async function decryptAddress2(payload, privateKeyPem, partnerId) {
|
|
|
6829
7096
|
);
|
|
6830
7097
|
return JSON.parse(new TextDecoder().decode(plaintext));
|
|
6831
7098
|
}
|
|
7099
|
+
var PRODUCT_CODE_PATTERN = /^[a-z0-9][a-z0-9_-]{0,39}$/;
|
|
7100
|
+
function readSessionProduct(raw) {
|
|
7101
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
7102
|
+
const { id, code, name } = raw;
|
|
7103
|
+
if (typeof id !== "string" || typeof code !== "string" || !PRODUCT_CODE_PATTERN.test(code)) return null;
|
|
7104
|
+
return { id, code, name: typeof name === "string" && name !== "" ? name : code };
|
|
7105
|
+
}
|
|
7106
|
+
function normaliseSessionProduct(data) {
|
|
7107
|
+
if (!data || typeof data !== "object" || !("product" in data)) return data;
|
|
7108
|
+
const product = readSessionProduct(data.product);
|
|
7109
|
+
if (product === null && data.product != null) {
|
|
7110
|
+
console.warn(
|
|
7111
|
+
// NOSONAR - intentional SDK diagnostic, not user-controlled data
|
|
7112
|
+
"[OneAddress SDK] the session envelope carried a malformed product, so it is treated as absent and the update is handled as a plain account."
|
|
7113
|
+
);
|
|
7114
|
+
}
|
|
7115
|
+
return { ...data, product };
|
|
7116
|
+
}
|
|
6832
7117
|
async function decryptSession2(share, envelopeB64, privateKeyPem, partnerId, expectedAlg) {
|
|
6833
7118
|
const { decryptSession: decryptSessionCrypto } = await Promise.resolve().then(() => (init_src(), src_exports));
|
|
6834
|
-
|
|
7119
|
+
const data = await decryptSessionCrypto(
|
|
6835
7120
|
share,
|
|
6836
7121
|
envelopeB64,
|
|
6837
7122
|
typeof privateKeyPem === "string" ? pemToBase64(privateKeyPem) : privateKeyPem,
|
|
6838
7123
|
partnerId,
|
|
6839
7124
|
expectedAlg
|
|
6840
7125
|
);
|
|
7126
|
+
return normaliseSessionProduct(data);
|
|
6841
7127
|
}
|
|
6842
7128
|
async function transformAddress(payload, privateKeyPem, partnerId, recipientSpkiPem) {
|
|
6843
7129
|
const plaintext = await decryptAddress2(payload, privateKeyPem, partnerId);
|
|
@@ -6952,7 +7238,11 @@ async function confirmUpdate(opts2) {
|
|
|
6952
7238
|
"Content-Type": "application/json",
|
|
6953
7239
|
"X-OneAddress-Timestamp": timestamp,
|
|
6954
7240
|
"X-OneAddress-Signature": signature,
|
|
6955
|
-
[PULL_SIGNATURE_VERSION_HEADER]: "2"
|
|
7241
|
+
[PULL_SIGNATURE_VERSION_HEADER]: "2",
|
|
7242
|
+
// Which SDK sent this, so the partner portal can say when an update
|
|
7243
|
+
// exists. Software name and version only; outside the signature, and
|
|
7244
|
+
// recorded by OneAddress only after the signature verifies.
|
|
7245
|
+
"X-OneAddress-Client": `partner-sdk-ts/${SDK_VERSION}`
|
|
6956
7246
|
},
|
|
6957
7247
|
// The SAME string that was signed. Not an object, and not re-stringified.
|
|
6958
7248
|
body
|
|
@@ -7648,7 +7938,8 @@ function createOneAddressHandler(options) {
|
|
|
7648
7938
|
}
|
|
7649
7939
|
}
|
|
7650
7940
|
assertEffectiveDateBound(data.effective_date, body.effective_date);
|
|
7651
|
-
|
|
7941
|
+
const product = data.product ?? null;
|
|
7942
|
+
return { updateTypes, address, newPhone, newEmail, customer, loa, loa_ref, product, raw: data };
|
|
7652
7943
|
}
|
|
7653
7944
|
function isD5Body(body) {
|
|
7654
7945
|
return typeof body.session_envelope === "string" && !!body.session_key_share && typeof body.session_key_share === "object";
|
|
@@ -7677,7 +7968,8 @@ function createOneAddressHandler(options) {
|
|
|
7677
7968
|
headers: { "Content-Type": "application/json" }
|
|
7678
7969
|
});
|
|
7679
7970
|
}
|
|
7680
|
-
|
|
7971
|
+
const signingSecret = matchingWebhookSecret(rawBody, tsHeader, sig, webhookSecret, previousWebhookSecret, webhookSecretGraceUntil);
|
|
7972
|
+
if (signingSecret === null) {
|
|
7681
7973
|
return new Response(JSON.stringify({ error: "Invalid signature" }), {
|
|
7682
7974
|
status: 401,
|
|
7683
7975
|
headers: { "Content-Type": "application/json" }
|
|
@@ -7821,6 +8113,7 @@ function createOneAddressHandler(options) {
|
|
|
7821
8113
|
loa_ref: d5.loa_ref,
|
|
7822
8114
|
id_verification: body.id_verification,
|
|
7823
8115
|
...body.effective_date !== void 0 ? { effective_date: body.effective_date } : {},
|
|
8116
|
+
product: d5.product,
|
|
7824
8117
|
raw: d5.raw
|
|
7825
8118
|
};
|
|
7826
8119
|
} else {
|
|
@@ -7889,6 +8182,8 @@ function createOneAddressHandler(options) {
|
|
|
7889
8182
|
loa,
|
|
7890
8183
|
loa_ref,
|
|
7891
8184
|
id_verification: body.id_verification,
|
|
8185
|
+
// The legacy blob predates product lines.
|
|
8186
|
+
product: null,
|
|
7892
8187
|
raw: rawAddress
|
|
7893
8188
|
};
|
|
7894
8189
|
}
|
|
@@ -8030,11 +8325,26 @@ function createOneAddressHandler(options) {
|
|
|
8030
8325
|
address: d5.address,
|
|
8031
8326
|
raw: d5.raw
|
|
8032
8327
|
});
|
|
8328
|
+
const index = typeof body.index === "number" ? body.index : void 0;
|
|
8329
|
+
const verificationId = typeof body.verification_id === "string" ? body.verification_id : "";
|
|
8330
|
+
let commitment;
|
|
8331
|
+
if (index !== void 0 && Number.isInteger(index) && index > 0 && verificationId) {
|
|
8332
|
+
const newAddress = d5.raw.new_address ?? {};
|
|
8333
|
+
commitment = computeVerificationCommitment(signingSecret, verificationId, index, {
|
|
8334
|
+
name: d5.raw.verified_name,
|
|
8335
|
+
street: newAddress.street,
|
|
8336
|
+
suburb: newAddress.suburb,
|
|
8337
|
+
state: newAddress.state,
|
|
8338
|
+
postcode: newAddress.postcode,
|
|
8339
|
+
country: newAddress.country
|
|
8340
|
+
});
|
|
8341
|
+
}
|
|
8033
8342
|
return declared(200, {
|
|
8034
8343
|
ok: true,
|
|
8035
8344
|
test: true,
|
|
8036
8345
|
verification: true,
|
|
8037
|
-
index
|
|
8346
|
+
index,
|
|
8347
|
+
...commitment ? { commitment } : {}
|
|
8038
8348
|
});
|
|
8039
8349
|
}
|
|
8040
8350
|
const evt = typeof body.event === "string" ? body.event : "(none)";
|
|
@@ -8257,7 +8567,11 @@ async function buildSignedTestWebhook(opts2) {
|
|
|
8257
8567
|
LoaV2RefusedError,
|
|
8258
8568
|
MAX_ADDRESS_FIELD_CHARS,
|
|
8259
8569
|
OUTBOX_LEASE_COLUMNS,
|
|
8570
|
+
PRODUCT_CODE_PATTERN,
|
|
8571
|
+
SDK_VERSION,
|
|
8260
8572
|
SUPPORTED_VERSIONS,
|
|
8573
|
+
UPDATE_GUIDE_URL,
|
|
8574
|
+
VERIFICATION_COMMITMENT_VERSION,
|
|
8261
8575
|
_resetLoaKeyCacheForTests,
|
|
8262
8576
|
_resetOnceWarningsForTests,
|
|
8263
8577
|
acceptTypedAliases,
|
|
@@ -8266,10 +8580,12 @@ async function buildSignedTestWebhook(opts2) {
|
|
|
8266
8580
|
cachedLoaPublicKey,
|
|
8267
8581
|
canonicalD5LoaForm,
|
|
8268
8582
|
canonicalD5LoaFormV2,
|
|
8583
|
+
checkForUpdate,
|
|
8269
8584
|
checkLoaV2,
|
|
8270
8585
|
checkRegistryHead,
|
|
8271
8586
|
compareAddresses,
|
|
8272
8587
|
computeBlindIndex,
|
|
8588
|
+
computeVerificationCommitment,
|
|
8273
8589
|
confirmUpdate,
|
|
8274
8590
|
createOneAddressHandler,
|
|
8275
8591
|
createOutboxConsumer,
|
|
@@ -8287,24 +8603,33 @@ async function buildSignedTestWebhook(opts2) {
|
|
|
8287
8603
|
isAcceptableAlias,
|
|
8288
8604
|
isEmailLike,
|
|
8289
8605
|
isFreshTimestamp,
|
|
8606
|
+
isNewerVersion,
|
|
8290
8607
|
loaEnvelopeSha256,
|
|
8291
8608
|
loaFirstName,
|
|
8292
8609
|
loaNamesMatch,
|
|
8293
8610
|
loaSurname,
|
|
8611
|
+
matchingWebhookSecret,
|
|
8294
8612
|
namePoolMatches,
|
|
8613
|
+
normaliseCommitmentField,
|
|
8295
8614
|
normaliseLoaName,
|
|
8296
8615
|
normalizeForBlindIndex,
|
|
8297
8616
|
parsePinnedRegistryRoots,
|
|
8298
8617
|
readAddressParts,
|
|
8618
|
+
readSessionProduct,
|
|
8299
8619
|
sendVerifyResult,
|
|
8300
8620
|
signPullRequest,
|
|
8621
|
+
startUpdateCheck,
|
|
8301
8622
|
toExpressHandler,
|
|
8302
8623
|
toOutboxTimestamp,
|
|
8303
8624
|
transform,
|
|
8304
8625
|
transformAddress,
|
|
8305
8626
|
transformSession,
|
|
8306
8627
|
typedAliasesOf,
|
|
8628
|
+
updateAvailableLine,
|
|
8629
|
+
updateCheckEnabled,
|
|
8630
|
+
updateCheckMetric,
|
|
8307
8631
|
validateAddress,
|
|
8632
|
+
verificationCommitmentString,
|
|
8308
8633
|
verify,
|
|
8309
8634
|
verifyD5LOA,
|
|
8310
8635
|
verifyD5LOAv2,
|