@agent-cards/sdk 0.20.0 → 0.22.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.
Files changed (111) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/PREFLIGHT.md +34 -0
  3. package/README.md +1217 -15
  4. package/dist/aci.d.ts +173 -0
  5. package/dist/aci.generated.d.ts +87 -0
  6. package/dist/aci.generated.js +306 -0
  7. package/dist/aci.js +371 -0
  8. package/dist/adyen-merchant-hosted.generated.d.ts +3 -3
  9. package/dist/adyen-merchant-hosted.generated.js +283 -49
  10. package/dist/agentcard.d.ts +9 -2
  11. package/dist/agentcard.js +4 -2
  12. package/dist/amadeus-checkout.generated.d.ts +57 -0
  13. package/dist/amadeus-checkout.generated.js +549 -0
  14. package/dist/amadeus.d.ts +41 -0
  15. package/dist/amadeus.js +81 -0
  16. package/dist/builtin-registry.generated.js +1 -1
  17. package/dist/card-endpoint.d.ts +177 -0
  18. package/dist/card-endpoint.js +286 -0
  19. package/dist/card-fields.generated.d.ts +5 -3
  20. package/dist/card-fields.generated.js +284 -7
  21. package/dist/cdp.d.ts +6 -1
  22. package/dist/cdp.js +983 -147
  23. package/dist/client.d.ts +493 -13
  24. package/dist/client.js +1100 -82
  25. package/dist/creditguard.generated.d.ts +79 -0
  26. package/dist/creditguard.generated.js +662 -0
  27. package/dist/cse-body.js +11 -1
  28. package/dist/cybersource-flex.d.ts +183 -0
  29. package/dist/cybersource-flex.generated.d.ts +92 -0
  30. package/dist/cybersource-flex.generated.js +689 -0
  31. package/dist/cybersource-flex.js +275 -0
  32. package/dist/datatrans.d.ts +96 -0
  33. package/dist/datatrans.generated.d.ts +64 -0
  34. package/dist/datatrans.generated.js +426 -0
  35. package/dist/datatrans.js +178 -0
  36. package/dist/elavon-converge.d.ts +37 -0
  37. package/dist/elavon-converge.generated.d.ts +49 -0
  38. package/dist/elavon-converge.generated.js +439 -0
  39. package/dist/elavon-converge.js +84 -0
  40. package/dist/eprotect.d.ts +152 -0
  41. package/dist/eprotect.generated.d.ts +77 -0
  42. package/dist/eprotect.generated.js +498 -0
  43. package/dist/eprotect.js +222 -0
  44. package/dist/gmo.d.ts +63 -0
  45. package/dist/gmo.generated.d.ts +60 -0
  46. package/dist/gmo.generated.js +586 -0
  47. package/dist/gmo.js +119 -0
  48. package/dist/hosted-form.d.ts +3 -2
  49. package/dist/hosted-form.js +3 -2
  50. package/dist/index.d.ts +19 -3
  51. package/dist/index.js +6 -1
  52. package/dist/juspay-gate.d.ts +82 -0
  53. package/dist/juspay-gate.js +126 -0
  54. package/dist/juspay.generated.d.ts +89 -0
  55. package/dist/juspay.generated.js +705 -0
  56. package/dist/lifecycle.d.ts +62 -6
  57. package/dist/lifecycle.js +123 -8
  58. package/dist/merchant-card-endpoints.generated.d.ts +63 -0
  59. package/dist/merchant-card-endpoints.generated.js +1103 -0
  60. package/dist/merchant-hosted.d.ts +4 -1
  61. package/dist/merchant-hosted.js +5 -2
  62. package/dist/merchant-session-probe.d.ts +48 -0
  63. package/dist/merchant-session-probe.js +53 -0
  64. package/dist/merchant-session.generated.d.ts +69 -0
  65. package/dist/merchant-session.generated.js +919 -0
  66. package/dist/payrails.d.ts +133 -0
  67. package/dist/payrails.generated.d.ts +73 -0
  68. package/dist/payrails.generated.js +596 -0
  69. package/dist/payrails.js +305 -0
  70. package/dist/pelecard.d.ts +32 -0
  71. package/dist/pelecard.generated.d.ts +32 -0
  72. package/dist/pelecard.generated.js +283 -0
  73. package/dist/pelecard.js +42 -0
  74. package/dist/pre-claim.d.ts +84 -3
  75. package/dist/pre-claim.js +987 -9
  76. package/dist/preflight-catalog.json +2310 -263
  77. package/dist/preflight-schemas.json +187 -6
  78. package/dist/preflight.generated.d.ts +1 -1
  79. package/dist/preflight.generated.js +247 -4
  80. package/dist/preparation.d.ts +5 -2
  81. package/dist/preparation.js +36 -10
  82. package/dist/prepared-processor.d.ts +86 -5
  83. package/dist/prepared-processor.js +157 -6
  84. package/dist/primer.d.ts +53 -0
  85. package/dist/primer.generated.d.ts +38 -0
  86. package/dist/primer.generated.js +624 -0
  87. package/dist/primer.js +82 -0
  88. package/dist/registry.d.ts +114 -12
  89. package/dist/registry.js +85 -11
  90. package/dist/shiji-sts.d.ts +144 -0
  91. package/dist/shiji-sts.generated.d.ts +72 -0
  92. package/dist/shiji-sts.generated.js +913 -0
  93. package/dist/shiji-sts.js +222 -0
  94. package/dist/stripe-checkout.generated.d.ts +1 -1
  95. package/dist/stripe-checkout.generated.js +735 -10
  96. package/dist/stripe-setup.d.ts +16 -0
  97. package/dist/stripe-setup.js +61 -0
  98. package/dist/substitutions.generated.js +187 -29
  99. package/dist/verifone.d.ts +68 -0
  100. package/dist/verifone.generated.d.ts +51 -0
  101. package/dist/verifone.generated.js +1401 -0
  102. package/dist/verifone.js +119 -0
  103. package/dist/voice-types.d.ts +27 -0
  104. package/dist/voice.d.ts +6 -1
  105. package/dist/voice.js +6 -1
  106. package/dist/wspay.d.ts +41 -0
  107. package/dist/wspay.generated.d.ts +41 -0
  108. package/dist/wspay.generated.js +370 -0
  109. package/dist/wspay.js +65 -0
  110. package/examples/preflight/kernel-native/inventory.json +1 -1
  111. package/package.json +3 -3
