@nokinc-flur/sdk 1.0.3 → 1.0.4
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/dist/index.cjs +13 -51
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +13 -41
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1428,6 +1428,8 @@ function decodeAuthorizationQR(s) {
|
|
|
1428
1428
|
|
|
1429
1429
|
// src/offline/settlements.ts
|
|
1430
1430
|
import { z as z6 } from "zod";
|
|
1431
|
+
import { sha256 } from "@noble/hashes/sha256";
|
|
1432
|
+
import { bytesToHex as bytesToHex2 } from "@noble/hashes/utils";
|
|
1431
1433
|
var OfflineTokenSchema = z6.object({
|
|
1432
1434
|
tokenId: z6.string().uuid(),
|
|
1433
1435
|
tokenSerial: z6.string(),
|
|
@@ -1478,14 +1480,7 @@ var SettleResponseSchema = z6.object({
|
|
|
1478
1480
|
});
|
|
1479
1481
|
var ENCOUNTER_DOMAIN = "offline:v1:encounter";
|
|
1480
1482
|
async function sha256Hex(input) {
|
|
1481
|
-
|
|
1482
|
-
const enc2 = new TextEncoder().encode(input);
|
|
1483
|
-
if (subtle) {
|
|
1484
|
-
const buf = await subtle.digest("SHA-256", enc2);
|
|
1485
|
-
return Array.from(new Uint8Array(buf)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1486
|
-
}
|
|
1487
|
-
const mod = await import("crypto");
|
|
1488
|
-
return mod.createHash("sha256").update(input).digest("hex");
|
|
1483
|
+
return bytesToHex2(sha256(new TextEncoder().encode(input)));
|
|
1489
1484
|
}
|
|
1490
1485
|
async function computeEncounterId(input) {
|
|
1491
1486
|
return sha256Hex(
|
|
@@ -1533,8 +1528,8 @@ function createOfflineSettlementsClient(partner) {
|
|
|
1533
1528
|
|
|
1534
1529
|
// src/auth/hmac.ts
|
|
1535
1530
|
import { hmac } from "@noble/hashes/hmac";
|
|
1536
|
-
import { sha256 } from "@noble/hashes/sha256";
|
|
1537
|
-
function
|
|
1531
|
+
import { sha256 as sha2562 } from "@noble/hashes/sha256";
|
|
1532
|
+
function bytesToHex3(b) {
|
|
1538
1533
|
let s = "";
|
|
1539
1534
|
for (let i = 0; i < b.length; i++) s += b[i].toString(16).padStart(2, "0");
|
|
1540
1535
|
return s;
|
|
@@ -1546,7 +1541,7 @@ function constantTimeStringEqual(a, b) {
|
|
|
1546
1541
|
return diff === 0;
|
|
1547
1542
|
}
|
|
1548
1543
|
function bodySha256Hex(body) {
|
|
1549
|
-
return
|
|
1544
|
+
return bytesToHex3(sha2562(new TextEncoder().encode(body)));
|
|
1550
1545
|
}
|
|
1551
1546
|
function canonicalRequestString(input) {
|
|
1552
1547
|
return [
|
|
@@ -1558,8 +1553,8 @@ function canonicalRequestString(input) {
|
|
|
1558
1553
|
].join("\n");
|
|
1559
1554
|
}
|
|
1560
1555
|
function signRequestHMAC(input) {
|
|
1561
|
-
return
|
|
1562
|
-
hmac(
|
|
1556
|
+
return bytesToHex3(
|
|
1557
|
+
hmac(sha2562, input.apiSecret, canonicalRequestString(input))
|
|
1563
1558
|
);
|
|
1564
1559
|
}
|
|
1565
1560
|
function verifyRequestHMAC(input) {
|
|
@@ -2318,6 +2313,9 @@ function createAccountsClient(opts) {
|
|
|
2318
2313
|
|
|
2319
2314
|
// src/partner/client.ts
|
|
2320
2315
|
import { z as z11 } from "zod";
|
|
2316
|
+
import { sha256 as sha2563 } from "@noble/hashes/sha256";
|
|
2317
|
+
import { hmac as hmac2 } from "@noble/hashes/hmac";
|
|
2318
|
+
import { bytesToHex as bytesToHex4 } from "@noble/hashes/utils";
|
|
2321
2319
|
var PARTNER_SCOPES = [
|
|
2322
2320
|
"passes:write",
|
|
2323
2321
|
"passes:read",
|
|
@@ -2341,39 +2339,13 @@ var ApiCredentialPublicSchema = z11.object({
|
|
|
2341
2339
|
var MintedApiCredentialSchema = ApiCredentialPublicSchema.extend({
|
|
2342
2340
|
secret: z11.string().min(1)
|
|
2343
2341
|
});
|
|
2344
|
-
async function getSubtle() {
|
|
2345
|
-
const c = globalThis.crypto;
|
|
2346
|
-
if (c?.subtle) return c.subtle;
|
|
2347
|
-
const mod = await import("crypto");
|
|
2348
|
-
return mod.webcrypto.subtle;
|
|
2349
|
-
}
|
|
2350
2342
|
var enc = new TextEncoder();
|
|
2351
|
-
function bytesToHex3(buf) {
|
|
2352
|
-
const u = new Uint8Array(buf);
|
|
2353
|
-
let s = "";
|
|
2354
|
-
for (let i = 0; i < u.length; i++) {
|
|
2355
|
-
s += u[i].toString(16).padStart(2, "0");
|
|
2356
|
-
}
|
|
2357
|
-
return s;
|
|
2358
|
-
}
|
|
2359
2343
|
async function sha256Hex2(input) {
|
|
2360
|
-
const subtle = await getSubtle();
|
|
2361
2344
|
const data = typeof input === "string" ? enc.encode(input) : input;
|
|
2362
|
-
|
|
2363
|
-
const buf = await subtle.digest("SHA-256", buffer);
|
|
2364
|
-
return bytesToHex3(buf);
|
|
2345
|
+
return bytesToHex4(sha2563(data));
|
|
2365
2346
|
}
|
|
2366
2347
|
async function hmacSha256Hex(keyHex, message) {
|
|
2367
|
-
|
|
2368
|
-
const key = await subtle.importKey(
|
|
2369
|
-
"raw",
|
|
2370
|
-
enc.encode(keyHex),
|
|
2371
|
-
{ name: "HMAC", hash: "SHA-256" },
|
|
2372
|
-
false,
|
|
2373
|
-
["sign"]
|
|
2374
|
-
);
|
|
2375
|
-
const sig = await subtle.sign("HMAC", key, enc.encode(message));
|
|
2376
|
-
return bytesToHex3(sig);
|
|
2348
|
+
return bytesToHex4(hmac2(sha2563, enc.encode(keyHex), enc.encode(message)));
|
|
2377
2349
|
}
|
|
2378
2350
|
function defaultNonce2() {
|
|
2379
2351
|
const c = globalThis.crypto;
|