@tempoxyz/patron 0.0.18 → 0.0.20
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/bin.js +3 -3
- package/dist/chunks/{-643GYNS6.js → -RNUFDXSV.js} +1 -1
- package/dist/chunks/{chunk-XJOIDBXC.js → chunk-UFBFF3R6.js} +256 -16
- package/dist/chunks/{hook-CCXQ4T4L.js → hook-IWRRBFKG.js} +1 -1
- package/dist/chunks/{hook-process-YHSATQFR.js → hook-process-Y2W56T2X.js} +2 -2
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -4,14 +4,14 @@ const require = __patronCreateRequire(import.meta.url)
|
|
|
4
4
|
|
|
5
5
|
// src/bin.ts
|
|
6
6
|
if (process.argv[2] === "hook") {
|
|
7
|
-
const { runHookProcess } = await import("./chunks/hook-process-
|
|
7
|
+
const { runHookProcess } = await import("./chunks/hook-process-Y2W56T2X.js");
|
|
8
8
|
await runHookProcess().catch(() => void 0);
|
|
9
9
|
process.exit(0);
|
|
10
10
|
} else if (process.argv[2] === "pay") {
|
|
11
|
-
const { runPayProcess } = await import("./chunks/hook-process-
|
|
11
|
+
const { runPayProcess } = await import("./chunks/hook-process-Y2W56T2X.js");
|
|
12
12
|
await runPayProcess().catch(() => void 0);
|
|
13
13
|
process.exit(0);
|
|
14
14
|
} else {
|
|
15
|
-
const { run } = await import("./chunks/-
|
|
15
|
+
const { run } = await import("./chunks/-RNUFDXSV.js");
|
|
16
16
|
process.exitCode = await run(process.argv.slice(2));
|
|
17
17
|
}
|
|
@@ -27583,7 +27583,17 @@ var LeaderboardResponse = external_exports.object({
|
|
|
27583
27583
|
claimed: external_exports.boolean().default(true)
|
|
27584
27584
|
})
|
|
27585
27585
|
).default([]),
|
|
27586
|
-
|
|
27586
|
+
/**
|
|
27587
|
+
* tokens and usd are seals bought; spent and spentUsd are seals redeemed, which is what
|
|
27588
|
+
* sites have been paid.
|
|
27589
|
+
*/
|
|
27590
|
+
totals: external_exports.object({
|
|
27591
|
+
tokens: external_exports.number().int(),
|
|
27592
|
+
sites: external_exports.number().int(),
|
|
27593
|
+
usd,
|
|
27594
|
+
spent: external_exports.number().int().default(0),
|
|
27595
|
+
spentUsd: usd.default("0")
|
|
27596
|
+
})
|
|
27587
27597
|
});
|
|
27588
27598
|
var ClaimRequest = external_exports.object({
|
|
27589
27599
|
/** A registrable domain, or an X profile as "x.com/<handle>". */
|
|
@@ -34205,9 +34215,9 @@ var PARTIALLY_BLIND_RSA_TOKEN_TYPE = {
|
|
|
34205
34215
|
|
|
34206
34216
|
// ../../node_modules/.pnpm/@cloudflare+privacypass-ts@0.9.0/node_modules/@cloudflare/privacypass-ts/lib/src/pub_verif_token.js
|
|
34207
34217
|
var BlindRSAMode;
|
|
34208
|
-
(function(
|
|
34209
|
-
|
|
34210
|
-
|
|
34218
|
+
(function(BlindRSAMode2) {
|
|
34219
|
+
BlindRSAMode2[BlindRSAMode2["PSSZero"] = 0] = "PSSZero";
|
|
34220
|
+
BlindRSAMode2[BlindRSAMode2["PSS"] = 48] = "PSS";
|
|
34211
34221
|
})(BlindRSAMode || (BlindRSAMode = {}));
|
|
34212
34222
|
var PartiallyBlindRSAMode = BlindRSAMode;
|
|
34213
34223
|
var BLINDRSA_EXTRA_PARAMS = {
|
|
@@ -34528,29 +34538,259 @@ var MediaType2;
|
|
|
34528
34538
|
MediaType3["GENERIC_BATCHED_TOKEN_RESPONSE"] = "application/private-token-generic-batch-response";
|
|
34529
34539
|
})(MediaType2 || (MediaType2 = {}));
|
|
34530
34540
|
|
|
34541
|
+
// ../client/src/blind-rsa.ts
|
|
34542
|
+
var HASH = "SHA-384";
|
|
34543
|
+
var HASH_LENGTH = 48;
|
|
34544
|
+
var SALT_LENGTH = 48;
|
|
34545
|
+
var MAX_BLIND_ATTEMPTS = 128;
|
|
34546
|
+
async function importBlindRsaKey(cryptoKey) {
|
|
34547
|
+
const algorithm = cryptoKey.algorithm;
|
|
34548
|
+
if (cryptoKey.type !== "public" || algorithm.name !== "RSA-PSS")
|
|
34549
|
+
throw new Error("key is not an RSA-PSS public key");
|
|
34550
|
+
if (algorithm.hash.name !== HASH) throw new Error(`key hash is not ${HASH}`);
|
|
34551
|
+
const jwk = await crypto.subtle.exportKey("jwk", cryptoKey);
|
|
34552
|
+
if (!jwk.n || !jwk.e) throw new Error("key has invalid parameters");
|
|
34553
|
+
const n = bytesToInt(fromBase64UrlBytes(jwk.n));
|
|
34554
|
+
const e = bytesToInt(fromBase64UrlBytes(jwk.e));
|
|
34555
|
+
const modulusBits = n.toString(2).length;
|
|
34556
|
+
if (modulusBits !== algorithm.modulusLength)
|
|
34557
|
+
throw new Error("key has invalid parameters");
|
|
34558
|
+
return { cryptoKey, n, e, modulusBits, modulusBytes: Math.ceil(modulusBits / 8) };
|
|
34559
|
+
}
|
|
34560
|
+
async function blind(key, messages) {
|
|
34561
|
+
const encoded = await Promise.all(
|
|
34562
|
+
messages.map(
|
|
34563
|
+
(msg) => emsaPssEncode(
|
|
34564
|
+
msg,
|
|
34565
|
+
key.modulusBits - 1,
|
|
34566
|
+
crypto.getRandomValues(new Uint8Array(SALT_LENGTH))
|
|
34567
|
+
)
|
|
34568
|
+
)
|
|
34569
|
+
);
|
|
34570
|
+
return blindEncoded(key, encoded, randomBlindingFactors(key, messages.length));
|
|
34571
|
+
}
|
|
34572
|
+
function blindEncoded(key, encoded, factors) {
|
|
34573
|
+
const { n } = key;
|
|
34574
|
+
if (encoded.length !== factors.length)
|
|
34575
|
+
throw new Error("one blinding factor per message");
|
|
34576
|
+
const messages = encoded.map(bytesToInt);
|
|
34577
|
+
let product = 1n;
|
|
34578
|
+
for (const m of messages) {
|
|
34579
|
+
if (m >= n) throw new Error("invalid input");
|
|
34580
|
+
product = product * m % n;
|
|
34581
|
+
}
|
|
34582
|
+
if (gcd(product, n) !== 1n) throw new Error("invalid input");
|
|
34583
|
+
return messages.map((m, index) => {
|
|
34584
|
+
const factor = factors[index];
|
|
34585
|
+
const z2 = m * modPow(factor.r, key.e, n) % n;
|
|
34586
|
+
return { blindedMsg: intToBytes(z2, key.modulusBytes), inv: factor.inv };
|
|
34587
|
+
});
|
|
34588
|
+
}
|
|
34589
|
+
async function finalize2(key, msg, blindSig, inv) {
|
|
34590
|
+
if (blindSig.length !== key.modulusBytes) throw new Error("unexpected input size");
|
|
34591
|
+
const z2 = bytesToInt(blindSig);
|
|
34592
|
+
if (z2 >= key.n) throw new Error("invalid signature");
|
|
34593
|
+
const sig = intToBytes(z2 * inv % key.n, key.modulusBytes);
|
|
34594
|
+
const valid = await crypto.subtle.verify(
|
|
34595
|
+
{ name: "RSA-PSS", saltLength: SALT_LENGTH },
|
|
34596
|
+
key.cryptoKey,
|
|
34597
|
+
sig,
|
|
34598
|
+
msg.slice()
|
|
34599
|
+
);
|
|
34600
|
+
if (!valid) throw new Error("invalid signature");
|
|
34601
|
+
return sig;
|
|
34602
|
+
}
|
|
34603
|
+
async function emsaPssEncode(msg, emBits, salt) {
|
|
34604
|
+
const emLength = Math.ceil(emBits / 8);
|
|
34605
|
+
if (emLength < HASH_LENGTH + salt.length + 2) throw new Error("encoding error");
|
|
34606
|
+
const mHash = await digest(msg);
|
|
34607
|
+
const mPrime = new Uint8Array(8 + HASH_LENGTH + salt.length);
|
|
34608
|
+
mPrime.set(mHash, 8);
|
|
34609
|
+
mPrime.set(salt, 8 + HASH_LENGTH);
|
|
34610
|
+
const h = await digest(mPrime);
|
|
34611
|
+
const dbLength = emLength - HASH_LENGTH - 1;
|
|
34612
|
+
const mask = await mgf12(h, dbLength);
|
|
34613
|
+
const em = new Uint8Array(emLength);
|
|
34614
|
+
em[dbLength - salt.length - 1] = 1;
|
|
34615
|
+
em.set(salt, dbLength - salt.length);
|
|
34616
|
+
for (let index = 0; index < dbLength; index++)
|
|
34617
|
+
em[index] = (em[index] ?? 0) ^ (mask[index] ?? 0);
|
|
34618
|
+
em[0] = (em[0] ?? 0) & 255 >> 8 * emLength - emBits;
|
|
34619
|
+
em.set(h, dbLength);
|
|
34620
|
+
em[emLength - 1] = 188;
|
|
34621
|
+
return em;
|
|
34622
|
+
}
|
|
34623
|
+
function inverseMod2(a, n) {
|
|
34624
|
+
let oldR = a % n;
|
|
34625
|
+
let r = n;
|
|
34626
|
+
let oldS = 1n;
|
|
34627
|
+
let s = 0n;
|
|
34628
|
+
while (r !== 0n) {
|
|
34629
|
+
const quotient = oldR / r;
|
|
34630
|
+
const nextR = oldR - quotient * r;
|
|
34631
|
+
oldR = r;
|
|
34632
|
+
r = nextR;
|
|
34633
|
+
const nextS = oldS - quotient * s;
|
|
34634
|
+
oldS = s;
|
|
34635
|
+
s = nextS;
|
|
34636
|
+
}
|
|
34637
|
+
if (oldR !== 1n) return void 0;
|
|
34638
|
+
return oldS < 0n ? oldS + n : oldS;
|
|
34639
|
+
}
|
|
34640
|
+
function randomBlindingFactors(key, count) {
|
|
34641
|
+
const { n } = key;
|
|
34642
|
+
for (let attempt = 0; attempt < MAX_BLIND_ATTEMPTS; attempt++) {
|
|
34643
|
+
const factors = Array.from({ length: count }, () => randomBelow(key));
|
|
34644
|
+
const prefixes = [];
|
|
34645
|
+
let product = 1n;
|
|
34646
|
+
for (const r of factors) {
|
|
34647
|
+
product = product * r % n;
|
|
34648
|
+
prefixes.push(product);
|
|
34649
|
+
}
|
|
34650
|
+
let inverse = inverseMod2(product, n);
|
|
34651
|
+
if (inverse === void 0) continue;
|
|
34652
|
+
const inverses = new Array(count);
|
|
34653
|
+
for (let index = count - 1; index >= 0; index--) {
|
|
34654
|
+
const r = factors[index];
|
|
34655
|
+
inverses[index] = index === 0 ? inverse : inverse * prefixes[index - 1] % n;
|
|
34656
|
+
inverse = inverse * r % n;
|
|
34657
|
+
}
|
|
34658
|
+
return factors.map((r, index) => ({ r, inv: inverses[index] }));
|
|
34659
|
+
}
|
|
34660
|
+
throw new Error("blinding error: no invertible blinding factor found");
|
|
34661
|
+
}
|
|
34662
|
+
function randomBelow(key) {
|
|
34663
|
+
const bytes = new Uint8Array(key.modulusBytes);
|
|
34664
|
+
const topMask = 255 >> 8 * key.modulusBytes - key.modulusBits;
|
|
34665
|
+
try {
|
|
34666
|
+
for (let attempt = 0; attempt < MAX_BLIND_ATTEMPTS; attempt++) {
|
|
34667
|
+
crypto.getRandomValues(bytes);
|
|
34668
|
+
bytes[0] = (bytes[0] ?? 0) & topMask;
|
|
34669
|
+
const r = bytesToInt(bytes);
|
|
34670
|
+
if (r !== 0n && r < key.n) return r;
|
|
34671
|
+
}
|
|
34672
|
+
} finally {
|
|
34673
|
+
bytes.fill(0);
|
|
34674
|
+
}
|
|
34675
|
+
throw new Error("blinding error: no blinding factor below n found");
|
|
34676
|
+
}
|
|
34677
|
+
function modPow(base, exponent, modulus) {
|
|
34678
|
+
let result = 1n;
|
|
34679
|
+
let square = base % modulus;
|
|
34680
|
+
let remaining = exponent;
|
|
34681
|
+
while (remaining > 0n) {
|
|
34682
|
+
if (remaining & 1n) result = result * square % modulus;
|
|
34683
|
+
remaining >>= 1n;
|
|
34684
|
+
if (remaining > 0n) square = square * square % modulus;
|
|
34685
|
+
}
|
|
34686
|
+
return result;
|
|
34687
|
+
}
|
|
34688
|
+
function gcd(a, b) {
|
|
34689
|
+
let x = a;
|
|
34690
|
+
let y = b;
|
|
34691
|
+
while (y !== 0n) {
|
|
34692
|
+
const next = x % y;
|
|
34693
|
+
x = y;
|
|
34694
|
+
y = next;
|
|
34695
|
+
}
|
|
34696
|
+
return x;
|
|
34697
|
+
}
|
|
34698
|
+
async function mgf12(seed, length2) {
|
|
34699
|
+
const blocks = Math.ceil(length2 / HASH_LENGTH);
|
|
34700
|
+
const hashes = await Promise.all(
|
|
34701
|
+
Array.from({ length: blocks }, (_, counter) => {
|
|
34702
|
+
const input2 = new Uint8Array(seed.length + 4);
|
|
34703
|
+
input2.set(seed);
|
|
34704
|
+
new DataView(input2.buffer).setUint32(seed.length, counter);
|
|
34705
|
+
return digest(input2);
|
|
34706
|
+
})
|
|
34707
|
+
);
|
|
34708
|
+
const mask = new Uint8Array(blocks * HASH_LENGTH);
|
|
34709
|
+
hashes.forEach((hash2, index) => {
|
|
34710
|
+
mask.set(hash2, index * HASH_LENGTH);
|
|
34711
|
+
});
|
|
34712
|
+
return mask.subarray(0, length2);
|
|
34713
|
+
}
|
|
34714
|
+
async function digest(data) {
|
|
34715
|
+
return new Uint8Array(await crypto.subtle.digest(HASH, data.slice()));
|
|
34716
|
+
}
|
|
34717
|
+
var HEX = Array.from({ length: 256 }, (_, byte) => byte.toString(16).padStart(2, "0"));
|
|
34718
|
+
function bytesToInt(bytes) {
|
|
34719
|
+
if (bytes.length === 0) return 0n;
|
|
34720
|
+
let hex3 = "";
|
|
34721
|
+
for (const byte of bytes) hex3 += HEX[byte];
|
|
34722
|
+
return BigInt(`0x${hex3}`);
|
|
34723
|
+
}
|
|
34724
|
+
function intToBytes(value, length2) {
|
|
34725
|
+
const hex3 = value.toString(16);
|
|
34726
|
+
if (value < 0n || hex3.length > length2 * 2) throw new Error("integer too large");
|
|
34727
|
+
const padded = hex3.padStart(length2 * 2, "0");
|
|
34728
|
+
const bytes = new Uint8Array(length2);
|
|
34729
|
+
for (let index = 0; index < length2; index++)
|
|
34730
|
+
bytes[index] = Number.parseInt(padded.slice(index * 2, index * 2 + 2), 16);
|
|
34731
|
+
return bytes;
|
|
34732
|
+
}
|
|
34733
|
+
function fromBase64UrlBytes(value) {
|
|
34734
|
+
const base643 = value.replaceAll("-", "+").replaceAll("_", "/");
|
|
34735
|
+
const binary = atob(base643 + "=".repeat((4 - base643.length % 4) % 4));
|
|
34736
|
+
return Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
34737
|
+
}
|
|
34738
|
+
|
|
34531
34739
|
// ../client/src/privacy-pass.ts
|
|
34532
|
-
var {
|
|
34740
|
+
var { BLIND_RSA: BLIND_RSA2, TokenRequest: TokenRequest3, TokenResponse: TokenResponse3, convertRSASSAPSSToEnc: convertRSASSAPSSToEnc2 } = pub_verif_token_exports;
|
|
34533
34741
|
function tokenChallenge() {
|
|
34534
34742
|
return new TokenChallenge(TOKEN_TYPE, ISSUER_NAME, new Uint8Array(0));
|
|
34535
34743
|
}
|
|
34536
34744
|
async function createTokenRequests(publicKey, count) {
|
|
34745
|
+
if (!(count > 0)) return [];
|
|
34537
34746
|
const issuerKey = fromBase64Url(publicKey);
|
|
34538
|
-
const
|
|
34539
|
-
|
|
34540
|
-
|
|
34541
|
-
|
|
34542
|
-
|
|
34543
|
-
|
|
34747
|
+
const cryptoKey = await crypto.subtle.importKey(
|
|
34748
|
+
"spki",
|
|
34749
|
+
convertRSASSAPSSToEnc2(issuerKey).slice(),
|
|
34750
|
+
BLIND_RSA2.rsaParams,
|
|
34751
|
+
true,
|
|
34752
|
+
["verify"]
|
|
34753
|
+
);
|
|
34754
|
+
const key = await importBlindRsaKey(cryptoKey);
|
|
34755
|
+
if (key.modulusBytes !== BLIND_RSA2.Nk) throw new Error("issuer key is not RSA-2048");
|
|
34756
|
+
const [tokenKeyId, challengeDigest] = await Promise.all([
|
|
34757
|
+
sha256(issuerKey),
|
|
34758
|
+
sha256(tokenChallenge().serialize())
|
|
34759
|
+
]);
|
|
34760
|
+
const truncatedTokenKeyId = tokenKeyId[tokenKeyId.length - 1] ?? 0;
|
|
34761
|
+
const inputs = Array.from({ length: Math.ceil(count) }, () => {
|
|
34762
|
+
const nonce = crypto.getRandomValues(new Uint8Array(32));
|
|
34763
|
+
return new AuthenticatorInput(
|
|
34764
|
+
BLIND_RSA2,
|
|
34765
|
+
BLIND_RSA2.value,
|
|
34766
|
+
nonce,
|
|
34767
|
+
challengeDigest,
|
|
34768
|
+
tokenKeyId
|
|
34769
|
+
);
|
|
34770
|
+
});
|
|
34771
|
+
const tokenInputs = inputs.map((input2) => input2.serialize());
|
|
34772
|
+
const blinded = await blind(key, tokenInputs);
|
|
34773
|
+
const pending = inputs.map((authInput, index) => {
|
|
34774
|
+
const tokenInput = tokenInputs[index];
|
|
34775
|
+
const { blindedMsg, inv: blindInv } = blinded[index];
|
|
34776
|
+
let inv = blindInv;
|
|
34777
|
+
const request = new TokenRequest3(truncatedTokenKeyId, blindedMsg, BLIND_RSA2);
|
|
34778
|
+
return {
|
|
34544
34779
|
request: toBase64Url(request.serialize()),
|
|
34545
34780
|
async finalize(signature) {
|
|
34546
|
-
|
|
34547
|
-
const
|
|
34548
|
-
|
|
34781
|
+
if (inv === void 0) throw new Error("token was already finalized");
|
|
34782
|
+
const response = TokenResponse3.deserialize(fromBase64Url(signature));
|
|
34783
|
+
const authenticator = await finalize2(key, tokenInput, response.blindSig, inv);
|
|
34784
|
+
inv = void 0;
|
|
34785
|
+
return toBase64Url(new Token(BLIND_RSA2, authInput, authenticator).serialize());
|
|
34549
34786
|
}
|
|
34550
|
-
}
|
|
34551
|
-
}
|
|
34787
|
+
};
|
|
34788
|
+
});
|
|
34552
34789
|
return pending;
|
|
34553
34790
|
}
|
|
34791
|
+
async function sha256(data) {
|
|
34792
|
+
return new Uint8Array(await crypto.subtle.digest("SHA-256", data.slice()));
|
|
34793
|
+
}
|
|
34554
34794
|
|
|
34555
34795
|
// ../client/src/index.ts
|
|
34556
34796
|
async function getIssuer(gatewayUrl, fetchFn = fetch) {
|
|
@@ -25,7 +25,7 @@ async function runHookProcess(argument = process.argv[3]) {
|
|
|
25
25
|
if (isCursorPayload(payload)) process.stdout.write("{}\n");
|
|
26
26
|
if (!turnEnd(payload) && hookDomains(payload).length === 0) return;
|
|
27
27
|
if (await startPayment(raw)) return;
|
|
28
|
-
const { runHook } = await import("./hook-
|
|
28
|
+
const { runHook } = await import("./hook-IWRRBFKG.js");
|
|
29
29
|
await runHook({
|
|
30
30
|
readInput: async () => raw,
|
|
31
31
|
settings: resolveSettings(),
|
|
@@ -33,7 +33,7 @@ async function runHookProcess(argument = process.argv[3]) {
|
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
async function runPayProcess() {
|
|
36
|
-
const { PAY_TIMEOUT_MS, runHook } = await import("./hook-
|
|
36
|
+
const { PAY_TIMEOUT_MS, runHook } = await import("./hook-IWRRBFKG.js");
|
|
37
37
|
setTimeout(() => process.exit(0), PAY_TIMEOUT_MS + 1e3).unref();
|
|
38
38
|
const raw = await readStdin(HOOK_TIMEOUT_MS);
|
|
39
39
|
await runHook(
|