@@ -0,0 +1,586 @@
1
+ // @ts-nocheck
2
+ // Generated from @agent-cards/payment-core. Do not edit.
3
+ // artifact-sha256: 8149714daf5515a2fd3ec90d5aa0c7eb58a66d5ce79c3e3f0ba81c29d2946dc3
4
+ // src/sha256.js
5
+ var K = /* @__PURE__ */ new Uint32Array([
6
+ 1116352408,
7
+ 1899447441,
8
+ 3049323471,
9
+ 3921009573,
10
+ 961987163,
11
+ 1508970993,
12
+ 2453635748,
13
+ 2870763221,
14
+ 3624381080,
15
+ 310598401,
16
+ 607225278,
17
+ 1426881987,
18
+ 1925078388,
19
+ 2162078206,
20
+ 2614888103,
21
+ 3248222580,
22
+ 3835390401,
23
+ 4022224774,
24
+ 264347078,
25
+ 604807628,
26
+ 770255983,
27
+ 1249150122,
28
+ 1555081692,
29
+ 1996064986,
30
+ 2554220882,
31
+ 2821834349,
32
+ 2952996808,
33
+ 3210313671,
34
+ 3336571891,
35
+ 3584528711,
36
+ 113926993,
37
+ 338241895,
38
+ 666307205,
39
+ 773529912,
40
+ 1294757372,
41
+ 1396182291,
42
+ 1695183700,
43
+ 1986661051,
44
+ 2177026350,
45
+ 2456956037,
46
+ 2730485921,
47
+ 2820302411,
48
+ 3259730800,
49
+ 3345764771,
50
+ 3516065817,
51
+ 3600352804,
52
+ 4094571909,
53
+ 275423344,
54
+ 430227734,
55
+ 506948616,
56
+ 659060556,
57
+ 883997877,
58
+ 958139571,
59
+ 1322822218,
60
+ 1537002063,
61
+ 1747873779,
62
+ 1955562222,
63
+ 2024104815,
64
+ 2227730452,
65
+ 2361852424,
66
+ 2428436474,
67
+ 2756734187,
68
+ 3204031479,
69
+ 3329325298
70
+ ]);
71
+ var rotr = (x, n) => x >>> n | x << 32 - n;
72
+ function utf8(text) {
73
+ const out = [];
74
+ for (const char of text) {
75
+ let cp = char.codePointAt(0);
76
+ if (cp >= 55296 && cp <= 57343)
77
+ cp = 65533;
78
+ if (cp < 128)
79
+ out.push(cp);
80
+ else if (cp < 2048)
81
+ out.push(192 | cp >> 6, 128 | cp & 63);
82
+ else if (cp < 65536)
83
+ out.push(224 | cp >> 12, 128 | cp >> 6 & 63, 128 | cp & 63);
84
+ else
85
+ out.push(240 | cp >> 18, 128 | cp >> 12 & 63, 128 | cp >> 6 & 63, 128 | cp & 63);
86
+ }
87
+ return Uint8Array.from(out);
88
+ }
89
+ function sha256Hex(input) {
90
+ const isBytes = Object.prototype.toString.call(input) === "[object Uint8Array]";
91
+ if (typeof input !== "string" && !isBytes)
92
+ throw new TypeError("sha256Hex takes a string or a Uint8Array.");
93
+ const bytes = typeof input === "string" ? utf8(input) : input;
94
+ const length = bytes.length;
95
+ const padded = new Uint8Array((length + 8 >> 6) + 1 << 6);
96
+ padded.set(bytes);
97
+ padded[length] = 128;
98
+ const view = new DataView(padded.buffer);
99
+ view.setUint32(padded.length - 8, Math.floor(length / 536870912));
100
+ view.setUint32(padded.length - 4, length << 3 >>> 0);
101
+ const H = new Uint32Array([1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225]);
102
+ const W = new Uint32Array(64);
103
+ for (let offset = 0; offset < padded.length; offset += 64) {
104
+ for (let t = 0; t < 16; t++)
105
+ W[t] = view.getUint32(offset + t * 4);
106
+ for (let t = 16; t < 64; t++) {
107
+ const s0 = rotr(W[t - 15], 7) ^ rotr(W[t - 15], 18) ^ W[t - 15] >>> 3;
108
+ const s1 = rotr(W[t - 2], 17) ^ rotr(W[t - 2], 19) ^ W[t - 2] >>> 10;
109
+ W[t] = W[t - 16] + s0 + W[t - 7] + s1 >>> 0;
110
+ }
111
+ let a = H[0], b = H[1], c = H[2], d = H[3], e = H[4], f = H[5], g = H[6], h = H[7];
112
+ for (let t = 0; t < 64; t++) {
113
+ const t1 = h + (rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25)) + (e & f ^ ~e & g) + K[t] + W[t] >>> 0;
114
+ const t2 = (rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22)) + (a & b ^ a & c ^ b & c) >>> 0;
115
+ h = g;
116
+ g = f;
117
+ f = e;
118
+ e = d + t1 >>> 0;
119
+ d = c;
120
+ c = b;
121
+ b = a;
122
+ a = t1 + t2 >>> 0;
123
+ }
124
+ H[0] += a;
125
+ H[1] += b;
126
+ H[2] += c;
127
+ H[3] += d;
128
+ H[4] += e;
129
+ H[5] += f;
130
+ H[6] += g;
131
+ H[7] += h;
132
+ }
133
+ return Array.from(H, (word) => word.toString(16).padStart(8, "0")).join("");
134
+ }
135
+ // src/rsa-pkcs1v15.js
136
+ var RsaPkcs1v15Error = class extends Error {
137
+ constructor(reason) {
138
+ super("RSA PKCS#1 v1.5 encryption refused.");
139
+ this.name = "RsaPkcs1v15Error";
140
+ this.code = "rsa_pkcs1v15_refused";
141
+ this.reason = reason;
142
+ }
143
+ };
144
+ var refuse = (reason) => new RsaPkcs1v15Error(reason);
145
+ var BASE64 = /^[A-Za-z0-9+/]+={0,2}$/;
146
+ var SHA256_HEX = /^[0-9a-f]{64}$/;
147
+ var RSA_ALGORITHM = [48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0];
148
+ var MODULUS_BYTES = [128, 256, 384, 512];
149
+ var MIN_PADDING = 8;
150
+ var MAX_DRAWS = 16;
151
+ var TYPED_ARRAY = Object.getPrototypeOf(Uint8Array.prototype);
152
+ var typedArrayName = Object.getOwnPropertyDescriptor(TYPED_ARRAY, Symbol.toStringTag).get;
153
+ function parseRsaPublicKey(key) {
154
+ const spki = key && typeof key === "object" ? key.spki : void 0;
155
+ const pin = key && typeof key === "object" ? key.sha256 : void 0;
156
+ if (typeof spki !== "string" || spki.length > 1024 || spki.length % 4 !== 0 || !BASE64.test(spki))
157
+ throw refuse("key");
158
+ if (typeof pin !== "string" || !SHA256_HEX.test(pin))
159
+ throw refuse("key");
160
+ let binary;
161
+ try {
162
+ binary = atob(spki);
163
+ }
164
+ catch {
165
+ throw refuse("key");
166
+ }
167
+ if (btoa(binary) !== spki)
168
+ throw refuse("key");
169
+ const der = Uint8Array.from(binary, (c) => c.charCodeAt(0));
170
+ if (sha256Hex(der) !== pin)
171
+ throw refuse("key");
172
+ const outer = readElement(der, 0, 48);
173
+ if (outer.end !== der.length || outer.start + RSA_ALGORITHM.length > der.length)
174
+ throw refuse("key");
175
+ if (!RSA_ALGORITHM.every((byte, i) => der[outer.start + i] === byte))
176
+ throw refuse("key");
177
+ const bits = readElement(der, outer.start + RSA_ALGORITHM.length, 3);
178
+ if (bits.end !== outer.end || bits.start === bits.end || der[bits.start] !== 0)
179
+ throw refuse("key");
180
+ const rsa = readElement(der, bits.start + 1, 48);
181
+ if (rsa.end !== bits.end)
182
+ throw refuse("key");
183
+ const modulus = readPositiveInteger(der, rsa.start);
184
+ const exponent = readPositiveInteger(der, modulus.end);
185
+ if (exponent.end !== rsa.end)
186
+ throw refuse("key");
187
+ const n = modulus.bytes;
188
+ if (!MODULUS_BYTES.includes(n.length) || !(n[0] & 128) || !(n[n.length - 1] & 1))
189
+ throw refuse("key");
190
+ const e = exponent.bytes;
191
+ if (e.length !== 3 || e[0] !== 1 || e[1] !== 0 || e[2] !== 1)
192
+ throw refuse("key");
193
+ return Object.freeze({ n: toBigInt(n), e: 65537n, size: n.length });
194
+ }
195
+ function rsaesPkcs1v15Encrypt(key, message, random) {
196
+ const { n, e, size } = parseRsaPublicKey(key);
197
+ if (typedArrayName.call(message) !== "Uint8Array")
198
+ throw refuse("message");
199
+ let bytes;
200
+ try {
201
+ bytes = new Uint8Array(message);
202
+ }
203
+ catch {
204
+ throw refuse("message");
205
+ }
206
+ const em = new Uint8Array(size);
207
+ try {
208
+ if (bytes.length > size - MIN_PADDING - 3)
209
+ throw refuse("message");
210
+ em[1] = 2;
211
+ fillNonZero(em.subarray(2, size - bytes.length - 1), random);
212
+ em.set(bytes, size - bytes.length);
213
+ return toBytes(modPow(toBigInt(em), e, n), size);
214
+ }
215
+ finally {
216
+ em.fill(0);
217
+ bytes.fill(0);
218
+ }
219
+ }
220
+ function readElement(der, at, tag) {
221
+ if (at + 2 > der.length || der[at] !== tag)
222
+ throw refuse("key");
223
+ let length = der[at + 1];
224
+ let start = at + 2;
225
+ if (length & 128) {
226
+ const count = length & 127;
227
+ if (count === 0 || count > 2 || start + count > der.length || der[start] === 0)
228
+ throw refuse("key");
229
+ length = count === 1 ? der[start] : der[start] * 256 + der[start + 1];
230
+ if (length < 128)
231
+ throw refuse("key");
232
+ start += count;
233
+ }
234
+ if (start + length > der.length)
235
+ throw refuse("key");
236
+ return { start, end: start + length };
237
+ }
238
+ function readPositiveInteger(der, at) {
239
+ const { start, end } = readElement(der, at, 2);
240
+ if (end === start || der[start] & 128)
241
+ throw refuse("key");
242
+ if (der[start] === 0 && (end - start === 1 || !(der[start + 1] & 128)))
243
+ throw refuse("key");
244
+ return { bytes: der.subarray(der[start] === 0 ? start + 1 : start, end), end };
245
+ }
246
+ function fillNonZero(target, random) {
247
+ if (!random || typeof random.getRandomValues !== "function")
248
+ throw refuse("random");
249
+ const draw = new Uint8Array(target.length);
250
+ let filled = 0;
251
+ try {
252
+ for (let round = 0; round < MAX_DRAWS && filled < target.length; round++) {
253
+ draw.fill(0);
254
+ random.getRandomValues(draw);
255
+ for (let i = 0; i < draw.length && filled < target.length; i++)
256
+ if (draw[i] !== 0)
257
+ target[filled++] = draw[i];
258
+ }
259
+ }
260
+ catch {
261
+ throw refuse("random");
262
+ }
263
+ finally {
264
+ draw.fill(0);
265
+ }
266
+ if (filled < target.length)
267
+ throw refuse("random");
268
+ }
269
+ function toBigInt(bytes) {
270
+ let hex2 = "";
271
+ for (let i = 0; i < bytes.length; i++)
272
+ hex2 += (bytes[i] < 16 ? "0" : "") + bytes[i].toString(16);
273
+ return BigInt(`0x${hex2}`);
274
+ }
275
+ function toBytes(value, size) {
276
+ const hex2 = value.toString(16).padStart(size * 2, "0");
277
+ const out = new Uint8Array(size);
278
+ for (let i = 0; i < size; i++)
279
+ out[i] = parseInt(hex2.slice(2 * i, 2 * i + 2), 16);
280
+ return out;
281
+ }
282
+ function modPow(base, exponent, modulus) {
283
+ let result = 1n;
284
+ let square = base % modulus;
285
+ for (let rest = exponent; rest > 0n; rest >>= 1n) {
286
+ if (rest & 1n)
287
+ result = result * square % modulus;
288
+ square = square * square % modulus;
289
+ }
290
+ return result;
291
+ }
292
+ // src/gmo.js
293
+ var GMO_PSP = "gmo_pg";
294
+ var GMO_CLIENT_TYPE = "js-legacy";
295
+ var GMO_CONTENT_TYPE = "application/json";
296
+ var GMO_TOKEN_PATH = "/payment/CreateToken.json";
297
+ var GMO_TOKEN_HOSTS = Object.freeze({ production: "token.mul-pay.jp", sandbox: "stg.token.mul-pay.jp" });
298
+ var GMO_TOKEN_URLS = Object.freeze({
299
+ production: `https://${GMO_TOKEN_HOSTS.production}${GMO_TOKEN_PATH}`,
300
+ sandbox: `https://${GMO_TOKEN_HOSTS.sandbox}${GMO_TOKEN_PATH}`
301
+ });
302
+ var GMO_SHARED_KEYS = Object.freeze({
303
+ [GMO_TOKEN_HOSTS.production]: Object.freeze({
304
+ spki: "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzJ6Ps4kEHAoUxWoTQM2YzvCnJrCpYo3kUKV6G8Pbl7NU1eAkF+rGKhGQVOqULbOa7bS+67txfK+p+WhYIVpxoCzkL9rFKKSb1qeW+phosmN3sXYo0IUa658adLvvpPzpwAqqTu+WNiANZrlstuCC2/dRBwGVl9i8W1pxJZbz2j2lPD7G/jxnqWgfDw+d/EXUAKazS/G6Dk+WoZkmTqkIzsJij5QX4xqmXbdyfsj6BXfmBS1RLAsngJ8bxtshRY9uQ6faSCuTaEF5l38Qh9HhXBoFB+MsOKQ4biUwgW/WaFc5KZ75VDFadrJtUn+5XOlY+iXIQhgdp/zewoZda0rGnQIDAQAB",
305
+ sha256: "c12555cbac901b38910f7f5034a97e353767e1ab6d7c8362c13d0b82f618e142"
306
+ }),
307
+ [GMO_TOKEN_HOSTS.sandbox]: Object.freeze({
308
+ spki: "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoRuXDRz86jW+7es/BxzFJAmSxsjt69NvjrRCBsmBZb29luUsayl0Ge0pFDXYasVcv0V53S2AZXsikg+dxl3Ykxv0578LMNrKoMvuSDAOZP44/wIaEhN7375754kdubdvK+fHDdW48Q4t2GLrkzMcWjoYgflSW4ldIA/jvnIAine2fK+3ho2WRbIOLHSSwKmAOPI6CKs5v8yN9fg9MvX8IOi2rmFxu0NnYYv32w5qW5BHVzqD1w1ZKfrQHhhFk1Ngkle66NUoyCpVYCsXCJyLwfeN6M2vOIM/ob/K89XXUuAJzSSOgLBVUlSwOoxH35nr1TaKIu5VXp9irYBfiLmJewIDAQAB",
309
+ sha256: "0b065ee8e674fd50f01f9906c1e2393032dfe739eebc9d7b36ba7628312a63d8"
310
+ })
311
+ });
312
+ var SHOP_ID = Object.freeze({ production: /^[0-9]{13}$/, sandbox: /^tshop[0-9]{8}$/ });
313
+ var PASSPHRASE = "SecretPassphrase";
314
+ var PBKDF2_ITERATIONS = 100;
315
+ var ENVELOPE_KEYS = Object.freeze(["createCount", "encryptionParameters", "encryptedData"]);
316
+ var PARAMETER_KEYS = Object.freeze(["type", "apiKey", "keySpec", "signature"]);
317
+ var BODY_LIMIT = 8192;
318
+ var BASE642 = /^[A-Za-z0-9+/]+={0,2}$/;
319
+ var SIGNATURE = /^[0-9a-f]{40}$/;
320
+ var KEY_SPEC_BYTES = 256;
321
+ var GMO_REFUSAL_REASONS = Object.freeze([
322
+ "request",
323
+ "psp",
324
+ "url",
325
+ "environment_mismatch",
326
+ "template",
327
+ "card",
328
+ "test_card_required",
329
+ "crypto"
330
+ ]);
331
+ var GmoError = class extends Error {
332
+ /** @param {string} reason one of GMO_REFUSAL_REASONS @param {string} message */
333
+ constructor(reason, message) {
334
+ super(`Refusing to pay: ${message}`);
335
+ this.name = "GmoError";
336
+ this.reason = reason;
337
+ }
338
+ };
339
+ var refuse2 = (reason, message) => {
340
+ throw new GmoError(reason, message);
341
+ };
342
+ var record = (value) => !!value && typeof value === "object" && !Array.isArray(value);
343
+ var own = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
344
+ function gmoTokenEnvironment(rawUrl) {
345
+ if (typeof rawUrl !== "string" || rawUrl.length > 256 || rawUrl.includes("?") || rawUrl.includes("#"))
346
+ return null;
347
+ let url;
348
+ try {
349
+ url = new URL(rawUrl);
350
+ }
351
+ catch {
352
+ return null;
353
+ }
354
+ if (url.protocol !== "https:" || url.port || url.username || url.password || url.search || url.hash)
355
+ return null;
356
+ if (url.href !== rawUrl || url.pathname !== GMO_TOKEN_PATH)
357
+ return null;
358
+ if (url.hostname === GMO_TOKEN_HOSTS.production)
359
+ return "production";
360
+ if (url.hostname === GMO_TOKEN_HOSTS.sandbox)
361
+ return "sandbox";
362
+ return null;
363
+ }
364
+ function isGmoTokenHost(rawUrl) {
365
+ if (typeof rawUrl !== "string")
366
+ return false;
367
+ let url;
368
+ try {
369
+ url = new URL(rawUrl);
370
+ }
371
+ catch {
372
+ return false;
373
+ }
374
+ const host = url.hostname.toLowerCase().replace(/\.$/, "");
375
+ return host === GMO_TOKEN_HOSTS.production || host === GMO_TOKEN_HOSTS.sandbox;
376
+ }
377
+ function base64Length(text) {
378
+ if (typeof text !== "string" || text.length === 0 || text.length % 4 !== 0 || !BASE642.test(text))
379
+ return -1;
380
+ let binary;
381
+ try {
382
+ binary = atob(text);
383
+ }
384
+ catch {
385
+ return -1;
386
+ }
387
+ return btoa(binary) === text ? binary.length : -1;
388
+ }
389
+ function parseGmoSharedPkBody(body, environment) {
390
+ if (typeof body !== "string" || body.length > BODY_LIMIT || !own(SHOP_ID, environment))
391
+ return null;
392
+ let parsed;
393
+ try {
394
+ parsed = JSON.parse(body);
395
+ }
396
+ catch {
397
+ return null;
398
+ }
399
+ if (!record(parsed) || !Object.keys(parsed).every((key) => ENVELOPE_KEYS.includes(key)))
400
+ return null;
401
+ const hasCount = own(parsed, "createCount");
402
+ if (hasCount && parsed.createCount !== null && parsed.createCount !== "1")
403
+ return null;
404
+ const parameters = parsed.encryptionParameters;
405
+ if (!record(parameters) || Object.keys(parameters).length !== PARAMETER_KEYS.length || !PARAMETER_KEYS.every((key) => own(parameters, key) && typeof parameters[key] === "string"))
406
+ return null;
407
+ const { type, apiKey, keySpec, signature } = parameters;
408
+ if (type !== "SHARED_PK" || !SHOP_ID[environment].test(apiKey))
409
+ return null;
410
+ if (base64Length(keySpec) !== KEY_SPEC_BYTES || !SIGNATURE.test(signature))
411
+ return null;
412
+ const dataLength = base64Length(parsed.encryptedData);
413
+ if (dataLength < 16 || dataLength % 16 !== 0)
414
+ return null;
415
+ const canonical = serializeEnvelope(hasCount ? { createCount: parsed.createCount } : {}, apiKey, keySpec, signature, parsed.encryptedData);
416
+ if (canonical !== body)
417
+ return null;
418
+ return hasCount ? { createCount: parsed.createCount, apiKey } : { apiKey };
419
+ }
420
+ function serializeEnvelope(count, apiKey, keySpec, signature, encryptedData) {
421
+ return JSON.stringify({ ...count, encryptionParameters: { type: "SHARED_PK", apiKey, keySpec, signature }, encryptedData });
422
+ }
423
+ function headerValues(headers, name) {
424
+ if (headers === void 0)
425
+ return [];
426
+ if (!record(headers))
427
+ return null;
428
+ const values = [];
429
+ for (const [key, value] of Object.entries(headers)) {
430
+ if (typeof value !== "string")
431
+ return null;
432
+ if (key.toLowerCase() === name)
433
+ values.push(value);
434
+ }
435
+ return values;
436
+ }
437
+ function isGmoSharedPkRequest(request) {
438
+ if (!record(request) || request.method !== "POST")
439
+ return false;
440
+ const environment = gmoTokenEnvironment(request.url);
441
+ if (!environment)
442
+ return false;
443
+ const clientType = headerValues(request.headers, "x-mp-client-type");
444
+ if (!clientType || clientType.length !== 1 || clientType[0] !== GMO_CLIENT_TYPE)
445
+ return false;
446
+ const contentType = headerValues(request.headers, "content-type");
447
+ if (!contentType || contentType.length > 1 || contentType.length === 1 && !/^application\/json(?:\s*;\s*charset=utf-8)?$/i.test(contentType[0].trim()))
448
+ return false;
449
+ return parseGmoSharedPkBody(request.body, environment) !== null;
450
+ }
451
+ function gmoShopId(request) {
452
+ if (!isGmoSharedPkRequest(request))
453
+ return null;
454
+ return parseGmoSharedPkBody(
455
+ /** @type {string} */
456
+ request?.body,
457
+ /** @type {'production' | 'sandbox'} */
458
+ gmoTokenEnvironment(request?.url)).apiKey;
459
+ }
460
+ var utf82 = (text) => new TextEncoder().encode(text);
461
+ var hex = (bytes) => Array.from(bytes, (byte) => (byte < 16 ? "0" : "") + byte.toString(16)).join("");
462
+ function base64(bytes) {
463
+ let binary = "";
464
+ for (let i = 0; i < bytes.length; i++)
465
+ binary += String.fromCharCode(bytes[i]);
466
+ return btoa(binary);
467
+ }
468
+ function holderName(name, number) {
469
+ if (typeof name !== "string")
470
+ return "";
471
+ const folded = name.normalize("NFKD").toUpperCase().replace(/[^A-Z0-9 ,./-]/g, "").replace(/\s+/g, " ").trim().slice(0, 50).trim();
472
+ return folded === number ? "" : folded;
473
+ }
474
+ function cardPlaintext(card) {
475
+ if (!record(card))
476
+ refuse2("card", "no card to send.");
477
+ const number = String(card.number ?? "").replace(/[ -]/g, "");
478
+ const month = String(card.month ?? "").padStart(2, "0");
479
+ const fullYear = String(card.year ?? "");
480
+ const year = fullYear.length === 4 ? fullYear.slice(2) : fullYear;
481
+ const hasCvc = card.cvc !== void 0 && card.cvc !== null && card.cvc !== "";
482
+ const cvc = hasCvc ? String(card.cvc) : null;
483
+ if (!/^[0-9]{10,16}$/.test(number) || !/^(?:0[1-9]|1[0-2])$/.test(month) || !/^[0-9]{2}$/.test(year) || !/^(?:[0-9]{2}|[0-9]{4})$/.test(fullYear) || cvc !== null && !/^[0-9]{3,4}$/.test(cvc)) {
484
+ refuse2("card", "this card cannot be sent to GMO.");
485
+ }
486
+ return JSON.stringify({
487
+ deviceFingerprint: "",
488
+ card: { cardNumber: number, cardholderName: holderName(card.name, number), expiryMonth: month, expiryYear: year, securityCode: cvc }
489
+ });
490
+ }
491
+ async function buildGmoSharedPkBody(templateBody, card, { crypto, host } = {}) {
492
+ const environment = host === GMO_TOKEN_HOSTS.production ? "production" : host === GMO_TOKEN_HOSTS.sandbox ? "sandbox" : null;
493
+ if (!environment)
494
+ refuse2("url", "this is not a GMO token host.");
495
+ const template = parseGmoSharedPkBody(templateBody, environment);
496
+ if (!template)
497
+ refuse2("template", "the paused request is not GMO's single-token card request.");
498
+ const subtle = crypto && crypto.subtle;
499
+ if (!subtle || typeof crypto.getRandomValues !== "function")
500
+ refuse2("crypto", "this device cannot encrypt for GMO.");
501
+ const plaintext = utf82(cardPlaintext(card));
502
+ const iv = new Uint8Array(16);
503
+ const salt = new Uint8Array(16);
504
+ let keyMessage = new Uint8Array(0);
505
+ try {
506
+ crypto.getRandomValues(iv);
507
+ crypto.getRandomValues(salt);
508
+ if (iv.every((byte) => byte === 0) || salt.every((byte) => byte === 0))
509
+ throw new Error("no randomness");
510
+ const passphrase = await subtle.importKey("raw", utf82(PASSPHRASE), "PBKDF2", false, ["deriveKey"]);
511
+ const aes = await subtle.deriveKey({ name: "PBKDF2", hash: "SHA-1", salt, iterations: PBKDF2_ITERATIONS }, passphrase, { name: "AES-CBC", length: 128 }, false, ["encrypt"]);
512
+ const encryptedData = base64(new Uint8Array(await subtle.encrypt({ name: "AES-CBC", iv }, aes, plaintext)));
513
+ keyMessage = utf82(JSON.stringify({ iv: hex(iv), salt: hex(salt) }));
514
+ const keySpec = base64(rsaesPkcs1v15Encrypt(GMO_SHARED_KEYS[host], keyMessage, crypto));
515
+ const signature = hex(new Uint8Array(await subtle.digest("SHA-1", utf82(`${template.apiKey}|${keySpec}|${encryptedData}`))));
516
+ const count = own(template, "createCount") ? { createCount: template.createCount } : {};
517
+ const body = serializeEnvelope(count, template.apiKey, keySpec, signature, encryptedData);
518
+ if (!parseGmoSharedPkBody(body, environment))
519
+ throw new Error("rebuilt body out of shape");
520
+ return body;
521
+ }
522
+ catch {
523
+ return refuse2("crypto", "the card could not be encrypted for GMO on this device.");
524
+ }
525
+ finally {
526
+ plaintext.fill(0);
527
+ iv.fill(0);
528
+ salt.fill(0);
529
+ keyMessage.fill(0);
530
+ }
531
+ }
532
+ var TOKEN = /^[0-9a-f]{64}$/;
533
+ var MASKED_NUMBER = /^[0-9]{4,6}\*+[0-9]{4}$/;
534
+ var RFC3339 = /^[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12][0-9]|3[01])T(?:[01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\.[0-9]{1,9})?(?:Z|[+-](?:[01][0-9]|2[0-3]):[0-5][0-9])$/;
535
+ var REFUSAL_RESULTS = Object.freeze(["validation_error", "decryption_error"]);
536
+ var LEGACY_CODE = /^[0-9]{3}$/;
537
+ var RESPONSE_LIMIT = 4096;
538
+ function parseResponse(text) {
539
+ if (typeof text !== "string" || text.length > RESPONSE_LIMIT)
540
+ return null;
541
+ try {
542
+ const parsed = JSON.parse(text);
543
+ return record(parsed) ? parsed : null;
544
+ }
545
+ catch {
546
+ return null;
547
+ }
548
+ }
549
+ function sanitizeGmoTokenResponse(text) {
550
+ const parsed = parseResponse(text);
551
+ if (!parsed || parsed.result !== "success")
552
+ return null;
553
+ const { maskedCardNumber, tokenExpiryDate, isSecurityCodeSet, tokenList } = parsed;
554
+ if (typeof maskedCardNumber !== "string" || !MASKED_NUMBER.test(maskedCardNumber) || typeof tokenExpiryDate !== "string" || !RFC3339.test(tokenExpiryDate) || typeof isSecurityCodeSet !== "boolean" || !Array.isArray(tokenList) || tokenList.length !== 1 || typeof tokenList[0] !== "string" || !TOKEN.test(tokenList[0]))
555
+ return null;
556
+ return JSON.stringify({ result: "success", maskedCardNumber, tokenExpiryDate, isSecurityCodeSet, tokenList: [tokenList[0]] });
557
+ }
558
+ function gmoTokenMatchesCard(sanitized, card) {
559
+ const parsed = parseResponse(sanitized);
560
+ const number = String(card?.number ?? "").replace(/[ -]/g, "");
561
+ if (!parsed || typeof parsed.maskedCardNumber !== "string" || !/^[0-9]{10,16}$/.test(number))
562
+ return false;
563
+ const masked = parsed.maskedCardNumber;
564
+ const head = masked.slice(0, masked.indexOf("*"));
565
+ return masked.length === number.length && number.startsWith(head) && number.endsWith(masked.slice(-4));
566
+ }
567
+ function gmoRefusalCode(text) {
568
+ const parsed = parseResponse(text);
569
+ if (!parsed || !REFUSAL_RESULTS.includes(parsed.result) || !Array.isArray(parsed.errorList))
570
+ return null;
571
+ const first = parsed.errorList[0];
572
+ const legacy = record(first) && typeof first.legacyCode === "string" && LEGACY_CODE.test(first.legacyCode) ? first.legacyCode : null;
573
+ return legacy ?? parsed.result;
574
+ }
575
+ function gmoResponseFacts(status, text) {
576
+ if (status === 200) {
577
+ const body = sanitizeGmoTokenResponse(text);
578
+ return body ? { outcome: "token", body } : { outcome: "unknown" };
579
+ }
580
+ if (status === 400) {
581
+ const code = gmoRefusalCode(text);
582
+ return code ? { outcome: "refused", code } : { outcome: "unknown" };
583
+ }
584
+ return { outcome: "unknown" };
585
+ }
586
+ export { GMO_CLIENT_TYPE, GMO_CONTENT_TYPE, GMO_PSP, GMO_REFUSAL_REASONS, GMO_SHARED_KEYS, GMO_TOKEN_HOSTS, GMO_TOKEN_PATH, GMO_TOKEN_URLS, GmoError, buildGmoSharedPkBody, gmoRefusalCode, gmoResponseFacts, gmoShopId, gmoTokenEnvironment, gmoTokenMatchesCard, isGmoSharedPkRequest, isGmoTokenHost, parseGmoSharedPkBody, sanitizeGmoTokenResponse };