@oneaddress/partner-sdk 2.7.0 → 2.9.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 +172 -0
- package/README.md +203 -62
- package/dist/{chunk-OKAJO4T6.mjs → chunk-OKPEOGR5.mjs} +588 -51
- 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 +591 -42
- package/dist/edge.mjs +28 -2
- package/dist/index.d.mts +452 -53
- package/dist/index.d.ts +452 -53
- package/dist/index.js +691 -49
- package/dist/index.mjs +52 -2
- package/dist/{src-FPYBM6X6.mjs → src-P3LR7F4A.mjs} +1 -1
- package/package.json +2 -2
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
|
|
@@ -5755,6 +5848,19 @@ init_src();
|
|
|
5755
5848
|
var CURRENT_VERSION = "2026.1";
|
|
5756
5849
|
var SUPPORTED_VERSIONS = ["2026.1"];
|
|
5757
5850
|
|
|
5851
|
+
// ../protocol/src/notice-period.ts
|
|
5852
|
+
var ISO_DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
5853
|
+
function isIsoDate(value) {
|
|
5854
|
+
if (typeof value !== "string") return false;
|
|
5855
|
+
const m = ISO_DATE.exec(value);
|
|
5856
|
+
if (!m) return false;
|
|
5857
|
+
const d = new Date(Date.UTC(Number(m[1]), Number(m[2]) - 1, Number(m[3])));
|
|
5858
|
+
return toIso(d) === value;
|
|
5859
|
+
}
|
|
5860
|
+
function toIso(d) {
|
|
5861
|
+
return d.toISOString().slice(0, 10);
|
|
5862
|
+
}
|
|
5863
|
+
|
|
5758
5864
|
// ../protocol/src/d5-body.ts
|
|
5759
5865
|
var D5_BODY_ALWAYS = [
|
|
5760
5866
|
"event",
|
|
@@ -5764,7 +5870,6 @@ var D5_BODY_ALWAYS = [
|
|
|
5764
5870
|
"partner_id",
|
|
5765
5871
|
"session_envelope",
|
|
5766
5872
|
"session_key_share",
|
|
5767
|
-
"stripe_session_id",
|
|
5768
5873
|
"timestamp",
|
|
5769
5874
|
"update_id",
|
|
5770
5875
|
"user_id"
|
|
@@ -5785,7 +5890,18 @@ var D5_BODY_CONDITIONAL = {
|
|
|
5785
5890
|
*/
|
|
5786
5891
|
id: "key-crossover copy only",
|
|
5787
5892
|
/** The sibling marker naming the other key_ids this update was sealed to. */
|
|
5788
|
-
crossover_key_ids: "key-crossover copy only"
|
|
5893
|
+
crossover_key_ids: "key-crossover copy only",
|
|
5894
|
+
/**
|
|
5895
|
+
* The day the change takes effect, `YYYY-MM-DD` (31 Oct 2026). Set on every
|
|
5896
|
+
* dispatch made for a SCHEDULED MOVE, which is its move date. A scheduled
|
|
5897
|
+
* move sends each recipient early enough for its own notice period
|
|
5898
|
+
* (`resolveRecipientSendPlan` in `notice-period.ts`), so the update can
|
|
5899
|
+
* arrive days before the customer moves; a recipient that treated it as
|
|
5900
|
+
* immediate could start charging at the new address from the day it arrived.
|
|
5901
|
+
* Absent on an immediate update, which takes effect on receipt. Optional for
|
|
5902
|
+
* receivers: an SDK that does not know the field ignores it.
|
|
5903
|
+
*/
|
|
5904
|
+
effective_date: "scheduled move only"
|
|
5789
5905
|
};
|
|
5790
5906
|
var D5_BODY_DRILL_ONLY = ["conformance"];
|
|
5791
5907
|
var D5_BODY_ADDED_AT_SEND = ["dispatch_id"];
|
|
@@ -5799,6 +5915,108 @@ var D5_BODY_ALL_ALLOWED = [
|
|
|
5799
5915
|
// ../protocol/src/retention.ts
|
|
5800
5916
|
var DAY_MS = 24 * 60 * 60 * 1e3;
|
|
5801
5917
|
|
|
5918
|
+
// ../protocol/src/pull-signature.ts
|
|
5919
|
+
var PULL_SIGNATURE_VERSION_HEADER = "X-OneAddress-Signature-Version";
|
|
5920
|
+
function pullSigningStringV2(timestamp, method, pathAndQuery, body = "") {
|
|
5921
|
+
return `v2.${timestamp}.${method.toUpperCase()}.${pathAndQuery}.${body}`;
|
|
5922
|
+
}
|
|
5923
|
+
|
|
5924
|
+
// ../protocol/src/loa-v2.ts
|
|
5925
|
+
var LOA_V2_VERSION_TAG = "oneaddress-loa/2";
|
|
5926
|
+
var LOA_V2_LEGACY_ENVELOPE_TAG = "oneaddress-legacy-envelope/1";
|
|
5927
|
+
var LOA_V2_FIELD_ORDER = [
|
|
5928
|
+
"consumer_name",
|
|
5929
|
+
"authorisation_date",
|
|
5930
|
+
"scope",
|
|
5931
|
+
"update_uid",
|
|
5932
|
+
"partner_id",
|
|
5933
|
+
"envelope_sha256"
|
|
5934
|
+
];
|
|
5935
|
+
var LOA_MAX_TYPED_ALIASES = 3;
|
|
5936
|
+
var LoaV2FieldError = class extends Error {
|
|
5937
|
+
constructor(field, reason) {
|
|
5938
|
+
super(`LOA v2 field ${field} ${reason}`);
|
|
5939
|
+
this.field = field;
|
|
5940
|
+
this.name = "LoaV2FieldError";
|
|
5941
|
+
}
|
|
5942
|
+
};
|
|
5943
|
+
var CONTROL_RE = /[\u0000-\u001F\u007F]/;
|
|
5944
|
+
var LONE_SURROGATE_RE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;
|
|
5945
|
+
function utf8Length(s) {
|
|
5946
|
+
return new TextEncoder().encode(s).length;
|
|
5947
|
+
}
|
|
5948
|
+
function encodeField(name, value) {
|
|
5949
|
+
if (typeof value !== "string") throw new LoaV2FieldError(name, "is not a string");
|
|
5950
|
+
if (CONTROL_RE.test(value)) throw new LoaV2FieldError(name, "contains a control character");
|
|
5951
|
+
if (LONE_SURROGATE_RE.test(value)) throw new LoaV2FieldError(name, "is not well-formed Unicode");
|
|
5952
|
+
return `${utf8Length(value)}:${value}
|
|
5953
|
+
`;
|
|
5954
|
+
}
|
|
5955
|
+
function canonicalLoaV2(fields) {
|
|
5956
|
+
let out = encodeField("version", LOA_V2_VERSION_TAG);
|
|
5957
|
+
for (const f of LOA_V2_FIELD_ORDER) out += encodeField(f, fields[f]);
|
|
5958
|
+
const aliases = fields.consumer_typed_aliases;
|
|
5959
|
+
if (!Array.isArray(aliases)) throw new LoaV2FieldError("consumer_typed_aliases", "is not a list");
|
|
5960
|
+
if (aliases.length > LOA_MAX_TYPED_ALIASES) {
|
|
5961
|
+
throw new LoaV2FieldError("consumer_typed_aliases", `has more than ${LOA_MAX_TYPED_ALIASES} entries`);
|
|
5962
|
+
}
|
|
5963
|
+
out += encodeField("consumer_typed_aliases", String(aliases.length));
|
|
5964
|
+
for (const a of aliases) out += encodeField("consumer_typed_aliases", a);
|
|
5965
|
+
return out;
|
|
5966
|
+
}
|
|
5967
|
+
function loaV2EnvelopeDigestInput(envelope) {
|
|
5968
|
+
if (typeof envelope === "string") return envelope;
|
|
5969
|
+
if (!envelope || typeof envelope !== "object") {
|
|
5970
|
+
throw new LoaV2FieldError("envelope", "is neither a session_envelope string nor an address_encrypted object");
|
|
5971
|
+
}
|
|
5972
|
+
return encodeField("tag", LOA_V2_LEGACY_ENVELOPE_TAG) + encodeField("ephemeralPublicKey", envelope.ephemeralPublicKey) + encodeField("iv", envelope.iv) + encodeField("ciphertext", envelope.ciphertext) + encodeField("hkdfSalt", envelope.hkdfSalt ?? "");
|
|
5973
|
+
}
|
|
5974
|
+
var ASCII_WS_RE = /[ \t\n\v\f\r]+/;
|
|
5975
|
+
var MARK_RE = /\p{M}/gu;
|
|
5976
|
+
function normaliseLoaName(name) {
|
|
5977
|
+
return name.normalize("NFKD").replace(MARK_RE, "").toLowerCase().replace(/\u03C2/g, "\u03C3").split(ASCII_WS_RE).filter((t) => t.length > 0).join(" ");
|
|
5978
|
+
}
|
|
5979
|
+
function loaSurname(name) {
|
|
5980
|
+
const tokens = normaliseLoaName(name).split(" ").filter((t) => t.length > 0);
|
|
5981
|
+
return tokens.length > 0 ? tokens[tokens.length - 1] : "";
|
|
5982
|
+
}
|
|
5983
|
+
function loaFirstName(name) {
|
|
5984
|
+
const tokens = normaliseLoaName(name).split(" ").filter((t) => t.length > 0);
|
|
5985
|
+
return tokens.length > 0 ? tokens[0] : "";
|
|
5986
|
+
}
|
|
5987
|
+
function loaNamesMatch(a, b) {
|
|
5988
|
+
const na = normaliseLoaName(a);
|
|
5989
|
+
return na.length > 0 && na === normaliseLoaName(b);
|
|
5990
|
+
}
|
|
5991
|
+
var LOA_MIN_SHORT_FORM_LETTERS = 3;
|
|
5992
|
+
function codePoints(s) {
|
|
5993
|
+
return Array.from(s).length;
|
|
5994
|
+
}
|
|
5995
|
+
function isAcceptableAlias(verifiedName, alias) {
|
|
5996
|
+
const vFirst = loaFirstName(verifiedName);
|
|
5997
|
+
const aFirst = loaFirstName(alias);
|
|
5998
|
+
if (!vFirst || !aFirst) return false;
|
|
5999
|
+
if (aFirst === vFirst) return true;
|
|
6000
|
+
const [shorter, longer] = codePoints(aFirst) <= codePoints(vFirst) ? [aFirst, vFirst] : [vFirst, aFirst];
|
|
6001
|
+
return codePoints(shorter) >= LOA_MIN_SHORT_FORM_LETTERS && longer.startsWith(shorter);
|
|
6002
|
+
}
|
|
6003
|
+
function acceptTypedAliases(verifiedName, aliases) {
|
|
6004
|
+
const out = [];
|
|
6005
|
+
if (!Array.isArray(aliases)) return out;
|
|
6006
|
+
const seen = /* @__PURE__ */ new Set([normaliseLoaName(verifiedName)]);
|
|
6007
|
+
for (const a of aliases) {
|
|
6008
|
+
if (out.length >= LOA_MAX_TYPED_ALIASES) break;
|
|
6009
|
+
if (typeof a !== "string") continue;
|
|
6010
|
+
if (CONTROL_RE.test(a) || LONE_SURROGATE_RE.test(a)) continue;
|
|
6011
|
+
const n = normaliseLoaName(a);
|
|
6012
|
+
if (!n || seen.has(n)) continue;
|
|
6013
|
+
if (!isAcceptableAlias(verifiedName, a)) continue;
|
|
6014
|
+
seen.add(n);
|
|
6015
|
+
out.push(a);
|
|
6016
|
+
}
|
|
6017
|
+
return out;
|
|
6018
|
+
}
|
|
6019
|
+
|
|
5802
6020
|
// src/app-hosts.ts
|
|
5803
6021
|
function allowedAppHosts() {
|
|
5804
6022
|
const hosts = ["oneaddress.io", "app.oneaddress.io"];
|
|
@@ -5807,7 +6025,7 @@ function allowedAppHosts() {
|
|
|
5807
6025
|
}
|
|
5808
6026
|
return new Set(hosts);
|
|
5809
6027
|
}
|
|
5810
|
-
function resolveAppOrigin(baseUrl, label) {
|
|
6028
|
+
function resolveAppOrigin(baseUrl, label, extraHosts) {
|
|
5811
6029
|
let parsed;
|
|
5812
6030
|
try {
|
|
5813
6031
|
parsed = new URL(baseUrl);
|
|
@@ -5815,6 +6033,9 @@ function resolveAppOrigin(baseUrl, label) {
|
|
|
5815
6033
|
throw new Error(`[OneAddress SDK] ${label}: appBaseUrl is not a valid URL`);
|
|
5816
6034
|
}
|
|
5817
6035
|
const allowed = allowedAppHosts();
|
|
6036
|
+
for (const h of extraHosts ?? []) {
|
|
6037
|
+
if (typeof h === "string" && h.trim() !== "") allowed.add(h.trim().toLowerCase());
|
|
6038
|
+
}
|
|
5818
6039
|
if (!allowed.has(parsed.hostname)) {
|
|
5819
6040
|
throw new Error(
|
|
5820
6041
|
`[OneAddress SDK] ${label}: appBaseUrl host must be one of: ${[...allowed].join(", ")}`
|
|
@@ -5850,26 +6071,38 @@ function surnameVariants(token) {
|
|
|
5850
6071
|
if (!token.includes("-")) return [token];
|
|
5851
6072
|
return [token, ...token.split("-").filter(Boolean)];
|
|
5852
6073
|
}
|
|
6074
|
+
var MAX_ALIASES = 10;
|
|
6075
|
+
var MAX_TOKENS_PER_NAME = 8;
|
|
6076
|
+
var MAX_POOL_TOKENS = 24;
|
|
5853
6077
|
function namePoolMatches(providedNames, storedName) {
|
|
5854
6078
|
if (isEmailLike2(storedName)) return false;
|
|
5855
|
-
const provided = providedNames.filter((n) =>
|
|
6079
|
+
const provided = providedNames.filter((n) => typeof n === "string" && n !== "" && !isEmailLike2(n));
|
|
5856
6080
|
const primary = tokenize(provided[0] ?? "");
|
|
5857
|
-
if (primary.length === 0) return false;
|
|
6081
|
+
if (primary.length === 0 || primary.length > MAX_TOKENS_PER_NAME) return false;
|
|
6082
|
+
const aliases = provided.slice(1, 1 + MAX_ALIASES).map(tokenize).filter((t) => t.length > 0 && t.length <= MAX_TOKENS_PER_NAME);
|
|
6083
|
+
const distinct = new Set(primary);
|
|
6084
|
+
for (const t of aliases) for (const tok of t) distinct.add(tok);
|
|
6085
|
+
if (distinct.size > MAX_POOL_TOKENS) return false;
|
|
5858
6086
|
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
|
|
6087
|
+
for (const t of aliases) {
|
|
6088
|
+
const last = t[t.length - 1];
|
|
6089
|
+
if (t.length >= 2 && last.length >= 2) for (const v of surnameVariants(last)) surnames.add(v);
|
|
6090
|
+
}
|
|
6091
|
+
const givenSet = /* @__PURE__ */ new Set();
|
|
6092
|
+
for (const tok of primary) if (!surnames.has(tok)) givenSet.add(tok);
|
|
6093
|
+
for (const t of aliases) for (const tok of t) if (tok.length >= 2 && !surnames.has(tok)) givenSet.add(tok);
|
|
6094
|
+
const given = [...givenSet];
|
|
6095
|
+
const fullGiven = given.filter((g) => g.length >= 2);
|
|
5866
6096
|
const stored = tokenize(storedName);
|
|
5867
|
-
if (stored.length
|
|
6097
|
+
if (stored.length < 2) return false;
|
|
5868
6098
|
const storedSurname = stored[stored.length - 1];
|
|
5869
6099
|
const storedGiven = stored.slice(0, -1);
|
|
5870
6100
|
if (!surnameVariants(storedSurname).some((v) => surnames.has(v))) return false;
|
|
5871
6101
|
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
|
-
|
|
6102
|
+
if (!storedGiven.every(covered)) return false;
|
|
6103
|
+
return storedGiven.some(
|
|
6104
|
+
(tok) => fullGiven.includes(tok) || tok.length === 1 && fullGiven.some((g) => g[0] === tok)
|
|
6105
|
+
);
|
|
5873
6106
|
}
|
|
5874
6107
|
function findMatchingStoredName(providedNames, storedCandidates) {
|
|
5875
6108
|
return storedCandidates.find((candidate) => namePoolMatches(providedNames, candidate));
|
|
@@ -6035,6 +6268,7 @@ async function transformSession(share, envelopeB64, privateKeyPem, partnerId, re
|
|
|
6035
6268
|
);
|
|
6036
6269
|
}
|
|
6037
6270
|
var OA_APP_BASE_URL = "https://oneaddress.io";
|
|
6271
|
+
var CONFIRM_PATH = "/api/confirm";
|
|
6038
6272
|
async function confirmUpdate(opts2) {
|
|
6039
6273
|
const {
|
|
6040
6274
|
partnerId,
|
|
@@ -6049,6 +6283,13 @@ async function confirmUpdate(opts2) {
|
|
|
6049
6283
|
} = opts2;
|
|
6050
6284
|
if (!partnerId) return { ok: false, status: 0, error: "partnerId is required" };
|
|
6051
6285
|
if (!secret) return { ok: false, status: 0, error: "secret is required" };
|
|
6286
|
+
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(partnerId)) {
|
|
6287
|
+
return {
|
|
6288
|
+
ok: false,
|
|
6289
|
+
status: 0,
|
|
6290
|
+
error: `partnerId must be your partner UUID from the portal, received ${JSON.stringify(partnerId)}`
|
|
6291
|
+
};
|
|
6292
|
+
}
|
|
6052
6293
|
const id = typeof dispatchId === "string" ? Number(dispatchId) : dispatchId;
|
|
6053
6294
|
if (!Number.isInteger(id) || id <= 0) {
|
|
6054
6295
|
return {
|
|
@@ -6066,18 +6307,22 @@ async function confirmUpdate(opts2) {
|
|
|
6066
6307
|
...memberName !== void 0 ? { member_name: memberName } : {}
|
|
6067
6308
|
});
|
|
6068
6309
|
const timestamp = String(Math.floor(Date.now() / 1e3));
|
|
6069
|
-
const signature = import_crypto2.default.createHmac("sha256", secret).update(
|
|
6070
|
-
let
|
|
6071
|
-
|
|
6310
|
+
const signature = import_crypto2.default.createHmac("sha256", secret).update(pullSigningStringV2(timestamp, "POST", CONFIRM_PATH, body)).digest("hex");
|
|
6311
|
+
let origin;
|
|
6312
|
+
try {
|
|
6313
|
+
origin = resolveAppOrigin(appBaseUrl, "confirmUpdate", opts2.allowedHosts);
|
|
6314
|
+
} catch (err) {
|
|
6315
|
+
return { ok: false, status: 0, error: err instanceof Error ? err.message : String(err) };
|
|
6316
|
+
}
|
|
6072
6317
|
let res;
|
|
6073
6318
|
try {
|
|
6074
|
-
res = await fetchImpl(`${
|
|
6319
|
+
res = await fetchImpl(`${origin}${CONFIRM_PATH}`, {
|
|
6075
6320
|
method: "POST",
|
|
6076
6321
|
headers: {
|
|
6077
6322
|
"Content-Type": "application/json",
|
|
6078
|
-
"Authorization": `Bearer ${secret}`,
|
|
6079
6323
|
"X-OneAddress-Timestamp": timestamp,
|
|
6080
|
-
"X-OneAddress-Signature": signature
|
|
6324
|
+
"X-OneAddress-Signature": signature,
|
|
6325
|
+
[PULL_SIGNATURE_VERSION_HEADER]: "2"
|
|
6081
6326
|
},
|
|
6082
6327
|
// The SAME string that was signed. Not an object, and not re-stringified.
|
|
6083
6328
|
body
|
|
@@ -6103,6 +6348,44 @@ async function fetchLoaPublicKey(appBaseUrl = OA_APP_BASE_URL) {
|
|
|
6103
6348
|
}
|
|
6104
6349
|
return res.text();
|
|
6105
6350
|
}
|
|
6351
|
+
var LOA_PUBLIC_KEY_CACHE_MS = 24 * 60 * 60 * 1e3;
|
|
6352
|
+
var loaKeyCache = /* @__PURE__ */ new Map();
|
|
6353
|
+
var loaKeyInFlight = /* @__PURE__ */ new Map();
|
|
6354
|
+
var LoaPublicKeyUnavailableError = class extends Error {
|
|
6355
|
+
constructor(from, cause) {
|
|
6356
|
+
super(
|
|
6357
|
+
`[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.`
|
|
6358
|
+
);
|
|
6359
|
+
this.from = from;
|
|
6360
|
+
this.name = "LoaPublicKeyUnavailableError";
|
|
6361
|
+
}
|
|
6362
|
+
};
|
|
6363
|
+
async function cachedLoaPublicKey(appBaseUrl = OA_APP_BASE_URL, now = Date.now()) {
|
|
6364
|
+
const origin = resolveAppOrigin(appBaseUrl, "cachedLoaPublicKey");
|
|
6365
|
+
const held = loaKeyCache.get(origin);
|
|
6366
|
+
if (held && now - held.at < LOA_PUBLIC_KEY_CACHE_MS) return held.pem;
|
|
6367
|
+
let pending = loaKeyInFlight.get(origin);
|
|
6368
|
+
if (!pending) {
|
|
6369
|
+
pending = (async () => {
|
|
6370
|
+
const pem = (await fetchLoaPublicKey(origin)).trim();
|
|
6371
|
+
if (!pem.includes("-----BEGIN PUBLIC KEY-----")) {
|
|
6372
|
+
throw new Error("the response is not a PEM public key");
|
|
6373
|
+
}
|
|
6374
|
+
loaKeyCache.set(origin, { pem, at: Date.now() });
|
|
6375
|
+
return pem;
|
|
6376
|
+
})().finally(() => loaKeyInFlight.delete(origin));
|
|
6377
|
+
loaKeyInFlight.set(origin, pending);
|
|
6378
|
+
}
|
|
6379
|
+
try {
|
|
6380
|
+
return await pending;
|
|
6381
|
+
} catch (err) {
|
|
6382
|
+
if (held) return held.pem;
|
|
6383
|
+
throw new LoaPublicKeyUnavailableError(
|
|
6384
|
+
`${origin}/.well-known/oneaddress-loa-key.pem`,
|
|
6385
|
+
err instanceof Error ? err.message : String(err)
|
|
6386
|
+
);
|
|
6387
|
+
}
|
|
6388
|
+
}
|
|
6106
6389
|
async function verifyLOA(loa, publicKeyPem) {
|
|
6107
6390
|
if (loa.algorithm !== "ECDSA-P256") {
|
|
6108
6391
|
console.warn(
|
|
@@ -6182,6 +6465,91 @@ async function decryptLoaEncrypted(loaEncrypted, privateKeyPem, partnerId, expec
|
|
|
6182
6465
|
);
|
|
6183
6466
|
return data;
|
|
6184
6467
|
}
|
|
6468
|
+
function hasLoaV2(loa) {
|
|
6469
|
+
return typeof loa.oneaddress_signature_v2 === "string";
|
|
6470
|
+
}
|
|
6471
|
+
function canonicalD5LoaFormV2(loa) {
|
|
6472
|
+
return canonicalLoaV2({
|
|
6473
|
+
consumer_name: loa.consumer_name,
|
|
6474
|
+
authorisation_date: loa.authorisation_date,
|
|
6475
|
+
scope: loa.scope,
|
|
6476
|
+
update_uid: loa.update_uid,
|
|
6477
|
+
partner_id: loa.partner_id,
|
|
6478
|
+
envelope_sha256: loa.envelope_sha256,
|
|
6479
|
+
consumer_typed_aliases: loa.consumer_typed_aliases
|
|
6480
|
+
});
|
|
6481
|
+
}
|
|
6482
|
+
function loaEnvelopeSha256(envelope) {
|
|
6483
|
+
return import_crypto2.default.createHash("sha256").update(loaV2EnvelopeDigestInput(envelope), "utf8").digest("hex");
|
|
6484
|
+
}
|
|
6485
|
+
async function verifyD5LOAv2(loa, publicKeyPem) {
|
|
6486
|
+
if (loa.signature_algorithm !== "ECDSA-P256" || !hasLoaV2(loa)) return false;
|
|
6487
|
+
let text;
|
|
6488
|
+
try {
|
|
6489
|
+
text = canonicalD5LoaFormV2(loa);
|
|
6490
|
+
} catch {
|
|
6491
|
+
return false;
|
|
6492
|
+
}
|
|
6493
|
+
try {
|
|
6494
|
+
const key = await import_crypto2.default.subtle.importKey(
|
|
6495
|
+
"spki",
|
|
6496
|
+
pemToBuffer(publicKeyPem),
|
|
6497
|
+
{ name: "ECDSA", namedCurve: "P-256" },
|
|
6498
|
+
false,
|
|
6499
|
+
["verify"]
|
|
6500
|
+
);
|
|
6501
|
+
return await import_crypto2.default.subtle.verify(
|
|
6502
|
+
{ name: "ECDSA", hash: "SHA-256" },
|
|
6503
|
+
key,
|
|
6504
|
+
Buffer.from(loa.oneaddress_signature_v2, "hex"),
|
|
6505
|
+
new TextEncoder().encode(text)
|
|
6506
|
+
);
|
|
6507
|
+
} catch {
|
|
6508
|
+
return false;
|
|
6509
|
+
}
|
|
6510
|
+
}
|
|
6511
|
+
function typedAliasesOf(loa) {
|
|
6512
|
+
if (!hasLoaV2(loa)) return [];
|
|
6513
|
+
return acceptTypedAliases(loa.consumer_name, loa.consumer_typed_aliases);
|
|
6514
|
+
}
|
|
6515
|
+
function bodyUpdateIdString(v) {
|
|
6516
|
+
if (typeof v === "string") return v;
|
|
6517
|
+
if (typeof v === "number" && Number.isSafeInteger(v)) return String(v);
|
|
6518
|
+
return null;
|
|
6519
|
+
}
|
|
6520
|
+
async function checkLoaV2(loa, ctx) {
|
|
6521
|
+
if (!hasLoaV2(loa) || typeof loa.partner_id !== "string" || typeof loa.envelope_sha256 !== "string") {
|
|
6522
|
+
return "loa_v2_malformed";
|
|
6523
|
+
}
|
|
6524
|
+
try {
|
|
6525
|
+
canonicalD5LoaFormV2(loa);
|
|
6526
|
+
} catch {
|
|
6527
|
+
return "loa_v2_malformed";
|
|
6528
|
+
}
|
|
6529
|
+
if (ctx.publicKeyPem !== void 0 && !await verifyD5LOAv2(loa, ctx.publicKeyPem)) {
|
|
6530
|
+
return "loa_v2_signature_invalid";
|
|
6531
|
+
}
|
|
6532
|
+
if (loa.partner_id !== ctx.partnerId) return "loa_v2_partner_mismatch";
|
|
6533
|
+
if (bodyUpdateIdString(ctx.updateId) !== loa.update_uid) return "loa_v2_update_mismatch";
|
|
6534
|
+
let digest;
|
|
6535
|
+
try {
|
|
6536
|
+
digest = loaEnvelopeSha256(ctx.envelope);
|
|
6537
|
+
} catch {
|
|
6538
|
+
return "loa_v2_envelope_mismatch";
|
|
6539
|
+
}
|
|
6540
|
+
if (digest !== loa.envelope_sha256) return "loa_v2_envelope_mismatch";
|
|
6541
|
+
if (typeof ctx.envelopeVerifiedName !== "string" || !loaNamesMatch(ctx.envelopeVerifiedName, loa.consumer_name)) {
|
|
6542
|
+
return "loa_v2_name_mismatch";
|
|
6543
|
+
}
|
|
6544
|
+
return null;
|
|
6545
|
+
}
|
|
6546
|
+
var LoaV2RefusedError = class extends Error {
|
|
6547
|
+
constructor(code) {
|
|
6548
|
+
super(`[OneAddress SDK] D5 LOA v2 refused (${code}); refusing rather than applying an update the consent record does not cover`);
|
|
6549
|
+
this.code = code;
|
|
6550
|
+
this.name = "LoaV2RefusedError";
|
|
6551
|
+
}
|
|
6552
|
+
};
|
|
6185
6553
|
var ADDRESS_REQUIRED_FIELDS = [
|
|
6186
6554
|
"street",
|
|
6187
6555
|
"suburb",
|
|
@@ -6189,19 +6557,60 @@ var ADDRESS_REQUIRED_FIELDS = [
|
|
|
6189
6557
|
"postcode",
|
|
6190
6558
|
"country"
|
|
6191
6559
|
];
|
|
6560
|
+
var MAX_ADDRESS_FIELD_CHARS = 512;
|
|
6192
6561
|
function validateAddress(raw) {
|
|
6193
|
-
if (typeof raw !== "object" || raw === null) {
|
|
6562
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
6194
6563
|
throw new Error("[OneAddress SDK] Decrypted address payload is not an object");
|
|
6195
6564
|
}
|
|
6196
6565
|
const obj = raw;
|
|
6197
6566
|
for (const field of ADDRESS_REQUIRED_FIELDS) {
|
|
6198
|
-
|
|
6567
|
+
const value = obj[field];
|
|
6568
|
+
if (typeof value !== "string" || value === "") {
|
|
6569
|
+
throw new Error(
|
|
6570
|
+
`[OneAddress SDK] Decrypted address is missing required field "${field}". This may indicate a decryption error or a schema change - update @oneaddress/partner-sdk.`
|
|
6571
|
+
);
|
|
6572
|
+
}
|
|
6573
|
+
if (value.length > MAX_ADDRESS_FIELD_CHARS) {
|
|
6199
6574
|
throw new Error(
|
|
6200
|
-
`[OneAddress SDK] Decrypted address
|
|
6575
|
+
`[OneAddress SDK] Decrypted address field "${field}" is ${value.length} characters, over the ${MAX_ADDRESS_FIELD_CHARS} this SDK accepts; refusing rather than truncating`
|
|
6201
6576
|
);
|
|
6202
6577
|
}
|
|
6203
6578
|
}
|
|
6204
|
-
|
|
6579
|
+
const rawUpdatedAt = obj.updated_at;
|
|
6580
|
+
let updatedAt;
|
|
6581
|
+
if (rawUpdatedAt === void 0 || rawUpdatedAt === null) updatedAt = "";
|
|
6582
|
+
else if (typeof rawUpdatedAt === "number" && Number.isFinite(rawUpdatedAt)) updatedAt = String(rawUpdatedAt);
|
|
6583
|
+
else if (typeof rawUpdatedAt === "string") updatedAt = rawUpdatedAt;
|
|
6584
|
+
else throw new Error('[OneAddress SDK] Decrypted address field "updated_at" is not a string');
|
|
6585
|
+
if (updatedAt.length > MAX_ADDRESS_FIELD_CHARS) {
|
|
6586
|
+
throw new Error(
|
|
6587
|
+
`[OneAddress SDK] Decrypted address field "updated_at" is over the ${MAX_ADDRESS_FIELD_CHARS} characters this SDK accepts`
|
|
6588
|
+
);
|
|
6589
|
+
}
|
|
6590
|
+
return {
|
|
6591
|
+
street: obj.street,
|
|
6592
|
+
suburb: obj.suburb,
|
|
6593
|
+
state: obj.state,
|
|
6594
|
+
postcode: obj.postcode,
|
|
6595
|
+
country: obj.country,
|
|
6596
|
+
updated_at: updatedAt
|
|
6597
|
+
};
|
|
6598
|
+
}
|
|
6599
|
+
function legacyAddressOf(blob, body) {
|
|
6600
|
+
return validateAddress({
|
|
6601
|
+
street: blob.street,
|
|
6602
|
+
suburb: blob.suburb,
|
|
6603
|
+
state: blob.state,
|
|
6604
|
+
postcode: blob.postcode,
|
|
6605
|
+
country: blob.country,
|
|
6606
|
+
updated_at: typeof blob.updated_at === "string" ? blob.updated_at : body.timestamp ?? ""
|
|
6607
|
+
});
|
|
6608
|
+
}
|
|
6609
|
+
function stringOr(value, fallback) {
|
|
6610
|
+
return typeof value === "string" ? value : fallback;
|
|
6611
|
+
}
|
|
6612
|
+
function stringsOf(value) {
|
|
6613
|
+
return Array.isArray(value) ? value.filter((v) => typeof v === "string") : [];
|
|
6205
6614
|
}
|
|
6206
6615
|
var STREET_SUFFIX_MAP = {
|
|
6207
6616
|
st: "street",
|
|
@@ -6353,6 +6762,41 @@ var warnedUnhandledEvents = /* @__PURE__ */ new Set();
|
|
|
6353
6762
|
var warnedConsentUnverified = false;
|
|
6354
6763
|
var warnedNoIdempotencyStore = false;
|
|
6355
6764
|
var MAX_TIMESTAMP_TOLERANCE_SECS = 86400;
|
|
6765
|
+
var DEFAULT_MAX_BODY_BYTES = 1048576;
|
|
6766
|
+
var IN_PROGRESS_RETRY_AFTER_SECS = 30;
|
|
6767
|
+
async function readBodyCapped(req, max) {
|
|
6768
|
+
const declaredLength = req.headers.get("content-length");
|
|
6769
|
+
if (declaredLength !== null && /^\s*\d+\s*$/.test(declaredLength) && Number(declaredLength) > max) {
|
|
6770
|
+
return null;
|
|
6771
|
+
}
|
|
6772
|
+
const stream = req.body;
|
|
6773
|
+
if (stream && typeof stream.getReader === "function") {
|
|
6774
|
+
const reader = stream.getReader();
|
|
6775
|
+
const chunks = [];
|
|
6776
|
+
let total = 0;
|
|
6777
|
+
for (; ; ) {
|
|
6778
|
+
const { done, value } = await reader.read();
|
|
6779
|
+
if (done) break;
|
|
6780
|
+
if (!value) continue;
|
|
6781
|
+
total += value.byteLength;
|
|
6782
|
+
if (total > max) {
|
|
6783
|
+
await reader.cancel().catch(() => void 0);
|
|
6784
|
+
return null;
|
|
6785
|
+
}
|
|
6786
|
+
chunks.push(value);
|
|
6787
|
+
}
|
|
6788
|
+
const joined = new Uint8Array(total);
|
|
6789
|
+
let offset = 0;
|
|
6790
|
+
for (const c of chunks) {
|
|
6791
|
+
joined.set(c, offset);
|
|
6792
|
+
offset += c.byteLength;
|
|
6793
|
+
}
|
|
6794
|
+
return new TextDecoder("utf-8").decode(joined);
|
|
6795
|
+
}
|
|
6796
|
+
const text = await req.text();
|
|
6797
|
+
if (text.length > max || new TextEncoder().encode(text).byteLength > max) return null;
|
|
6798
|
+
return text;
|
|
6799
|
+
}
|
|
6356
6800
|
var XWING_SEED_BYTES = 32;
|
|
6357
6801
|
function assertUsablePrivateKey(privateKeyPem) {
|
|
6358
6802
|
if (typeof privateKeyPem !== "string") {
|
|
@@ -6382,6 +6826,21 @@ function requirePemFor(purpose, key) {
|
|
|
6382
6826
|
`[OneAddress SDK] ${purpose} needs the raw private key; a PrivateKeyOperations delegate ("${key.name}") covers session envelopes only`
|
|
6383
6827
|
);
|
|
6384
6828
|
}
|
|
6829
|
+
var EffectiveDateMismatchError = class extends Error {
|
|
6830
|
+
constructor(sealed, body) {
|
|
6831
|
+
super(
|
|
6832
|
+
`[OneAddress SDK] effective_date in the body (${JSON.stringify(body ?? null)}) does not match the one sealed in the envelope (${JSON.stringify(sealed ?? null)}); refusing rather than applying a date the consumer did not seal`
|
|
6833
|
+
);
|
|
6834
|
+
this.sealed = sealed;
|
|
6835
|
+
this.body = body;
|
|
6836
|
+
this.name = "EffectiveDateMismatchError";
|
|
6837
|
+
}
|
|
6838
|
+
};
|
|
6839
|
+
function assertEffectiveDateBound(sealed, body) {
|
|
6840
|
+
if (sealed === void 0 && body === void 0) return;
|
|
6841
|
+
if (sealed !== void 0 && body !== void 0 && sealed === body) return;
|
|
6842
|
+
throw new EffectiveDateMismatchError(sealed, body);
|
|
6843
|
+
}
|
|
6385
6844
|
function assertLoaBoundToEnvelope(loa, envelopeUpdateUid) {
|
|
6386
6845
|
if (typeof loa.update_uid !== "string" || typeof envelopeUpdateUid !== "string") return;
|
|
6387
6846
|
if (loa.update_uid !== envelopeUpdateUid) {
|
|
@@ -6399,13 +6858,16 @@ function createOneAddressHandler(options) {
|
|
|
6399
6858
|
expectedAlg,
|
|
6400
6859
|
keyId,
|
|
6401
6860
|
loaPublicKeyPem,
|
|
6402
|
-
requireLoa =
|
|
6861
|
+
requireLoa = true,
|
|
6862
|
+
loaPublicKeyBaseUrl,
|
|
6403
6863
|
confirm,
|
|
6864
|
+
partnerId: configuredPartnerId,
|
|
6404
6865
|
onUpdate,
|
|
6405
6866
|
onVerify,
|
|
6406
6867
|
onAccountVerify,
|
|
6407
6868
|
onTest,
|
|
6408
6869
|
timestampToleranceSecs = 300,
|
|
6870
|
+
maxBodyBytes = DEFAULT_MAX_BODY_BYTES,
|
|
6409
6871
|
idempotencyStore,
|
|
6410
6872
|
acceptedUpdateTypes: acceptedUpdateTypesRaw,
|
|
6411
6873
|
allowedCallbackHosts
|
|
@@ -6419,6 +6881,9 @@ function createOneAddressHandler(options) {
|
|
|
6419
6881
|
`[OneAddress SDK] timestampToleranceSecs must be a positive number of seconds up to ${MAX_TIMESTAMP_TOLERANCE_SECS}, got ${String(timestampToleranceSecs)}`
|
|
6420
6882
|
);
|
|
6421
6883
|
}
|
|
6884
|
+
if (typeof maxBodyBytes !== "number" || !Number.isSafeInteger(maxBodyBytes) || maxBodyBytes <= 0) {
|
|
6885
|
+
throw new Error(`[OneAddress SDK] maxBodyBytes must be a positive whole number of bytes, got ${String(maxBodyBytes)}`);
|
|
6886
|
+
}
|
|
6422
6887
|
if (webhookSecretGraceUntil !== void 0) {
|
|
6423
6888
|
const until = typeof webhookSecretGraceUntil === "number" ? webhookSecretGraceUntil : Date.parse(webhookSecretGraceUntil);
|
|
6424
6889
|
if (Number.isNaN(until)) {
|
|
@@ -6428,6 +6893,15 @@ function createOneAddressHandler(options) {
|
|
|
6428
6893
|
if (confirm && (!confirm.partnerId || !confirm.confirmSecret)) {
|
|
6429
6894
|
throw new Error("[OneAddress SDK] confirm needs both partnerId and confirmSecret");
|
|
6430
6895
|
}
|
|
6896
|
+
if (typeof requireLoa !== "boolean") {
|
|
6897
|
+
throw new Error(`[OneAddress SDK] requireLoa must be true or false, got ${String(requireLoa)}`);
|
|
6898
|
+
}
|
|
6899
|
+
if (loaPublicKeyBaseUrl !== void 0) resolveAppOrigin(loaPublicKeyBaseUrl, "loaPublicKeyBaseUrl");
|
|
6900
|
+
async function loaVerificationKey() {
|
|
6901
|
+
if (loaPublicKeyPem) return loaPublicKeyPem;
|
|
6902
|
+
if (!requireLoa) return void 0;
|
|
6903
|
+
return cachedLoaPublicKey(loaPublicKeyBaseUrl ?? OA_APP_BASE_URL);
|
|
6904
|
+
}
|
|
6431
6905
|
function enforceLoaPresence(body) {
|
|
6432
6906
|
const present = !!body.loa_encrypted && typeof body.loa_encrypted === "object";
|
|
6433
6907
|
if (present) return;
|
|
@@ -6440,7 +6914,7 @@ function createOneAddressHandler(options) {
|
|
|
6440
6914
|
warnedConsentUnverified = true;
|
|
6441
6915
|
console.warn(
|
|
6442
6916
|
// 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.
|
|
6917
|
+
"[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
6918
|
);
|
|
6445
6919
|
}
|
|
6446
6920
|
}
|
|
@@ -6475,9 +6949,9 @@ function createOneAddressHandler(options) {
|
|
|
6475
6949
|
const newEmail = updateTypes.includes("email") ? requireContactValue("email", data.new_email) : void 0;
|
|
6476
6950
|
const customer = {
|
|
6477
6951
|
email: "",
|
|
6478
|
-
name: data.verified_name
|
|
6479
|
-
account_number: data.account_number
|
|
6480
|
-
known_names:
|
|
6952
|
+
name: stringOr(data.verified_name, ""),
|
|
6953
|
+
account_number: stringOr(data.account_number, null),
|
|
6954
|
+
known_names: stringsOf(data.known_names)
|
|
6481
6955
|
};
|
|
6482
6956
|
let loa;
|
|
6483
6957
|
let loa_ref;
|
|
@@ -6489,12 +6963,25 @@ function createOneAddressHandler(options) {
|
|
|
6489
6963
|
expectedAlg
|
|
6490
6964
|
);
|
|
6491
6965
|
loa_ref = d5LoaRef(loa);
|
|
6492
|
-
|
|
6493
|
-
|
|
6966
|
+
const loaKey = await loaVerificationKey();
|
|
6967
|
+
if (loaKey) {
|
|
6968
|
+
const valid = await verifyD5LOA(loa, loaKey);
|
|
6494
6969
|
if (!valid) throw new Error("D5 LOA signature verification failed");
|
|
6495
6970
|
}
|
|
6496
6971
|
assertLoaBoundToEnvelope(loa, data.update_uid);
|
|
6972
|
+
if (hasLoaV2(loa)) {
|
|
6973
|
+
const refusal = await checkLoaV2(loa, {
|
|
6974
|
+
partnerId: configuredPartnerId ?? confirm?.partnerId ?? partnerId,
|
|
6975
|
+
updateId: body.update_id,
|
|
6976
|
+
envelope: body.session_envelope,
|
|
6977
|
+
envelopeVerifiedName: data.verified_name,
|
|
6978
|
+
...loaKey ? { publicKeyPem: loaKey } : {}
|
|
6979
|
+
});
|
|
6980
|
+
if (refusal) throw new LoaV2RefusedError(refusal);
|
|
6981
|
+
customer.known_names = typedAliasesOf(loa);
|
|
6982
|
+
}
|
|
6497
6983
|
}
|
|
6984
|
+
assertEffectiveDateBound(data.effective_date, body.effective_date);
|
|
6498
6985
|
return { updateTypes, address, newPhone, newEmail, customer, loa, loa_ref, raw: data };
|
|
6499
6986
|
}
|
|
6500
6987
|
function isD5Body(body) {
|
|
@@ -6509,7 +6996,13 @@ function createOneAddressHandler(options) {
|
|
|
6509
6996
|
return Array.isArray(siblings) && siblings.includes(keyId);
|
|
6510
6997
|
}
|
|
6511
6998
|
return async function handler(req) {
|
|
6512
|
-
const rawBody = await req
|
|
6999
|
+
const rawBody = await readBodyCapped(req, maxBodyBytes);
|
|
7000
|
+
if (rawBody === null) {
|
|
7001
|
+
return new Response(JSON.stringify({ error: "Payload too large" }), {
|
|
7002
|
+
status: 413,
|
|
7003
|
+
headers: { "Content-Type": "application/json" }
|
|
7004
|
+
});
|
|
7005
|
+
}
|
|
6513
7006
|
const sig = req.headers.get("x-oneaddress-signature") ?? "";
|
|
6514
7007
|
const tsHeader = req.headers.get("x-oneaddress-timestamp") ?? "";
|
|
6515
7008
|
if (!isFreshTimestamp(tsHeader, timestampToleranceSecs)) {
|
|
@@ -6558,6 +7051,8 @@ function createOneAddressHandler(options) {
|
|
|
6558
7051
|
if (isCrossoverSiblingToSkip(body)) {
|
|
6559
7052
|
return declared(200, { ok: true, skipped: true, crossover: true });
|
|
6560
7053
|
}
|
|
7054
|
+
let claimed = false;
|
|
7055
|
+
let completed = false;
|
|
6561
7056
|
if (dispatchId) {
|
|
6562
7057
|
if (!idempotencyStore) {
|
|
6563
7058
|
const nodeEnv = typeof process !== "undefined" ? process.env?.NODE_ENV : void 0;
|
|
@@ -6578,6 +7073,17 @@ function createOneAddressHandler(options) {
|
|
|
6578
7073
|
if (claim === "duplicate") {
|
|
6579
7074
|
return declared(200, { ok: true, duplicate: true });
|
|
6580
7075
|
}
|
|
7076
|
+
if (claim === "in-progress") {
|
|
7077
|
+
return new Response(JSON.stringify({
|
|
7078
|
+
error: "dispatch_in_progress",
|
|
7079
|
+
detail: "Another delivery of this dispatch is being processed. Retry later.",
|
|
7080
|
+
accepted_update_types: acceptedUpdateTypes
|
|
7081
|
+
}), {
|
|
7082
|
+
status: 503,
|
|
7083
|
+
headers: { "Content-Type": "application/json", "Retry-After": String(IN_PROGRESS_RETRY_AFTER_SECS) }
|
|
7084
|
+
});
|
|
7085
|
+
}
|
|
7086
|
+
claimed = true;
|
|
6581
7087
|
} else {
|
|
6582
7088
|
const alreadySeen = await idempotencyStore.has(dispatchId);
|
|
6583
7089
|
if (alreadySeen) {
|
|
@@ -6591,6 +7097,12 @@ function createOneAddressHandler(options) {
|
|
|
6591
7097
|
let event;
|
|
6592
7098
|
enforceLoaPresence(body);
|
|
6593
7099
|
if (isD5Body(body)) {
|
|
7100
|
+
if (body.effective_date !== void 0 && !isIsoDate(body.effective_date)) {
|
|
7101
|
+
return declared(400, {
|
|
7102
|
+
error: "invalid_effective_date",
|
|
7103
|
+
detail: "effective_date must be a YYYY-MM-DD calendar date. Nothing was processed."
|
|
7104
|
+
});
|
|
7105
|
+
}
|
|
6594
7106
|
let d5;
|
|
6595
7107
|
try {
|
|
6596
7108
|
d5 = await buildD5Pieces(body, partnerId);
|
|
@@ -6642,6 +7154,7 @@ function createOneAddressHandler(options) {
|
|
|
6642
7154
|
loa: d5.loa,
|
|
6643
7155
|
loa_ref: d5.loa_ref,
|
|
6644
7156
|
id_verification: body.id_verification,
|
|
7157
|
+
...body.effective_date !== void 0 ? { effective_date: body.effective_date } : {},
|
|
6645
7158
|
raw: d5.raw
|
|
6646
7159
|
};
|
|
6647
7160
|
} else {
|
|
@@ -6673,16 +7186,27 @@ function createOneAddressHandler(options) {
|
|
|
6673
7186
|
expectedAlg
|
|
6674
7187
|
);
|
|
6675
7188
|
loa_ref = d5LoaRef(loa);
|
|
6676
|
-
|
|
7189
|
+
const loaKey = await loaVerificationKey();
|
|
7190
|
+
if (loaKey && !await verifyD5LOA(loa, loaKey)) {
|
|
6677
7191
|
throw new Error("D5 LOA signature verification failed");
|
|
6678
7192
|
}
|
|
6679
7193
|
assertLoaBoundToEnvelope(loa, rawAddress.update_uid);
|
|
7194
|
+
if (hasLoaV2(loa)) {
|
|
7195
|
+
const refusal = await checkLoaV2(loa, {
|
|
7196
|
+
partnerId: configuredPartnerId ?? confirm?.partnerId ?? partnerId,
|
|
7197
|
+
updateId: body.update_id,
|
|
7198
|
+
envelope: encrypted,
|
|
7199
|
+
envelopeVerifiedName: rawAddress.fullName,
|
|
7200
|
+
...loaKey ? { publicKeyPem: loaKey } : {}
|
|
7201
|
+
});
|
|
7202
|
+
if (refusal) throw new LoaV2RefusedError(refusal);
|
|
7203
|
+
}
|
|
6680
7204
|
}
|
|
6681
7205
|
const customer = {
|
|
6682
7206
|
email: "",
|
|
6683
|
-
name: rawAddress.fullName
|
|
6684
|
-
account_number: rawAddress.accountReference
|
|
6685
|
-
known_names:
|
|
7207
|
+
name: stringOr(rawAddress.fullName, ""),
|
|
7208
|
+
account_number: stringOr(rawAddress.accountReference, null),
|
|
7209
|
+
known_names: loa && hasLoaV2(loa) ? typedAliasesOf(loa) : stringsOf(rawAddress.knownNames)
|
|
6686
7210
|
};
|
|
6687
7211
|
event = {
|
|
6688
7212
|
event: "address.updated",
|
|
@@ -6694,7 +7218,8 @@ function createOneAddressHandler(options) {
|
|
|
6694
7218
|
customer,
|
|
6695
7219
|
// The legacy blob predates kinds and always carries an address.
|
|
6696
7220
|
update_types: ["address"],
|
|
6697
|
-
|
|
7221
|
+
// Six named fields, never the blob: see validateAddress.
|
|
7222
|
+
address: legacyAddressOf(rawAddress, body),
|
|
6698
7223
|
loa,
|
|
6699
7224
|
loa_ref,
|
|
6700
7225
|
id_verification: body.id_verification,
|
|
@@ -6702,6 +7227,7 @@ function createOneAddressHandler(options) {
|
|
|
6702
7227
|
};
|
|
6703
7228
|
}
|
|
6704
7229
|
const result = await onUpdate(event);
|
|
7230
|
+
completed = true;
|
|
6705
7231
|
if (dispatchId && idempotencyStore) {
|
|
6706
7232
|
const record = idempotencyStore.complete ? idempotencyStore.complete(dispatchId) : idempotencyStore.set(dispatchId);
|
|
6707
7233
|
await record.catch(
|
|
@@ -6711,13 +7237,16 @@ function createOneAddressHandler(options) {
|
|
|
6711
7237
|
}
|
|
6712
7238
|
if (confirm && dispatchId) {
|
|
6713
7239
|
const status = result && typeof result === "object" && result.status ? result.status : "confirmed";
|
|
7240
|
+
const note = result && typeof result === "object" && typeof result.note === "string" ? result.note : void 0;
|
|
6714
7241
|
void confirmUpdate({
|
|
6715
7242
|
partnerId: confirm.partnerId,
|
|
6716
7243
|
secret: confirm.confirmSecret,
|
|
6717
7244
|
dispatchId,
|
|
6718
7245
|
status,
|
|
7246
|
+
...note !== void 0 ? { note } : {},
|
|
6719
7247
|
loaRef: event.loa_ref,
|
|
6720
7248
|
...confirm.oneAddressApi ? { appBaseUrl: confirm.oneAddressApi } : {},
|
|
7249
|
+
...confirm.allowedHosts ? { allowedHosts: confirm.allowedHosts } : {},
|
|
6721
7250
|
...confirm.fetchImpl ? { fetchImpl: confirm.fetchImpl } : {}
|
|
6722
7251
|
}).then(
|
|
6723
7252
|
(r) => {
|
|
@@ -6754,7 +7283,7 @@ function createOneAddressHandler(options) {
|
|
|
6754
7283
|
user_id: body.user_id ?? "",
|
|
6755
7284
|
customer: body.customer,
|
|
6756
7285
|
customer_match: body.customer_match,
|
|
6757
|
-
address:
|
|
7286
|
+
address: legacyAddressOf(rawAddress, body),
|
|
6758
7287
|
loa: body.loa,
|
|
6759
7288
|
id_verification: body.id_verification,
|
|
6760
7289
|
raw: rawAddress
|
|
@@ -6793,10 +7322,10 @@ function createOneAddressHandler(options) {
|
|
|
6793
7322
|
partnerId
|
|
6794
7323
|
);
|
|
6795
7324
|
customer = {
|
|
6796
|
-
email: raw.email
|
|
6797
|
-
name: raw.name
|
|
6798
|
-
account_number: raw.account_number
|
|
6799
|
-
known_names:
|
|
7325
|
+
email: stringOr(raw.email, ""),
|
|
7326
|
+
name: stringOr(raw.name, ""),
|
|
7327
|
+
account_number: stringOr(raw.account_number, null),
|
|
7328
|
+
known_names: stringsOf(raw.known_names)
|
|
6800
7329
|
};
|
|
6801
7330
|
} else {
|
|
6802
7331
|
customer = body.customer ?? {};
|
|
@@ -6883,6 +7412,13 @@ function createOneAddressHandler(options) {
|
|
|
6883
7412
|
status: 500,
|
|
6884
7413
|
headers: { "Content-Type": "application/json" }
|
|
6885
7414
|
});
|
|
7415
|
+
} finally {
|
|
7416
|
+
if (claimed && !completed && idempotencyStore?.release) {
|
|
7417
|
+
await idempotencyStore.release(dispatchId).catch(
|
|
7418
|
+
(err) => console.error("[OneAddress SDK] idempotency release failed:", err)
|
|
7419
|
+
// NOSONAR
|
|
7420
|
+
);
|
|
7421
|
+
}
|
|
6886
7422
|
}
|
|
6887
7423
|
};
|
|
6888
7424
|
}
|
|
@@ -6890,8 +7426,12 @@ function createOneAddressHandler(options) {
|
|
|
6890
7426
|
0 && (module.exports = {
|
|
6891
7427
|
CURRENT_VERSION,
|
|
6892
7428
|
DEFAULT_REPLAY_WINDOW_SECS,
|
|
7429
|
+
LoaV2RefusedError,
|
|
6893
7430
|
SUPPORTED_VERSIONS,
|
|
7431
|
+
acceptTypedAliases,
|
|
6894
7432
|
canonicalD5LoaForm,
|
|
7433
|
+
canonicalD5LoaFormV2,
|
|
7434
|
+
checkLoaV2,
|
|
6895
7435
|
compareAddresses,
|
|
6896
7436
|
computeBlindIndex,
|
|
6897
7437
|
createOneAddressHandler,
|
|
@@ -6901,15 +7441,24 @@ function createOneAddressHandler(options) {
|
|
|
6901
7441
|
decryptSession,
|
|
6902
7442
|
fetchLoaPublicKey,
|
|
6903
7443
|
findMatchingStoredName,
|
|
7444
|
+
hasLoaV2,
|
|
7445
|
+
isAcceptableAlias,
|
|
6904
7446
|
isEmailLike,
|
|
6905
7447
|
isFreshTimestamp,
|
|
7448
|
+
loaEnvelopeSha256,
|
|
7449
|
+
loaFirstName,
|
|
7450
|
+
loaNamesMatch,
|
|
7451
|
+
loaSurname,
|
|
6906
7452
|
namePoolMatches,
|
|
7453
|
+
normaliseLoaName,
|
|
6907
7454
|
normalizeForBlindIndex,
|
|
6908
7455
|
sendVerifyResult,
|
|
6909
7456
|
transformAddress,
|
|
6910
7457
|
transformSession,
|
|
7458
|
+
typedAliasesOf,
|
|
6911
7459
|
validateAddress,
|
|
6912
7460
|
verifyD5LOA,
|
|
7461
|
+
verifyD5LOAv2,
|
|
6913
7462
|
verifyLOA,
|
|
6914
7463
|
verifySignature,
|
|
6915
7464
|
verifyWithGrace
|