@oneaddress/partner-sdk 2.7.0 → 2.8.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 +138 -0
- package/README.md +184 -61
- package/dist/{chunk-OKAJO4T6.mjs → chunk-BFSYMDJI.mjs} +513 -50
- package/dist/{chunk-CLV6TLSP.mjs → chunk-PP2TM7HN.mjs} +80 -0
- package/dist/edge.d.mts +1 -1
- package/dist/edge.d.ts +1 -1
- package/dist/edge.js +534 -41
- package/dist/edge.mjs +28 -2
- package/dist/index.d.mts +399 -52
- package/dist/index.d.ts +399 -52
- package/dist/index.js +614 -48
- package/dist/index.mjs +48 -2
- package/dist/{src-FPYBM6X6.mjs → src-P3LR7F4A.mjs} +1 -1
- package/package.json +1 -1
package/dist/edge.js
CHANGED
|
@@ -4146,6 +4146,69 @@ function isBlockedIPv4(host) {
|
|
|
4146
4146
|
if (a === 192 && b === 168) return true;
|
|
4147
4147
|
if (a === 169 && b === 254) return true;
|
|
4148
4148
|
if (a === 100 && b >= 64 && b <= 127) return true;
|
|
4149
|
+
const c = octets[2];
|
|
4150
|
+
if (a === 192 && b === 0 && c === 0) return true;
|
|
4151
|
+
if (a === 198 && (b === 18 || b === 19)) return true;
|
|
4152
|
+
if (a >= 224 && a <= 239) return true;
|
|
4153
|
+
if (a >= 240) return true;
|
|
4154
|
+
return false;
|
|
4155
|
+
}
|
|
4156
|
+
function expandIPv6(clean2) {
|
|
4157
|
+
let text = clean2;
|
|
4158
|
+
const tail = [];
|
|
4159
|
+
const dotted = /^(.*:)(\d+\.\d+\.\d+\.\d+)$/.exec(text);
|
|
4160
|
+
if (dotted) {
|
|
4161
|
+
const parts = dotted[2].split(".").map((x) => Number.parseInt(x, 10));
|
|
4162
|
+
if (parts.some((x) => !Number.isInteger(x) || x > 255)) return null;
|
|
4163
|
+
tail.push(parts[0] << 8 | parts[1], parts[2] << 8 | parts[3]);
|
|
4164
|
+
text = dotted[1].endsWith("::") ? dotted[1] : dotted[1].slice(0, -1);
|
|
4165
|
+
}
|
|
4166
|
+
const halves = text.split("::");
|
|
4167
|
+
if (halves.length > 2) return null;
|
|
4168
|
+
const parse = (s) => {
|
|
4169
|
+
if (s === "") return [];
|
|
4170
|
+
const out = [];
|
|
4171
|
+
for (const g of s.split(":")) {
|
|
4172
|
+
if (!/^[0-9a-f]{1,4}$/.test(g)) return null;
|
|
4173
|
+
out.push(Number.parseInt(g, 16));
|
|
4174
|
+
}
|
|
4175
|
+
return out;
|
|
4176
|
+
};
|
|
4177
|
+
const head = parse(halves[0]);
|
|
4178
|
+
const rest = halves.length === 2 ? parse(halves[1]) : [];
|
|
4179
|
+
if (!head || !rest) return null;
|
|
4180
|
+
const known = head.length + rest.length + tail.length;
|
|
4181
|
+
if (halves.length === 1) {
|
|
4182
|
+
return known === 8 ? [...head, ...tail] : null;
|
|
4183
|
+
}
|
|
4184
|
+
if (known > 7) return null;
|
|
4185
|
+
return [...head, ...new Array(8 - known).fill(0), ...rest, ...tail];
|
|
4186
|
+
}
|
|
4187
|
+
function v4FromGroups(high, low) {
|
|
4188
|
+
return `${high >> 8 & 255}.${high & 255}.${low >> 8 & 255}.${low & 255}`;
|
|
4189
|
+
}
|
|
4190
|
+
function isBlockedIPv6Groups(g) {
|
|
4191
|
+
const first = g[0];
|
|
4192
|
+
if ((first & 65280) === 65280) return true;
|
|
4193
|
+
if ((first & 65472) === 65152) return true;
|
|
4194
|
+
if ((first & 65472) === 65216) return true;
|
|
4195
|
+
if ((first & 65024) === 64512) return true;
|
|
4196
|
+
if (first === 8194) return isBlockedIPv4(v4FromGroups(g[1], g[2]));
|
|
4197
|
+
if (first === 100 && g[1] === 65435) {
|
|
4198
|
+
if (g[2] === 0 && g[3] === 0 && g[4] === 0 && g[5] === 0) return isBlockedIPv4(v4FromGroups(g[6], g[7]));
|
|
4199
|
+
if (g[2] === 1) return isBlockedIPv4(v4FromGroups(g[6], g[7]));
|
|
4200
|
+
return true;
|
|
4201
|
+
}
|
|
4202
|
+
if (g[0] === 0 && g[1] === 0 && g[2] === 0 && g[3] === 0 && g[4] === 0) {
|
|
4203
|
+
if (g[5] === 65535 || g[5] === 0) {
|
|
4204
|
+
if (g[5] === 0 && g[6] === 0 && g[7] <= 1) return true;
|
|
4205
|
+
return isBlockedIPv4(v4FromGroups(g[6], g[7]));
|
|
4206
|
+
}
|
|
4207
|
+
return true;
|
|
4208
|
+
}
|
|
4209
|
+
if (g[0] === 0 && g[1] === 0 && g[2] === 0 && g[3] === 0 && g[4] === 65535 && g[5] === 0) {
|
|
4210
|
+
return isBlockedIPv4(v4FromGroups(g[6], g[7]));
|
|
4211
|
+
}
|
|
4149
4212
|
return false;
|
|
4150
4213
|
}
|
|
4151
4214
|
function v4FromHexPair(highHex, lowHex) {
|
|
@@ -4165,6 +4228,9 @@ function isBlockedIPv6(host) {
|
|
|
4165
4228
|
}
|
|
4166
4229
|
clean2 = clean2.split("%")[0];
|
|
4167
4230
|
if (!clean2.includes(":")) return false;
|
|
4231
|
+
const groups = expandIPv6(clean2);
|
|
4232
|
+
if (!groups) return true;
|
|
4233
|
+
if (isBlockedIPv6Groups(groups)) return true;
|
|
4168
4234
|
if (clean2 === "::1") return true;
|
|
4169
4235
|
if (clean2 === "::") return true;
|
|
4170
4236
|
if (clean2.startsWith("fe80:")) return true;
|
|
@@ -4548,12 +4614,26 @@ function hexToBytes4(hex) {
|
|
|
4548
4614
|
}
|
|
4549
4615
|
return out;
|
|
4550
4616
|
}
|
|
4617
|
+
function mapsAreCanonical(doc) {
|
|
4618
|
+
const canonical = (s) => typeof s === "string" && s === s.toLowerCase();
|
|
4619
|
+
for (const [partnerId, keyId] of Object.entries(doc.heads)) {
|
|
4620
|
+
if (!canonical(partnerId) || !canonical(keyId)) return false;
|
|
4621
|
+
}
|
|
4622
|
+
if (doc.staged === void 0) return true;
|
|
4623
|
+
if (!doc.staged || typeof doc.staged !== "object" || Array.isArray(doc.staged)) return false;
|
|
4624
|
+
for (const [partnerId, entry] of Object.entries(doc.staged)) {
|
|
4625
|
+
if (!canonical(partnerId) || !entry || typeof entry !== "object") return false;
|
|
4626
|
+
if (!canonical(entry.key_id) || !canonical(entry.key_sha256)) return false;
|
|
4627
|
+
}
|
|
4628
|
+
return true;
|
|
4629
|
+
}
|
|
4551
4630
|
async function verifyRegistryHead(doc, roots, now = /* @__PURE__ */ new Date()) {
|
|
4552
4631
|
try {
|
|
4553
4632
|
if (!doc || !KNOWN_VERSIONS.has(doc.version)) return "malformed";
|
|
4554
4633
|
if (doc.algorithm !== REGISTRY_HEAD_ALG) return "malformed";
|
|
4555
4634
|
if (typeof doc.signature !== "string" || !/^[0-9a-f]{128}$/i.test(doc.signature)) return "malformed";
|
|
4556
4635
|
if (!doc.heads || typeof doc.heads !== "object") return "malformed";
|
|
4636
|
+
if (!mapsAreCanonical(doc)) return "malformed";
|
|
4557
4637
|
const expires = Date.parse(doc.expires_at);
|
|
4558
4638
|
const issued = Date.parse(doc.issued_at);
|
|
4559
4639
|
if (Number.isNaN(expires) || Number.isNaN(issued)) return "malformed";
|
|
@@ -5721,8 +5801,12 @@ var edge_exports = {};
|
|
|
5721
5801
|
__export(edge_exports, {
|
|
5722
5802
|
CURRENT_VERSION: () => CURRENT_VERSION,
|
|
5723
5803
|
DEFAULT_REPLAY_WINDOW_SECS: () => DEFAULT_REPLAY_WINDOW_SECS,
|
|
5804
|
+
LoaV2RefusedError: () => LoaV2RefusedError,
|
|
5724
5805
|
SUPPORTED_VERSIONS: () => SUPPORTED_VERSIONS,
|
|
5806
|
+
acceptTypedAliases: () => acceptTypedAliases,
|
|
5725
5807
|
canonicalD5LoaForm: () => canonicalD5LoaForm,
|
|
5808
|
+
canonicalD5LoaFormV2: () => canonicalD5LoaFormV2,
|
|
5809
|
+
checkLoaV2: () => checkLoaV2,
|
|
5726
5810
|
compareAddresses: () => compareAddresses,
|
|
5727
5811
|
computeBlindIndex: () => computeBlindIndex,
|
|
5728
5812
|
createOneAddressHandler: () => createOneAddressHandler,
|
|
@@ -5732,15 +5816,24 @@ __export(edge_exports, {
|
|
|
5732
5816
|
decryptSession: () => decryptSession2,
|
|
5733
5817
|
fetchLoaPublicKey: () => fetchLoaPublicKey,
|
|
5734
5818
|
findMatchingStoredName: () => findMatchingStoredName,
|
|
5819
|
+
hasLoaV2: () => hasLoaV2,
|
|
5820
|
+
isAcceptableAlias: () => isAcceptableAlias,
|
|
5735
5821
|
isEmailLike: () => isEmailLike2,
|
|
5736
5822
|
isFreshTimestamp: () => isFreshTimestamp,
|
|
5823
|
+
loaEnvelopeSha256: () => loaEnvelopeSha256,
|
|
5824
|
+
loaFirstName: () => loaFirstName,
|
|
5825
|
+
loaNamesMatch: () => loaNamesMatch,
|
|
5826
|
+
loaSurname: () => loaSurname,
|
|
5737
5827
|
namePoolMatches: () => namePoolMatches,
|
|
5828
|
+
normaliseLoaName: () => normaliseLoaName,
|
|
5738
5829
|
normalizeForBlindIndex: () => normalizeForBlindIndex,
|
|
5739
5830
|
sendVerifyResult: () => sendVerifyResult,
|
|
5740
5831
|
transformAddress: () => transformAddress,
|
|
5741
5832
|
transformSession: () => transformSession,
|
|
5833
|
+
typedAliasesOf: () => typedAliasesOf,
|
|
5742
5834
|
validateAddress: () => validateAddress,
|
|
5743
5835
|
verifyD5LOA: () => verifyD5LOA,
|
|
5836
|
+
verifyD5LOAv2: () => verifyD5LOAv2,
|
|
5744
5837
|
verifyLOA: () => verifyLOA,
|
|
5745
5838
|
verifySignature: () => verifySignature,
|
|
5746
5839
|
verifyWithGrace: () => verifyWithGrace
|
|
@@ -5764,7 +5857,6 @@ var D5_BODY_ALWAYS = [
|
|
|
5764
5857
|
"partner_id",
|
|
5765
5858
|
"session_envelope",
|
|
5766
5859
|
"session_key_share",
|
|
5767
|
-
"stripe_session_id",
|
|
5768
5860
|
"timestamp",
|
|
5769
5861
|
"update_id",
|
|
5770
5862
|
"user_id"
|
|
@@ -5799,6 +5891,108 @@ var D5_BODY_ALL_ALLOWED = [
|
|
|
5799
5891
|
// ../protocol/src/retention.ts
|
|
5800
5892
|
var DAY_MS = 24 * 60 * 60 * 1e3;
|
|
5801
5893
|
|
|
5894
|
+
// ../protocol/src/pull-signature.ts
|
|
5895
|
+
var PULL_SIGNATURE_VERSION_HEADER = "X-OneAddress-Signature-Version";
|
|
5896
|
+
function pullSigningStringV2(timestamp, method, pathAndQuery, body = "") {
|
|
5897
|
+
return `v2.${timestamp}.${method.toUpperCase()}.${pathAndQuery}.${body}`;
|
|
5898
|
+
}
|
|
5899
|
+
|
|
5900
|
+
// ../protocol/src/loa-v2.ts
|
|
5901
|
+
var LOA_V2_VERSION_TAG = "oneaddress-loa/2";
|
|
5902
|
+
var LOA_V2_LEGACY_ENVELOPE_TAG = "oneaddress-legacy-envelope/1";
|
|
5903
|
+
var LOA_V2_FIELD_ORDER = [
|
|
5904
|
+
"consumer_name",
|
|
5905
|
+
"authorisation_date",
|
|
5906
|
+
"scope",
|
|
5907
|
+
"update_uid",
|
|
5908
|
+
"partner_id",
|
|
5909
|
+
"envelope_sha256"
|
|
5910
|
+
];
|
|
5911
|
+
var LOA_MAX_TYPED_ALIASES = 3;
|
|
5912
|
+
var LoaV2FieldError = class extends Error {
|
|
5913
|
+
constructor(field, reason) {
|
|
5914
|
+
super(`LOA v2 field ${field} ${reason}`);
|
|
5915
|
+
this.field = field;
|
|
5916
|
+
this.name = "LoaV2FieldError";
|
|
5917
|
+
}
|
|
5918
|
+
};
|
|
5919
|
+
var CONTROL_RE = /[\u0000-\u001F\u007F]/;
|
|
5920
|
+
var LONE_SURROGATE_RE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;
|
|
5921
|
+
function utf8Length(s) {
|
|
5922
|
+
return new TextEncoder().encode(s).length;
|
|
5923
|
+
}
|
|
5924
|
+
function encodeField(name, value) {
|
|
5925
|
+
if (typeof value !== "string") throw new LoaV2FieldError(name, "is not a string");
|
|
5926
|
+
if (CONTROL_RE.test(value)) throw new LoaV2FieldError(name, "contains a control character");
|
|
5927
|
+
if (LONE_SURROGATE_RE.test(value)) throw new LoaV2FieldError(name, "is not well-formed Unicode");
|
|
5928
|
+
return `${utf8Length(value)}:${value}
|
|
5929
|
+
`;
|
|
5930
|
+
}
|
|
5931
|
+
function canonicalLoaV2(fields) {
|
|
5932
|
+
let out = encodeField("version", LOA_V2_VERSION_TAG);
|
|
5933
|
+
for (const f of LOA_V2_FIELD_ORDER) out += encodeField(f, fields[f]);
|
|
5934
|
+
const aliases = fields.consumer_typed_aliases;
|
|
5935
|
+
if (!Array.isArray(aliases)) throw new LoaV2FieldError("consumer_typed_aliases", "is not a list");
|
|
5936
|
+
if (aliases.length > LOA_MAX_TYPED_ALIASES) {
|
|
5937
|
+
throw new LoaV2FieldError("consumer_typed_aliases", `has more than ${LOA_MAX_TYPED_ALIASES} entries`);
|
|
5938
|
+
}
|
|
5939
|
+
out += encodeField("consumer_typed_aliases", String(aliases.length));
|
|
5940
|
+
for (const a of aliases) out += encodeField("consumer_typed_aliases", a);
|
|
5941
|
+
return out;
|
|
5942
|
+
}
|
|
5943
|
+
function loaV2EnvelopeDigestInput(envelope) {
|
|
5944
|
+
if (typeof envelope === "string") return envelope;
|
|
5945
|
+
if (!envelope || typeof envelope !== "object") {
|
|
5946
|
+
throw new LoaV2FieldError("envelope", "is neither a session_envelope string nor an address_encrypted object");
|
|
5947
|
+
}
|
|
5948
|
+
return encodeField("tag", LOA_V2_LEGACY_ENVELOPE_TAG) + encodeField("ephemeralPublicKey", envelope.ephemeralPublicKey) + encodeField("iv", envelope.iv) + encodeField("ciphertext", envelope.ciphertext) + encodeField("hkdfSalt", envelope.hkdfSalt ?? "");
|
|
5949
|
+
}
|
|
5950
|
+
var ASCII_WS_RE = /[ \t\n\v\f\r]+/;
|
|
5951
|
+
var MARK_RE = /\p{M}/gu;
|
|
5952
|
+
function normaliseLoaName(name) {
|
|
5953
|
+
return name.normalize("NFKD").replace(MARK_RE, "").toLowerCase().replace(/\u03C2/g, "\u03C3").split(ASCII_WS_RE).filter((t) => t.length > 0).join(" ");
|
|
5954
|
+
}
|
|
5955
|
+
function loaSurname(name) {
|
|
5956
|
+
const tokens = normaliseLoaName(name).split(" ").filter((t) => t.length > 0);
|
|
5957
|
+
return tokens.length > 0 ? tokens[tokens.length - 1] : "";
|
|
5958
|
+
}
|
|
5959
|
+
function loaFirstName(name) {
|
|
5960
|
+
const tokens = normaliseLoaName(name).split(" ").filter((t) => t.length > 0);
|
|
5961
|
+
return tokens.length > 0 ? tokens[0] : "";
|
|
5962
|
+
}
|
|
5963
|
+
function loaNamesMatch(a, b) {
|
|
5964
|
+
const na = normaliseLoaName(a);
|
|
5965
|
+
return na.length > 0 && na === normaliseLoaName(b);
|
|
5966
|
+
}
|
|
5967
|
+
var LOA_MIN_SHORT_FORM_LETTERS = 3;
|
|
5968
|
+
function codePoints(s) {
|
|
5969
|
+
return Array.from(s).length;
|
|
5970
|
+
}
|
|
5971
|
+
function isAcceptableAlias(verifiedName, alias) {
|
|
5972
|
+
const vFirst = loaFirstName(verifiedName);
|
|
5973
|
+
const aFirst = loaFirstName(alias);
|
|
5974
|
+
if (!vFirst || !aFirst) return false;
|
|
5975
|
+
if (aFirst === vFirst) return true;
|
|
5976
|
+
const [shorter, longer] = codePoints(aFirst) <= codePoints(vFirst) ? [aFirst, vFirst] : [vFirst, aFirst];
|
|
5977
|
+
return codePoints(shorter) >= LOA_MIN_SHORT_FORM_LETTERS && longer.startsWith(shorter);
|
|
5978
|
+
}
|
|
5979
|
+
function acceptTypedAliases(verifiedName, aliases) {
|
|
5980
|
+
const out = [];
|
|
5981
|
+
if (!Array.isArray(aliases)) return out;
|
|
5982
|
+
const seen = /* @__PURE__ */ new Set([normaliseLoaName(verifiedName)]);
|
|
5983
|
+
for (const a of aliases) {
|
|
5984
|
+
if (out.length >= LOA_MAX_TYPED_ALIASES) break;
|
|
5985
|
+
if (typeof a !== "string") continue;
|
|
5986
|
+
if (CONTROL_RE.test(a) || LONE_SURROGATE_RE.test(a)) continue;
|
|
5987
|
+
const n = normaliseLoaName(a);
|
|
5988
|
+
if (!n || seen.has(n)) continue;
|
|
5989
|
+
if (!isAcceptableAlias(verifiedName, a)) continue;
|
|
5990
|
+
seen.add(n);
|
|
5991
|
+
out.push(a);
|
|
5992
|
+
}
|
|
5993
|
+
return out;
|
|
5994
|
+
}
|
|
5995
|
+
|
|
5802
5996
|
// src/app-hosts.ts
|
|
5803
5997
|
function allowedAppHosts() {
|
|
5804
5998
|
const hosts = ["oneaddress.io", "app.oneaddress.io"];
|
|
@@ -5807,7 +6001,7 @@ function allowedAppHosts() {
|
|
|
5807
6001
|
}
|
|
5808
6002
|
return new Set(hosts);
|
|
5809
6003
|
}
|
|
5810
|
-
function resolveAppOrigin(baseUrl, label) {
|
|
6004
|
+
function resolveAppOrigin(baseUrl, label, extraHosts) {
|
|
5811
6005
|
let parsed;
|
|
5812
6006
|
try {
|
|
5813
6007
|
parsed = new URL(baseUrl);
|
|
@@ -5815,6 +6009,9 @@ function resolveAppOrigin(baseUrl, label) {
|
|
|
5815
6009
|
throw new Error(`[OneAddress SDK] ${label}: appBaseUrl is not a valid URL`);
|
|
5816
6010
|
}
|
|
5817
6011
|
const allowed = allowedAppHosts();
|
|
6012
|
+
for (const h of extraHosts ?? []) {
|
|
6013
|
+
if (typeof h === "string" && h.trim() !== "") allowed.add(h.trim().toLowerCase());
|
|
6014
|
+
}
|
|
5818
6015
|
if (!allowed.has(parsed.hostname)) {
|
|
5819
6016
|
throw new Error(
|
|
5820
6017
|
`[OneAddress SDK] ${label}: appBaseUrl host must be one of: ${[...allowed].join(", ")}`
|
|
@@ -5850,26 +6047,38 @@ function surnameVariants(token) {
|
|
|
5850
6047
|
if (!token.includes("-")) return [token];
|
|
5851
6048
|
return [token, ...token.split("-").filter(Boolean)];
|
|
5852
6049
|
}
|
|
6050
|
+
var MAX_ALIASES = 10;
|
|
6051
|
+
var MAX_TOKENS_PER_NAME = 8;
|
|
6052
|
+
var MAX_POOL_TOKENS = 24;
|
|
5853
6053
|
function namePoolMatches(providedNames, storedName) {
|
|
5854
6054
|
if (isEmailLike2(storedName)) return false;
|
|
5855
|
-
const provided = providedNames.filter((n) =>
|
|
6055
|
+
const provided = providedNames.filter((n) => typeof n === "string" && n !== "" && !isEmailLike2(n));
|
|
5856
6056
|
const primary = tokenize(provided[0] ?? "");
|
|
5857
|
-
if (primary.length === 0) return false;
|
|
6057
|
+
if (primary.length === 0 || primary.length > MAX_TOKENS_PER_NAME) return false;
|
|
6058
|
+
const aliases = provided.slice(1, 1 + MAX_ALIASES).map(tokenize).filter((t) => t.length > 0 && t.length <= MAX_TOKENS_PER_NAME);
|
|
6059
|
+
const distinct = new Set(primary);
|
|
6060
|
+
for (const t of aliases) for (const tok of t) distinct.add(tok);
|
|
6061
|
+
if (distinct.size > MAX_POOL_TOKENS) return false;
|
|
5858
6062
|
const surnames = new Set(surnameVariants(primary[primary.length - 1]));
|
|
5859
|
-
for (
|
|
5860
|
-
const
|
|
5861
|
-
if (t.length >= 2) for (const v of surnameVariants(
|
|
5862
|
-
}
|
|
5863
|
-
const
|
|
5864
|
-
for (const
|
|
5865
|
-
const
|
|
6063
|
+
for (const t of aliases) {
|
|
6064
|
+
const last = t[t.length - 1];
|
|
6065
|
+
if (t.length >= 2 && last.length >= 2) for (const v of surnameVariants(last)) surnames.add(v);
|
|
6066
|
+
}
|
|
6067
|
+
const givenSet = /* @__PURE__ */ new Set();
|
|
6068
|
+
for (const tok of primary) if (!surnames.has(tok)) givenSet.add(tok);
|
|
6069
|
+
for (const t of aliases) for (const tok of t) if (tok.length >= 2 && !surnames.has(tok)) givenSet.add(tok);
|
|
6070
|
+
const given = [...givenSet];
|
|
6071
|
+
const fullGiven = given.filter((g) => g.length >= 2);
|
|
5866
6072
|
const stored = tokenize(storedName);
|
|
5867
|
-
if (stored.length
|
|
6073
|
+
if (stored.length < 2) return false;
|
|
5868
6074
|
const storedSurname = stored[stored.length - 1];
|
|
5869
6075
|
const storedGiven = stored.slice(0, -1);
|
|
5870
6076
|
if (!surnameVariants(storedSurname).some((v) => surnames.has(v))) return false;
|
|
5871
6077
|
const covered = (tok) => given.includes(tok) || tok.length === 1 && given.some((g) => g[0] === tok) || given.some((g) => g.length === 1 && g === tok[0]);
|
|
5872
|
-
|
|
6078
|
+
if (!storedGiven.every(covered)) return false;
|
|
6079
|
+
return storedGiven.some(
|
|
6080
|
+
(tok) => fullGiven.includes(tok) || tok.length === 1 && fullGiven.some((g) => g[0] === tok)
|
|
6081
|
+
);
|
|
5873
6082
|
}
|
|
5874
6083
|
function findMatchingStoredName(providedNames, storedCandidates) {
|
|
5875
6084
|
return storedCandidates.find((candidate) => namePoolMatches(providedNames, candidate));
|
|
@@ -6035,6 +6244,7 @@ async function transformSession(share, envelopeB64, privateKeyPem, partnerId, re
|
|
|
6035
6244
|
);
|
|
6036
6245
|
}
|
|
6037
6246
|
var OA_APP_BASE_URL = "https://oneaddress.io";
|
|
6247
|
+
var CONFIRM_PATH = "/api/confirm";
|
|
6038
6248
|
async function confirmUpdate(opts2) {
|
|
6039
6249
|
const {
|
|
6040
6250
|
partnerId,
|
|
@@ -6066,18 +6276,22 @@ async function confirmUpdate(opts2) {
|
|
|
6066
6276
|
...memberName !== void 0 ? { member_name: memberName } : {}
|
|
6067
6277
|
});
|
|
6068
6278
|
const timestamp = String(Math.floor(Date.now() / 1e3));
|
|
6069
|
-
const signature = import_crypto2.default.createHmac("sha256", secret).update(
|
|
6070
|
-
let
|
|
6071
|
-
|
|
6279
|
+
const signature = import_crypto2.default.createHmac("sha256", secret).update(pullSigningStringV2(timestamp, "POST", CONFIRM_PATH, body)).digest("hex");
|
|
6280
|
+
let origin;
|
|
6281
|
+
try {
|
|
6282
|
+
origin = resolveAppOrigin(appBaseUrl, "confirmUpdate", opts2.allowedHosts);
|
|
6283
|
+
} catch (err) {
|
|
6284
|
+
return { ok: false, status: 0, error: err instanceof Error ? err.message : String(err) };
|
|
6285
|
+
}
|
|
6072
6286
|
let res;
|
|
6073
6287
|
try {
|
|
6074
|
-
res = await fetchImpl(`${
|
|
6288
|
+
res = await fetchImpl(`${origin}${CONFIRM_PATH}`, {
|
|
6075
6289
|
method: "POST",
|
|
6076
6290
|
headers: {
|
|
6077
6291
|
"Content-Type": "application/json",
|
|
6078
|
-
"Authorization": `Bearer ${secret}`,
|
|
6079
6292
|
"X-OneAddress-Timestamp": timestamp,
|
|
6080
|
-
"X-OneAddress-Signature": signature
|
|
6293
|
+
"X-OneAddress-Signature": signature,
|
|
6294
|
+
[PULL_SIGNATURE_VERSION_HEADER]: "2"
|
|
6081
6295
|
},
|
|
6082
6296
|
// The SAME string that was signed. Not an object, and not re-stringified.
|
|
6083
6297
|
body
|
|
@@ -6103,6 +6317,44 @@ async function fetchLoaPublicKey(appBaseUrl = OA_APP_BASE_URL) {
|
|
|
6103
6317
|
}
|
|
6104
6318
|
return res.text();
|
|
6105
6319
|
}
|
|
6320
|
+
var LOA_PUBLIC_KEY_CACHE_MS = 24 * 60 * 60 * 1e3;
|
|
6321
|
+
var loaKeyCache = /* @__PURE__ */ new Map();
|
|
6322
|
+
var loaKeyInFlight = /* @__PURE__ */ new Map();
|
|
6323
|
+
var LoaPublicKeyUnavailableError = class extends Error {
|
|
6324
|
+
constructor(from, cause) {
|
|
6325
|
+
super(
|
|
6326
|
+
`[OneAddress SDK] could not fetch OneAddress's LOA public key from ${from} (${cause}). requireLoa is on (the default since 2.8.0), so this dispatch is refused and OneAddress will retry it. Pin the key with loaPublicKeyPem (from fetchLoaPublicKey), or set requireLoa: false to process dispatches without verifying consent.`
|
|
6327
|
+
);
|
|
6328
|
+
this.from = from;
|
|
6329
|
+
this.name = "LoaPublicKeyUnavailableError";
|
|
6330
|
+
}
|
|
6331
|
+
};
|
|
6332
|
+
async function cachedLoaPublicKey(appBaseUrl = OA_APP_BASE_URL, now = Date.now()) {
|
|
6333
|
+
const origin = resolveAppOrigin(appBaseUrl, "cachedLoaPublicKey");
|
|
6334
|
+
const held = loaKeyCache.get(origin);
|
|
6335
|
+
if (held && now - held.at < LOA_PUBLIC_KEY_CACHE_MS) return held.pem;
|
|
6336
|
+
let pending = loaKeyInFlight.get(origin);
|
|
6337
|
+
if (!pending) {
|
|
6338
|
+
pending = (async () => {
|
|
6339
|
+
const pem = (await fetchLoaPublicKey(origin)).trim();
|
|
6340
|
+
if (!pem.includes("-----BEGIN PUBLIC KEY-----")) {
|
|
6341
|
+
throw new Error("the response is not a PEM public key");
|
|
6342
|
+
}
|
|
6343
|
+
loaKeyCache.set(origin, { pem, at: Date.now() });
|
|
6344
|
+
return pem;
|
|
6345
|
+
})().finally(() => loaKeyInFlight.delete(origin));
|
|
6346
|
+
loaKeyInFlight.set(origin, pending);
|
|
6347
|
+
}
|
|
6348
|
+
try {
|
|
6349
|
+
return await pending;
|
|
6350
|
+
} catch (err) {
|
|
6351
|
+
if (held) return held.pem;
|
|
6352
|
+
throw new LoaPublicKeyUnavailableError(
|
|
6353
|
+
`${origin}/.well-known/oneaddress-loa-key.pem`,
|
|
6354
|
+
err instanceof Error ? err.message : String(err)
|
|
6355
|
+
);
|
|
6356
|
+
}
|
|
6357
|
+
}
|
|
6106
6358
|
async function verifyLOA(loa, publicKeyPem) {
|
|
6107
6359
|
if (loa.algorithm !== "ECDSA-P256") {
|
|
6108
6360
|
console.warn(
|
|
@@ -6182,6 +6434,91 @@ async function decryptLoaEncrypted(loaEncrypted, privateKeyPem, partnerId, expec
|
|
|
6182
6434
|
);
|
|
6183
6435
|
return data;
|
|
6184
6436
|
}
|
|
6437
|
+
function hasLoaV2(loa) {
|
|
6438
|
+
return typeof loa.oneaddress_signature_v2 === "string";
|
|
6439
|
+
}
|
|
6440
|
+
function canonicalD5LoaFormV2(loa) {
|
|
6441
|
+
return canonicalLoaV2({
|
|
6442
|
+
consumer_name: loa.consumer_name,
|
|
6443
|
+
authorisation_date: loa.authorisation_date,
|
|
6444
|
+
scope: loa.scope,
|
|
6445
|
+
update_uid: loa.update_uid,
|
|
6446
|
+
partner_id: loa.partner_id,
|
|
6447
|
+
envelope_sha256: loa.envelope_sha256,
|
|
6448
|
+
consumer_typed_aliases: loa.consumer_typed_aliases
|
|
6449
|
+
});
|
|
6450
|
+
}
|
|
6451
|
+
function loaEnvelopeSha256(envelope) {
|
|
6452
|
+
return import_crypto2.default.createHash("sha256").update(loaV2EnvelopeDigestInput(envelope), "utf8").digest("hex");
|
|
6453
|
+
}
|
|
6454
|
+
async function verifyD5LOAv2(loa, publicKeyPem) {
|
|
6455
|
+
if (loa.signature_algorithm !== "ECDSA-P256" || !hasLoaV2(loa)) return false;
|
|
6456
|
+
let text;
|
|
6457
|
+
try {
|
|
6458
|
+
text = canonicalD5LoaFormV2(loa);
|
|
6459
|
+
} catch {
|
|
6460
|
+
return false;
|
|
6461
|
+
}
|
|
6462
|
+
try {
|
|
6463
|
+
const key = await import_crypto2.default.subtle.importKey(
|
|
6464
|
+
"spki",
|
|
6465
|
+
pemToBuffer(publicKeyPem),
|
|
6466
|
+
{ name: "ECDSA", namedCurve: "P-256" },
|
|
6467
|
+
false,
|
|
6468
|
+
["verify"]
|
|
6469
|
+
);
|
|
6470
|
+
return await import_crypto2.default.subtle.verify(
|
|
6471
|
+
{ name: "ECDSA", hash: "SHA-256" },
|
|
6472
|
+
key,
|
|
6473
|
+
Buffer.from(loa.oneaddress_signature_v2, "hex"),
|
|
6474
|
+
new TextEncoder().encode(text)
|
|
6475
|
+
);
|
|
6476
|
+
} catch {
|
|
6477
|
+
return false;
|
|
6478
|
+
}
|
|
6479
|
+
}
|
|
6480
|
+
function typedAliasesOf(loa) {
|
|
6481
|
+
if (!hasLoaV2(loa)) return [];
|
|
6482
|
+
return acceptTypedAliases(loa.consumer_name, loa.consumer_typed_aliases);
|
|
6483
|
+
}
|
|
6484
|
+
function bodyUpdateIdString(v) {
|
|
6485
|
+
if (typeof v === "string") return v;
|
|
6486
|
+
if (typeof v === "number" && Number.isSafeInteger(v)) return String(v);
|
|
6487
|
+
return null;
|
|
6488
|
+
}
|
|
6489
|
+
async function checkLoaV2(loa, ctx) {
|
|
6490
|
+
if (!hasLoaV2(loa) || typeof loa.partner_id !== "string" || typeof loa.envelope_sha256 !== "string") {
|
|
6491
|
+
return "loa_v2_malformed";
|
|
6492
|
+
}
|
|
6493
|
+
try {
|
|
6494
|
+
canonicalD5LoaFormV2(loa);
|
|
6495
|
+
} catch {
|
|
6496
|
+
return "loa_v2_malformed";
|
|
6497
|
+
}
|
|
6498
|
+
if (ctx.publicKeyPem !== void 0 && !await verifyD5LOAv2(loa, ctx.publicKeyPem)) {
|
|
6499
|
+
return "loa_v2_signature_invalid";
|
|
6500
|
+
}
|
|
6501
|
+
if (loa.partner_id !== ctx.partnerId) return "loa_v2_partner_mismatch";
|
|
6502
|
+
if (bodyUpdateIdString(ctx.updateId) !== loa.update_uid) return "loa_v2_update_mismatch";
|
|
6503
|
+
let digest;
|
|
6504
|
+
try {
|
|
6505
|
+
digest = loaEnvelopeSha256(ctx.envelope);
|
|
6506
|
+
} catch {
|
|
6507
|
+
return "loa_v2_envelope_mismatch";
|
|
6508
|
+
}
|
|
6509
|
+
if (digest !== loa.envelope_sha256) return "loa_v2_envelope_mismatch";
|
|
6510
|
+
if (typeof ctx.envelopeVerifiedName !== "string" || !loaNamesMatch(ctx.envelopeVerifiedName, loa.consumer_name)) {
|
|
6511
|
+
return "loa_v2_name_mismatch";
|
|
6512
|
+
}
|
|
6513
|
+
return null;
|
|
6514
|
+
}
|
|
6515
|
+
var LoaV2RefusedError = class extends Error {
|
|
6516
|
+
constructor(code) {
|
|
6517
|
+
super(`[OneAddress SDK] D5 LOA v2 refused (${code}); refusing rather than applying an update the consent record does not cover`);
|
|
6518
|
+
this.code = code;
|
|
6519
|
+
this.name = "LoaV2RefusedError";
|
|
6520
|
+
}
|
|
6521
|
+
};
|
|
6185
6522
|
var ADDRESS_REQUIRED_FIELDS = [
|
|
6186
6523
|
"street",
|
|
6187
6524
|
"suburb",
|
|
@@ -6189,19 +6526,60 @@ var ADDRESS_REQUIRED_FIELDS = [
|
|
|
6189
6526
|
"postcode",
|
|
6190
6527
|
"country"
|
|
6191
6528
|
];
|
|
6529
|
+
var MAX_ADDRESS_FIELD_CHARS = 512;
|
|
6192
6530
|
function validateAddress(raw) {
|
|
6193
|
-
if (typeof raw !== "object" || raw === null) {
|
|
6531
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
6194
6532
|
throw new Error("[OneAddress SDK] Decrypted address payload is not an object");
|
|
6195
6533
|
}
|
|
6196
6534
|
const obj = raw;
|
|
6197
6535
|
for (const field of ADDRESS_REQUIRED_FIELDS) {
|
|
6198
|
-
|
|
6536
|
+
const value = obj[field];
|
|
6537
|
+
if (typeof value !== "string" || value === "") {
|
|
6538
|
+
throw new Error(
|
|
6539
|
+
`[OneAddress SDK] Decrypted address is missing required field "${field}". This may indicate a decryption error or a schema change - update @oneaddress/partner-sdk.`
|
|
6540
|
+
);
|
|
6541
|
+
}
|
|
6542
|
+
if (value.length > MAX_ADDRESS_FIELD_CHARS) {
|
|
6199
6543
|
throw new Error(
|
|
6200
|
-
`[OneAddress SDK] Decrypted address
|
|
6544
|
+
`[OneAddress SDK] Decrypted address field "${field}" is ${value.length} characters, over the ${MAX_ADDRESS_FIELD_CHARS} this SDK accepts; refusing rather than truncating`
|
|
6201
6545
|
);
|
|
6202
6546
|
}
|
|
6203
6547
|
}
|
|
6204
|
-
|
|
6548
|
+
const rawUpdatedAt = obj.updated_at;
|
|
6549
|
+
let updatedAt;
|
|
6550
|
+
if (rawUpdatedAt === void 0 || rawUpdatedAt === null) updatedAt = "";
|
|
6551
|
+
else if (typeof rawUpdatedAt === "number" && Number.isFinite(rawUpdatedAt)) updatedAt = String(rawUpdatedAt);
|
|
6552
|
+
else if (typeof rawUpdatedAt === "string") updatedAt = rawUpdatedAt;
|
|
6553
|
+
else throw new Error('[OneAddress SDK] Decrypted address field "updated_at" is not a string');
|
|
6554
|
+
if (updatedAt.length > MAX_ADDRESS_FIELD_CHARS) {
|
|
6555
|
+
throw new Error(
|
|
6556
|
+
`[OneAddress SDK] Decrypted address field "updated_at" is over the ${MAX_ADDRESS_FIELD_CHARS} characters this SDK accepts`
|
|
6557
|
+
);
|
|
6558
|
+
}
|
|
6559
|
+
return {
|
|
6560
|
+
street: obj.street,
|
|
6561
|
+
suburb: obj.suburb,
|
|
6562
|
+
state: obj.state,
|
|
6563
|
+
postcode: obj.postcode,
|
|
6564
|
+
country: obj.country,
|
|
6565
|
+
updated_at: updatedAt
|
|
6566
|
+
};
|
|
6567
|
+
}
|
|
6568
|
+
function legacyAddressOf(blob, body) {
|
|
6569
|
+
return validateAddress({
|
|
6570
|
+
street: blob.street,
|
|
6571
|
+
suburb: blob.suburb,
|
|
6572
|
+
state: blob.state,
|
|
6573
|
+
postcode: blob.postcode,
|
|
6574
|
+
country: blob.country,
|
|
6575
|
+
updated_at: typeof blob.updated_at === "string" ? blob.updated_at : body.timestamp ?? ""
|
|
6576
|
+
});
|
|
6577
|
+
}
|
|
6578
|
+
function stringOr(value, fallback) {
|
|
6579
|
+
return typeof value === "string" ? value : fallback;
|
|
6580
|
+
}
|
|
6581
|
+
function stringsOf(value) {
|
|
6582
|
+
return Array.isArray(value) ? value.filter((v) => typeof v === "string") : [];
|
|
6205
6583
|
}
|
|
6206
6584
|
var STREET_SUFFIX_MAP = {
|
|
6207
6585
|
st: "street",
|
|
@@ -6353,6 +6731,41 @@ var warnedUnhandledEvents = /* @__PURE__ */ new Set();
|
|
|
6353
6731
|
var warnedConsentUnverified = false;
|
|
6354
6732
|
var warnedNoIdempotencyStore = false;
|
|
6355
6733
|
var MAX_TIMESTAMP_TOLERANCE_SECS = 86400;
|
|
6734
|
+
var DEFAULT_MAX_BODY_BYTES = 1048576;
|
|
6735
|
+
var IN_PROGRESS_RETRY_AFTER_SECS = 30;
|
|
6736
|
+
async function readBodyCapped(req, max) {
|
|
6737
|
+
const declaredLength = req.headers.get("content-length");
|
|
6738
|
+
if (declaredLength !== null && /^\s*\d+\s*$/.test(declaredLength) && Number(declaredLength) > max) {
|
|
6739
|
+
return null;
|
|
6740
|
+
}
|
|
6741
|
+
const stream = req.body;
|
|
6742
|
+
if (stream && typeof stream.getReader === "function") {
|
|
6743
|
+
const reader = stream.getReader();
|
|
6744
|
+
const chunks = [];
|
|
6745
|
+
let total = 0;
|
|
6746
|
+
for (; ; ) {
|
|
6747
|
+
const { done, value } = await reader.read();
|
|
6748
|
+
if (done) break;
|
|
6749
|
+
if (!value) continue;
|
|
6750
|
+
total += value.byteLength;
|
|
6751
|
+
if (total > max) {
|
|
6752
|
+
await reader.cancel().catch(() => void 0);
|
|
6753
|
+
return null;
|
|
6754
|
+
}
|
|
6755
|
+
chunks.push(value);
|
|
6756
|
+
}
|
|
6757
|
+
const joined = new Uint8Array(total);
|
|
6758
|
+
let offset = 0;
|
|
6759
|
+
for (const c of chunks) {
|
|
6760
|
+
joined.set(c, offset);
|
|
6761
|
+
offset += c.byteLength;
|
|
6762
|
+
}
|
|
6763
|
+
return new TextDecoder("utf-8").decode(joined);
|
|
6764
|
+
}
|
|
6765
|
+
const text = await req.text();
|
|
6766
|
+
if (text.length > max || new TextEncoder().encode(text).byteLength > max) return null;
|
|
6767
|
+
return text;
|
|
6768
|
+
}
|
|
6356
6769
|
var XWING_SEED_BYTES = 32;
|
|
6357
6770
|
function assertUsablePrivateKey(privateKeyPem) {
|
|
6358
6771
|
if (typeof privateKeyPem !== "string") {
|
|
@@ -6399,13 +6812,16 @@ function createOneAddressHandler(options) {
|
|
|
6399
6812
|
expectedAlg,
|
|
6400
6813
|
keyId,
|
|
6401
6814
|
loaPublicKeyPem,
|
|
6402
|
-
requireLoa =
|
|
6815
|
+
requireLoa = true,
|
|
6816
|
+
loaPublicKeyBaseUrl,
|
|
6403
6817
|
confirm,
|
|
6818
|
+
partnerId: configuredPartnerId,
|
|
6404
6819
|
onUpdate,
|
|
6405
6820
|
onVerify,
|
|
6406
6821
|
onAccountVerify,
|
|
6407
6822
|
onTest,
|
|
6408
6823
|
timestampToleranceSecs = 300,
|
|
6824
|
+
maxBodyBytes = DEFAULT_MAX_BODY_BYTES,
|
|
6409
6825
|
idempotencyStore,
|
|
6410
6826
|
acceptedUpdateTypes: acceptedUpdateTypesRaw,
|
|
6411
6827
|
allowedCallbackHosts
|
|
@@ -6419,6 +6835,9 @@ function createOneAddressHandler(options) {
|
|
|
6419
6835
|
`[OneAddress SDK] timestampToleranceSecs must be a positive number of seconds up to ${MAX_TIMESTAMP_TOLERANCE_SECS}, got ${String(timestampToleranceSecs)}`
|
|
6420
6836
|
);
|
|
6421
6837
|
}
|
|
6838
|
+
if (typeof maxBodyBytes !== "number" || !Number.isSafeInteger(maxBodyBytes) || maxBodyBytes <= 0) {
|
|
6839
|
+
throw new Error(`[OneAddress SDK] maxBodyBytes must be a positive whole number of bytes, got ${String(maxBodyBytes)}`);
|
|
6840
|
+
}
|
|
6422
6841
|
if (webhookSecretGraceUntil !== void 0) {
|
|
6423
6842
|
const until = typeof webhookSecretGraceUntil === "number" ? webhookSecretGraceUntil : Date.parse(webhookSecretGraceUntil);
|
|
6424
6843
|
if (Number.isNaN(until)) {
|
|
@@ -6428,6 +6847,15 @@ function createOneAddressHandler(options) {
|
|
|
6428
6847
|
if (confirm && (!confirm.partnerId || !confirm.confirmSecret)) {
|
|
6429
6848
|
throw new Error("[OneAddress SDK] confirm needs both partnerId and confirmSecret");
|
|
6430
6849
|
}
|
|
6850
|
+
if (typeof requireLoa !== "boolean") {
|
|
6851
|
+
throw new Error(`[OneAddress SDK] requireLoa must be true or false, got ${String(requireLoa)}`);
|
|
6852
|
+
}
|
|
6853
|
+
if (loaPublicKeyBaseUrl !== void 0) resolveAppOrigin(loaPublicKeyBaseUrl, "loaPublicKeyBaseUrl");
|
|
6854
|
+
async function loaVerificationKey() {
|
|
6855
|
+
if (loaPublicKeyPem) return loaPublicKeyPem;
|
|
6856
|
+
if (!requireLoa) return void 0;
|
|
6857
|
+
return cachedLoaPublicKey(loaPublicKeyBaseUrl ?? OA_APP_BASE_URL);
|
|
6858
|
+
}
|
|
6431
6859
|
function enforceLoaPresence(body) {
|
|
6432
6860
|
const present = !!body.loa_encrypted && typeof body.loa_encrypted === "object";
|
|
6433
6861
|
if (present) return;
|
|
@@ -6440,7 +6868,7 @@ function createOneAddressHandler(options) {
|
|
|
6440
6868
|
warnedConsentUnverified = true;
|
|
6441
6869
|
console.warn(
|
|
6442
6870
|
// NOSONAR - intentional SDK diagnostic, not user-controlled data
|
|
6443
|
-
"[OneAddress SDK] a dispatch arrived with no loa_encrypted and requireLoa is off, so consent for this update is UNVERIFIED.
|
|
6871
|
+
"[OneAddress SDK] a dispatch arrived with no loa_encrypted and requireLoa is off, so consent for this update is UNVERIFIED. Remove requireLoa: false (it is on by default) to refuse such dispatches. Logged once per process."
|
|
6444
6872
|
);
|
|
6445
6873
|
}
|
|
6446
6874
|
}
|
|
@@ -6475,9 +6903,9 @@ function createOneAddressHandler(options) {
|
|
|
6475
6903
|
const newEmail = updateTypes.includes("email") ? requireContactValue("email", data.new_email) : void 0;
|
|
6476
6904
|
const customer = {
|
|
6477
6905
|
email: "",
|
|
6478
|
-
name: data.verified_name
|
|
6479
|
-
account_number: data.account_number
|
|
6480
|
-
known_names:
|
|
6906
|
+
name: stringOr(data.verified_name, ""),
|
|
6907
|
+
account_number: stringOr(data.account_number, null),
|
|
6908
|
+
known_names: stringsOf(data.known_names)
|
|
6481
6909
|
};
|
|
6482
6910
|
let loa;
|
|
6483
6911
|
let loa_ref;
|
|
@@ -6489,11 +6917,23 @@ function createOneAddressHandler(options) {
|
|
|
6489
6917
|
expectedAlg
|
|
6490
6918
|
);
|
|
6491
6919
|
loa_ref = d5LoaRef(loa);
|
|
6492
|
-
|
|
6493
|
-
|
|
6920
|
+
const loaKey = await loaVerificationKey();
|
|
6921
|
+
if (loaKey) {
|
|
6922
|
+
const valid = await verifyD5LOA(loa, loaKey);
|
|
6494
6923
|
if (!valid) throw new Error("D5 LOA signature verification failed");
|
|
6495
6924
|
}
|
|
6496
6925
|
assertLoaBoundToEnvelope(loa, data.update_uid);
|
|
6926
|
+
if (hasLoaV2(loa)) {
|
|
6927
|
+
const refusal = await checkLoaV2(loa, {
|
|
6928
|
+
partnerId: configuredPartnerId ?? confirm?.partnerId ?? partnerId,
|
|
6929
|
+
updateId: body.update_id,
|
|
6930
|
+
envelope: body.session_envelope,
|
|
6931
|
+
envelopeVerifiedName: data.verified_name,
|
|
6932
|
+
...loaKey ? { publicKeyPem: loaKey } : {}
|
|
6933
|
+
});
|
|
6934
|
+
if (refusal) throw new LoaV2RefusedError(refusal);
|
|
6935
|
+
customer.known_names = typedAliasesOf(loa);
|
|
6936
|
+
}
|
|
6497
6937
|
}
|
|
6498
6938
|
return { updateTypes, address, newPhone, newEmail, customer, loa, loa_ref, raw: data };
|
|
6499
6939
|
}
|
|
@@ -6509,7 +6949,13 @@ function createOneAddressHandler(options) {
|
|
|
6509
6949
|
return Array.isArray(siblings) && siblings.includes(keyId);
|
|
6510
6950
|
}
|
|
6511
6951
|
return async function handler(req) {
|
|
6512
|
-
const rawBody = await req
|
|
6952
|
+
const rawBody = await readBodyCapped(req, maxBodyBytes);
|
|
6953
|
+
if (rawBody === null) {
|
|
6954
|
+
return new Response(JSON.stringify({ error: "Payload too large" }), {
|
|
6955
|
+
status: 413,
|
|
6956
|
+
headers: { "Content-Type": "application/json" }
|
|
6957
|
+
});
|
|
6958
|
+
}
|
|
6513
6959
|
const sig = req.headers.get("x-oneaddress-signature") ?? "";
|
|
6514
6960
|
const tsHeader = req.headers.get("x-oneaddress-timestamp") ?? "";
|
|
6515
6961
|
if (!isFreshTimestamp(tsHeader, timestampToleranceSecs)) {
|
|
@@ -6558,6 +7004,8 @@ function createOneAddressHandler(options) {
|
|
|
6558
7004
|
if (isCrossoverSiblingToSkip(body)) {
|
|
6559
7005
|
return declared(200, { ok: true, skipped: true, crossover: true });
|
|
6560
7006
|
}
|
|
7007
|
+
let claimed = false;
|
|
7008
|
+
let completed = false;
|
|
6561
7009
|
if (dispatchId) {
|
|
6562
7010
|
if (!idempotencyStore) {
|
|
6563
7011
|
const nodeEnv = typeof process !== "undefined" ? process.env?.NODE_ENV : void 0;
|
|
@@ -6578,6 +7026,17 @@ function createOneAddressHandler(options) {
|
|
|
6578
7026
|
if (claim === "duplicate") {
|
|
6579
7027
|
return declared(200, { ok: true, duplicate: true });
|
|
6580
7028
|
}
|
|
7029
|
+
if (claim === "in-progress") {
|
|
7030
|
+
return new Response(JSON.stringify({
|
|
7031
|
+
error: "dispatch_in_progress",
|
|
7032
|
+
detail: "Another delivery of this dispatch is being processed. Retry later.",
|
|
7033
|
+
accepted_update_types: acceptedUpdateTypes
|
|
7034
|
+
}), {
|
|
7035
|
+
status: 503,
|
|
7036
|
+
headers: { "Content-Type": "application/json", "Retry-After": String(IN_PROGRESS_RETRY_AFTER_SECS) }
|
|
7037
|
+
});
|
|
7038
|
+
}
|
|
7039
|
+
claimed = true;
|
|
6581
7040
|
} else {
|
|
6582
7041
|
const alreadySeen = await idempotencyStore.has(dispatchId);
|
|
6583
7042
|
if (alreadySeen) {
|
|
@@ -6673,16 +7132,27 @@ function createOneAddressHandler(options) {
|
|
|
6673
7132
|
expectedAlg
|
|
6674
7133
|
);
|
|
6675
7134
|
loa_ref = d5LoaRef(loa);
|
|
6676
|
-
|
|
7135
|
+
const loaKey = await loaVerificationKey();
|
|
7136
|
+
if (loaKey && !await verifyD5LOA(loa, loaKey)) {
|
|
6677
7137
|
throw new Error("D5 LOA signature verification failed");
|
|
6678
7138
|
}
|
|
6679
7139
|
assertLoaBoundToEnvelope(loa, rawAddress.update_uid);
|
|
7140
|
+
if (hasLoaV2(loa)) {
|
|
7141
|
+
const refusal = await checkLoaV2(loa, {
|
|
7142
|
+
partnerId: configuredPartnerId ?? confirm?.partnerId ?? partnerId,
|
|
7143
|
+
updateId: body.update_id,
|
|
7144
|
+
envelope: encrypted,
|
|
7145
|
+
envelopeVerifiedName: rawAddress.fullName,
|
|
7146
|
+
...loaKey ? { publicKeyPem: loaKey } : {}
|
|
7147
|
+
});
|
|
7148
|
+
if (refusal) throw new LoaV2RefusedError(refusal);
|
|
7149
|
+
}
|
|
6680
7150
|
}
|
|
6681
7151
|
const customer = {
|
|
6682
7152
|
email: "",
|
|
6683
|
-
name: rawAddress.fullName
|
|
6684
|
-
account_number: rawAddress.accountReference
|
|
6685
|
-
known_names:
|
|
7153
|
+
name: stringOr(rawAddress.fullName, ""),
|
|
7154
|
+
account_number: stringOr(rawAddress.accountReference, null),
|
|
7155
|
+
known_names: loa && hasLoaV2(loa) ? typedAliasesOf(loa) : stringsOf(rawAddress.knownNames)
|
|
6686
7156
|
};
|
|
6687
7157
|
event = {
|
|
6688
7158
|
event: "address.updated",
|
|
@@ -6694,7 +7164,8 @@ function createOneAddressHandler(options) {
|
|
|
6694
7164
|
customer,
|
|
6695
7165
|
// The legacy blob predates kinds and always carries an address.
|
|
6696
7166
|
update_types: ["address"],
|
|
6697
|
-
|
|
7167
|
+
// Six named fields, never the blob: see validateAddress.
|
|
7168
|
+
address: legacyAddressOf(rawAddress, body),
|
|
6698
7169
|
loa,
|
|
6699
7170
|
loa_ref,
|
|
6700
7171
|
id_verification: body.id_verification,
|
|
@@ -6702,6 +7173,7 @@ function createOneAddressHandler(options) {
|
|
|
6702
7173
|
};
|
|
6703
7174
|
}
|
|
6704
7175
|
const result = await onUpdate(event);
|
|
7176
|
+
completed = true;
|
|
6705
7177
|
if (dispatchId && idempotencyStore) {
|
|
6706
7178
|
const record = idempotencyStore.complete ? idempotencyStore.complete(dispatchId) : idempotencyStore.set(dispatchId);
|
|
6707
7179
|
await record.catch(
|
|
@@ -6718,6 +7190,7 @@ function createOneAddressHandler(options) {
|
|
|
6718
7190
|
status,
|
|
6719
7191
|
loaRef: event.loa_ref,
|
|
6720
7192
|
...confirm.oneAddressApi ? { appBaseUrl: confirm.oneAddressApi } : {},
|
|
7193
|
+
...confirm.allowedHosts ? { allowedHosts: confirm.allowedHosts } : {},
|
|
6721
7194
|
...confirm.fetchImpl ? { fetchImpl: confirm.fetchImpl } : {}
|
|
6722
7195
|
}).then(
|
|
6723
7196
|
(r) => {
|
|
@@ -6754,7 +7227,7 @@ function createOneAddressHandler(options) {
|
|
|
6754
7227
|
user_id: body.user_id ?? "",
|
|
6755
7228
|
customer: body.customer,
|
|
6756
7229
|
customer_match: body.customer_match,
|
|
6757
|
-
address:
|
|
7230
|
+
address: legacyAddressOf(rawAddress, body),
|
|
6758
7231
|
loa: body.loa,
|
|
6759
7232
|
id_verification: body.id_verification,
|
|
6760
7233
|
raw: rawAddress
|
|
@@ -6793,10 +7266,10 @@ function createOneAddressHandler(options) {
|
|
|
6793
7266
|
partnerId
|
|
6794
7267
|
);
|
|
6795
7268
|
customer = {
|
|
6796
|
-
email: raw.email
|
|
6797
|
-
name: raw.name
|
|
6798
|
-
account_number: raw.account_number
|
|
6799
|
-
known_names:
|
|
7269
|
+
email: stringOr(raw.email, ""),
|
|
7270
|
+
name: stringOr(raw.name, ""),
|
|
7271
|
+
account_number: stringOr(raw.account_number, null),
|
|
7272
|
+
known_names: stringsOf(raw.known_names)
|
|
6800
7273
|
};
|
|
6801
7274
|
} else {
|
|
6802
7275
|
customer = body.customer ?? {};
|
|
@@ -6883,6 +7356,13 @@ function createOneAddressHandler(options) {
|
|
|
6883
7356
|
status: 500,
|
|
6884
7357
|
headers: { "Content-Type": "application/json" }
|
|
6885
7358
|
});
|
|
7359
|
+
} finally {
|
|
7360
|
+
if (claimed && !completed && idempotencyStore?.release) {
|
|
7361
|
+
await idempotencyStore.release(dispatchId).catch(
|
|
7362
|
+
(err) => console.error("[OneAddress SDK] idempotency release failed:", err)
|
|
7363
|
+
// NOSONAR
|
|
7364
|
+
);
|
|
7365
|
+
}
|
|
6886
7366
|
}
|
|
6887
7367
|
};
|
|
6888
7368
|
}
|
|
@@ -6890,8 +7370,12 @@ function createOneAddressHandler(options) {
|
|
|
6890
7370
|
0 && (module.exports = {
|
|
6891
7371
|
CURRENT_VERSION,
|
|
6892
7372
|
DEFAULT_REPLAY_WINDOW_SECS,
|
|
7373
|
+
LoaV2RefusedError,
|
|
6893
7374
|
SUPPORTED_VERSIONS,
|
|
7375
|
+
acceptTypedAliases,
|
|
6894
7376
|
canonicalD5LoaForm,
|
|
7377
|
+
canonicalD5LoaFormV2,
|
|
7378
|
+
checkLoaV2,
|
|
6895
7379
|
compareAddresses,
|
|
6896
7380
|
computeBlindIndex,
|
|
6897
7381
|
createOneAddressHandler,
|
|
@@ -6901,15 +7385,24 @@ function createOneAddressHandler(options) {
|
|
|
6901
7385
|
decryptSession,
|
|
6902
7386
|
fetchLoaPublicKey,
|
|
6903
7387
|
findMatchingStoredName,
|
|
7388
|
+
hasLoaV2,
|
|
7389
|
+
isAcceptableAlias,
|
|
6904
7390
|
isEmailLike,
|
|
6905
7391
|
isFreshTimestamp,
|
|
7392
|
+
loaEnvelopeSha256,
|
|
7393
|
+
loaFirstName,
|
|
7394
|
+
loaNamesMatch,
|
|
7395
|
+
loaSurname,
|
|
6906
7396
|
namePoolMatches,
|
|
7397
|
+
normaliseLoaName,
|
|
6907
7398
|
normalizeForBlindIndex,
|
|
6908
7399
|
sendVerifyResult,
|
|
6909
7400
|
transformAddress,
|
|
6910
7401
|
transformSession,
|
|
7402
|
+
typedAliasesOf,
|
|
6911
7403
|
validateAddress,
|
|
6912
7404
|
verifyD5LOA,
|
|
7405
|
+
verifyD5LOAv2,
|
|
6913
7406
|
verifyLOA,
|
|
6914
7407
|
verifySignature,
|
|
6915
7408
|
verifyWithGrace
|