passkey-kit 0.12.1 → 0.14.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/README.md +408 -227
- package/{types → dist}/base.d.ts +1 -0
- package/dist/base.d.ts.map +1 -0
- package/{src/base.ts → dist/base.js} +8 -10
- package/dist/base.js.map +1 -0
- package/dist/base64url.d.ts +18 -0
- package/dist/base64url.d.ts.map +1 -0
- package/dist/base64url.js +18 -0
- package/dist/base64url.js.map +1 -0
- package/dist/constants.d.ts +91 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +115 -0
- package/dist/constants.js.map +1 -0
- package/dist/contract-errors.d.ts +69 -0
- package/dist/contract-errors.d.ts.map +1 -0
- package/dist/contract-errors.js +132 -0
- package/dist/contract-errors.js.map +1 -0
- package/dist/errors.d.ts +163 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +244 -0
- package/dist/errors.js.map +1 -0
- package/dist/events.d.ts +94 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +92 -0
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/indexer/codec.d.ts +18 -0
- package/dist/indexer/codec.d.ts.map +1 -0
- package/dist/indexer/codec.js +32 -0
- package/dist/indexer/codec.js.map +1 -0
- package/dist/indexer/index.d.ts +25 -0
- package/dist/indexer/index.d.ts.map +1 -0
- package/dist/indexer/index.js +34 -0
- package/dist/indexer/index.js.map +1 -0
- package/dist/indexer/mercury.d.ts +94 -0
- package/dist/indexer/mercury.d.ts.map +1 -0
- package/dist/indexer/mercury.js +245 -0
- package/dist/indexer/mercury.js.map +1 -0
- package/dist/indexer/stellar-indexer.d.ts +115 -0
- package/dist/indexer/stellar-indexer.d.ts.map +1 -0
- package/dist/indexer/stellar-indexer.js +279 -0
- package/dist/indexer/stellar-indexer.js.map +1 -0
- package/dist/indexer/types.d.ts +73 -0
- package/dist/indexer/types.d.ts.map +1 -0
- package/dist/indexer/types.js +9 -0
- package/dist/indexer/types.js.map +1 -0
- package/dist/kit/auth-payload.d.ts +106 -0
- package/dist/kit/auth-payload.d.ts.map +1 -0
- package/dist/kit/auth-payload.js +227 -0
- package/dist/kit/auth-payload.js.map +1 -0
- package/dist/kit/deploy-ops.d.ts +45 -0
- package/dist/kit/deploy-ops.d.ts.map +1 -0
- package/dist/kit/deploy-ops.js +69 -0
- package/dist/kit/deploy-ops.js.map +1 -0
- package/dist/kit/tx-ops.d.ts +95 -0
- package/dist/kit/tx-ops.d.ts.map +1 -0
- package/dist/kit/tx-ops.js +125 -0
- package/dist/kit/tx-ops.js.map +1 -0
- package/dist/kit/wallet-ops.d.ts +59 -0
- package/dist/kit/wallet-ops.d.ts.map +1 -0
- package/dist/kit/wallet-ops.js +122 -0
- package/dist/kit/wallet-ops.js.map +1 -0
- package/dist/kit/webauthn-ops.d.ts +55 -0
- package/dist/kit/webauthn-ops.d.ts.map +1 -0
- package/dist/kit/webauthn-ops.js +79 -0
- package/dist/kit/webauthn-ops.js.map +1 -0
- package/dist/kit.d.ts +132 -0
- package/dist/kit.d.ts.map +1 -0
- package/dist/kit.js +290 -0
- package/dist/kit.js.map +1 -0
- package/dist/managers/credential-manager.d.ts +39 -0
- package/dist/managers/credential-manager.d.ts.map +1 -0
- package/dist/managers/credential-manager.js +47 -0
- package/dist/managers/credential-manager.js.map +1 -0
- package/dist/managers/index.d.ts +7 -0
- package/dist/managers/index.d.ts.map +1 -0
- package/dist/managers/index.js +7 -0
- package/dist/managers/index.js.map +1 -0
- package/dist/managers/signer-manager.d.ts +62 -0
- package/dist/managers/signer-manager.d.ts.map +1 -0
- package/dist/managers/signer-manager.js +111 -0
- package/dist/managers/signer-manager.js.map +1 -0
- package/dist/managers/submission-manager.d.ts +52 -0
- package/dist/managers/submission-manager.d.ts.map +1 -0
- package/dist/managers/submission-manager.js +77 -0
- package/dist/managers/submission-manager.js.map +1 -0
- package/dist/relayer.d.ts +61 -0
- package/dist/relayer.d.ts.map +1 -0
- package/dist/relayer.js +122 -0
- package/dist/relayer.js.map +1 -0
- package/dist/rpc-data.d.ts +45 -0
- package/dist/rpc-data.d.ts.map +1 -0
- package/dist/rpc-data.js +61 -0
- package/dist/rpc-data.js.map +1 -0
- package/dist/sac.d.ts +31 -0
- package/dist/sac.d.ts.map +1 -0
- package/dist/sac.js +47 -0
- package/dist/sac.js.map +1 -0
- package/dist/server.d.ts +79 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +152 -0
- package/dist/server.js.map +1 -0
- package/dist/signers.d.ts +83 -0
- package/dist/signers.d.ts.map +1 -0
- package/dist/signers.js +124 -0
- package/dist/signers.js.map +1 -0
- package/dist/storage/index.d.ts +13 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +12 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/indexeddb.d.ts +26 -0
- package/dist/storage/indexeddb.d.ts.map +1 -0
- package/dist/storage/indexeddb.js +100 -0
- package/dist/storage/indexeddb.js.map +1 -0
- package/dist/storage/localStorage.d.ts +22 -0
- package/dist/storage/localStorage.d.ts.map +1 -0
- package/dist/storage/localStorage.js +86 -0
- package/dist/storage/localStorage.js.map +1 -0
- package/dist/storage/memory.d.ts +18 -0
- package/dist/storage/memory.d.ts.map +1 -0
- package/dist/storage/memory.js +41 -0
- package/dist/storage/memory.js.map +1 -0
- package/dist/types.d.ts +136 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +39 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +72 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +253 -0
- package/dist/utils.js.map +1 -0
- package/dist/validation.d.ts +42 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +75 -0
- package/dist/validation.js.map +1 -0
- package/dist/version.d.ts +7 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +9 -0
- package/dist/version.js.map +1 -0
- package/package.json +47 -20
- package/.claude/settings.local.json +0 -20
- package/.cursorrules +0 -170
- package/.gitattributes +0 -2
- package/.github/workflows/release.yml +0 -21
- package/.vscode/settings.json +0 -6
- package/PROPOSAL.md +0 -397
- package/cheatsheet.txt +0 -18
- package/clone-js-sdk.sh +0 -21
- package/packages/passkey-kit-sdk/README.md +0 -54
- package/packages/passkey-kit-sdk/package.json +0 -21
- package/packages/passkey-kit-sdk/src/index.ts +0 -171
- package/packages/passkey-kit-sdk/tsconfig.json +0 -98
- package/packages/passkey-kit-sdk/types/index.d.ts +0 -190
- package/packages/sac-sdk/README.md +0 -54
- package/packages/sac-sdk/package.json +0 -21
- package/packages/sac-sdk/src/index.ts +0 -586
- package/packages/sac-sdk/tsconfig.json +0 -98
- package/packages/sac-sdk/types/index.d.ts +0 -532
- package/pnpm-workspace.yaml +0 -2
- package/src/index.ts +0 -5
- package/src/kit.ts +0 -823
- package/src/sac.ts +0 -29
- package/src/server.ts +0 -179
- package/src/types.ts +0 -32
- package/tsconfig.json +0 -28
- package/types/index.d.ts +0 -5
- package/types/kit.d.ts +0 -95
- package/types/sac.d.ts +0 -13
- package/types/server.d.ts +0 -29
- package/types/types.d.ts +0 -22
package/dist/utils.js
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cryptographic and derivation helpers for the Passkey Kit SDK.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
import { StrKey, hash, xdr, Address } from "@stellar/stellar-sdk";
|
|
7
|
+
import base64url from "./base64url.js";
|
|
8
|
+
import { SECP256R1_PUBLIC_KEY_SIZE, SECP256R1_CURVE_ORDER, SECP256R1_FIELD_PRIME, SECP256R1_B, UNCOMPRESSED_PUBKEY_PREFIX, WEBAUTHN_CHALLENGE_SIZE, } from "./constants.js";
|
|
9
|
+
import { ValidationError, WebAuthnError, PasskeyKitErrorCode, } from "./errors.js";
|
|
10
|
+
// ============================================================================
|
|
11
|
+
// Deterministic contract-address derivation
|
|
12
|
+
// ============================================================================
|
|
13
|
+
/**
|
|
14
|
+
* Derive a smart-wallet contract address from a passkey credential id.
|
|
15
|
+
*
|
|
16
|
+
* The wallet's contract id is deterministic: `salt = sha256(keyId)` and the
|
|
17
|
+
* deployer address salts a `ContractIdPreimageFromAddress`. This determinism is
|
|
18
|
+
* load-bearing — the indexer reverse-lookup (keyId → wallet) re-derives the
|
|
19
|
+
* address the same way — so this function is pinned with golden vectors in
|
|
20
|
+
* `utils.test.ts`. Any change to the derivation breaks the tests instead of
|
|
21
|
+
* silently shifting deployed addresses.
|
|
22
|
+
*
|
|
23
|
+
* @param keyId - The raw credential id bytes
|
|
24
|
+
* @param deployerPublicKey - The deployer's `G…` public key
|
|
25
|
+
* @param networkPassphrase - The network passphrase
|
|
26
|
+
* @returns The derived contract address (`C…`)
|
|
27
|
+
*/
|
|
28
|
+
export function deriveContractAddress(keyId, deployerPublicKey, networkPassphrase) {
|
|
29
|
+
const preimage = xdr.HashIdPreimage.envelopeTypeContractId(new xdr.HashIdPreimageContractId({
|
|
30
|
+
networkId: hash(Buffer.from(networkPassphrase)),
|
|
31
|
+
contractIdPreimage: xdr.ContractIdPreimage.contractIdPreimageFromAddress(new xdr.ContractIdPreimageFromAddress({
|
|
32
|
+
address: Address.fromString(deployerPublicKey).toScAddress(),
|
|
33
|
+
salt: hash(keyId),
|
|
34
|
+
})),
|
|
35
|
+
}));
|
|
36
|
+
return StrKey.encodeContract(hash(preimage.toXDR()));
|
|
37
|
+
}
|
|
38
|
+
// ============================================================================
|
|
39
|
+
// WebAuthn public-key extraction
|
|
40
|
+
// ============================================================================
|
|
41
|
+
/** COSE map prefix for an ES256 (P-256) key: `{1:2, 3:-26, -1:1, -2: bytes(32)…}`. */
|
|
42
|
+
const ES256_COSE_PREFIX = Buffer.from([
|
|
43
|
+
0xa5, 0x01, 0x02, 0x03, 0x26, 0x20, 0x01, 0x21, 0x58, 0x20,
|
|
44
|
+
]);
|
|
45
|
+
/** COSE label for the `y` coordinate that must follow `x`: `-3: bytes(32)`. */
|
|
46
|
+
const COSE_Y_LABEL = Buffer.from([0x22, 0x58, 0x20]);
|
|
47
|
+
/**
|
|
48
|
+
* Whether an uncompressed `0x04 || x || y` key is a point on the P-256 curve
|
|
49
|
+
* (`y² ≡ x³ − 3x + b (mod p)`, coordinates in-field). A structurally valid but
|
|
50
|
+
* off-curve key would register fine and deploy a wallet no signature can ever
|
|
51
|
+
* satisfy, so extraction rejects it up front.
|
|
52
|
+
*/
|
|
53
|
+
export function isOnP256Curve(publicKey) {
|
|
54
|
+
const key = Buffer.from(publicKey);
|
|
55
|
+
if (key.length !== SECP256R1_PUBLIC_KEY_SIZE ||
|
|
56
|
+
key[0] !== UNCOMPRESSED_PUBKEY_PREFIX) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
const p = SECP256R1_FIELD_PRIME;
|
|
60
|
+
const x = BigInt("0x" + key.subarray(1, 33).toString("hex"));
|
|
61
|
+
const y = BigInt("0x" + key.subarray(33, 65).toString("hex"));
|
|
62
|
+
if (x >= p || y >= p)
|
|
63
|
+
return false;
|
|
64
|
+
const x3 = (((x * x) % p) * x) % p;
|
|
65
|
+
const rhs = (((x3 - ((3n * x) % p) + SECP256R1_B) % p) + p) % p;
|
|
66
|
+
return (y * y) % p === rhs;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Read `x || y` out of a COSE key at `xStart`, verifying the `y` label bytes
|
|
70
|
+
* and buffer bounds instead of trusting fixed offsets. Returns the
|
|
71
|
+
* uncompressed `0x04 || x || y` point, or `undefined` when the shape doesn't
|
|
72
|
+
* match.
|
|
73
|
+
*/
|
|
74
|
+
function coseCoordinates(buf, xStart) {
|
|
75
|
+
const yLabelStart = xStart + 32;
|
|
76
|
+
const yStart = yLabelStart + COSE_Y_LABEL.length;
|
|
77
|
+
if (buf.length < yStart + 32)
|
|
78
|
+
return undefined;
|
|
79
|
+
if (!buf.subarray(yLabelStart, yStart).equals(COSE_Y_LABEL))
|
|
80
|
+
return undefined;
|
|
81
|
+
return Buffer.concat([
|
|
82
|
+
Buffer.from([UNCOMPRESSED_PUBKEY_PREFIX]),
|
|
83
|
+
buf.subarray(xStart, xStart + 32),
|
|
84
|
+
buf.subarray(yStart, yStart + 32),
|
|
85
|
+
]);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Parse the attested COSE key out of raw `authenticatorData`:
|
|
89
|
+
* `rpIdHash(32) | flags(1) | counter(4) | aaguid(16) | credIdLen(2) | credId | COSE`.
|
|
90
|
+
* Every offset is bounds-checked and the ES256 COSE prefix is verified in
|
|
91
|
+
* place before any coordinate is sliced.
|
|
92
|
+
*/
|
|
93
|
+
function coseKeyFromAuthenticatorData(ad) {
|
|
94
|
+
if (ad.length < 55)
|
|
95
|
+
return undefined;
|
|
96
|
+
const credentialIdLength = (ad[53] << 8) | ad[54];
|
|
97
|
+
const coseStart = 55 + credentialIdLength;
|
|
98
|
+
if (ad.length < coseStart + ES256_COSE_PREFIX.length)
|
|
99
|
+
return undefined;
|
|
100
|
+
if (!ad
|
|
101
|
+
.subarray(coseStart, coseStart + ES256_COSE_PREFIX.length)
|
|
102
|
+
.equals(ES256_COSE_PREFIX)) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
return coseCoordinates(ad, coseStart + ES256_COSE_PREFIX.length);
|
|
106
|
+
}
|
|
107
|
+
/** Locate the ES256 COSE key inside a CBOR attestation object and extract it. */
|
|
108
|
+
function coseKeyFromAttestationObject(ao) {
|
|
109
|
+
const prefixIndex = ao.indexOf(ES256_COSE_PREFIX);
|
|
110
|
+
if (prefixIndex === -1)
|
|
111
|
+
return undefined;
|
|
112
|
+
return coseCoordinates(ao, prefixIndex + ES256_COSE_PREFIX.length);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Extract the 65-byte uncompressed secp256r1 public key from a WebAuthn
|
|
116
|
+
* registration (attestation) response.
|
|
117
|
+
*
|
|
118
|
+
* Tries, in order:
|
|
119
|
+
* 1. `response.publicKey` when it is already a raw uncompressed EC point.
|
|
120
|
+
* 2. `response.publicKey` decoded from SPKI via WebCrypto (`crypto.subtle`),
|
|
121
|
+
* which is the correct, non-magic-offset way to normalize the DER-encoded
|
|
122
|
+
* SubjectPublicKeyInfo most authenticators return.
|
|
123
|
+
* 3. Parsing the COSE key out of `authenticatorData`, then
|
|
124
|
+
* `attestationObject` — with the COSE structure verified in place, never
|
|
125
|
+
* trusted fixed offsets.
|
|
126
|
+
*
|
|
127
|
+
* Whatever the source, the result must be a valid point ON the P-256 curve;
|
|
128
|
+
* a mangled key is rejected here rather than deployed as an unusable wallet
|
|
129
|
+
* signer.
|
|
130
|
+
*
|
|
131
|
+
* @throws {WebAuthnError} If no valid public key can be extracted.
|
|
132
|
+
*/
|
|
133
|
+
export async function extractPublicKeyFromAttestation(response) {
|
|
134
|
+
let publicKey;
|
|
135
|
+
if (response.publicKey) {
|
|
136
|
+
const encodedPublicKey = base64url.toBuffer(response.publicKey);
|
|
137
|
+
if (encodedPublicKey.length === SECP256R1_PUBLIC_KEY_SIZE &&
|
|
138
|
+
encodedPublicKey[0] === UNCOMPRESSED_PUBKEY_PREFIX) {
|
|
139
|
+
publicKey = encodedPublicKey;
|
|
140
|
+
}
|
|
141
|
+
else if (typeof crypto?.subtle !== "undefined") {
|
|
142
|
+
try {
|
|
143
|
+
const imported = await crypto.subtle.importKey("spki", new Uint8Array(encodedPublicKey), { name: "ECDSA", namedCurve: "P-256" }, true, []);
|
|
144
|
+
const rawKey = await crypto.subtle.exportKey("raw", imported);
|
|
145
|
+
publicKey = Buffer.from(new Uint8Array(rawKey));
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
publicKey = undefined; // not SPKI — fall through to the COSE paths
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// Fall back to the attested COSE key when `response.publicKey` is absent or
|
|
153
|
+
// didn't yield a valid on-curve point.
|
|
154
|
+
if (!publicKey || !isOnP256Curve(publicKey)) {
|
|
155
|
+
publicKey =
|
|
156
|
+
(response.authenticatorData
|
|
157
|
+
? coseKeyFromAuthenticatorData(base64url.toBuffer(response.authenticatorData))
|
|
158
|
+
: undefined) ??
|
|
159
|
+
(response.attestationObject
|
|
160
|
+
? coseKeyFromAttestationObject(base64url.toBuffer(response.attestationObject))
|
|
161
|
+
: undefined);
|
|
162
|
+
}
|
|
163
|
+
if (!publicKey || !isOnP256Curve(publicKey)) {
|
|
164
|
+
throw new WebAuthnError("Could not extract a valid secp256r1 public key from the attestation response", PasskeyKitErrorCode.PUBLIC_KEY_EXTRACTION_FAILED);
|
|
165
|
+
}
|
|
166
|
+
return new Uint8Array(publicKey);
|
|
167
|
+
}
|
|
168
|
+
// ============================================================================
|
|
169
|
+
// Signature encoding
|
|
170
|
+
// ============================================================================
|
|
171
|
+
function malformedDer(reason) {
|
|
172
|
+
return new ValidationError(`Malformed DER ECDSA signature: ${reason}`, PasskeyKitErrorCode.INVALID_INPUT);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Convert a DER-encoded ECDSA signature to Stellar's compact `r || s` form with
|
|
176
|
+
* a low-S value (S <= n/2), as required by the secp256r1 host function.
|
|
177
|
+
*
|
|
178
|
+
* The DER structure is validated before any offset is dereferenced:
|
|
179
|
+
* sequence/integer tags, short-form lengths that exactly span the buffer, and
|
|
180
|
+
* `r`/`s` values in `[1, n-1]`. A WebAuthn P-256 signature always fits
|
|
181
|
+
* short-form DER (total length < 128 bytes), so long-form lengths are rejected.
|
|
182
|
+
*
|
|
183
|
+
* @param derSignature - The DER-encoded signature
|
|
184
|
+
* @returns 64-byte compact signature (`r || s`)
|
|
185
|
+
* @throws {ValidationError} If the signature is not structurally valid DER or
|
|
186
|
+
* `r`/`s` are out of range for P-256.
|
|
187
|
+
*/
|
|
188
|
+
export function compactSignature(derSignature) {
|
|
189
|
+
// DER: 0x30 [total-len] 0x02 [r-len] [r] 0x02 [s-len] [s]
|
|
190
|
+
if (derSignature.length < 8)
|
|
191
|
+
throw malformedDer("too short");
|
|
192
|
+
if (derSignature[0] !== 0x30)
|
|
193
|
+
throw malformedDer("missing SEQUENCE tag");
|
|
194
|
+
const totalLength = derSignature[1];
|
|
195
|
+
if (totalLength >= 0x80)
|
|
196
|
+
throw malformedDer("long-form length not supported");
|
|
197
|
+
if (totalLength !== derSignature.length - 2) {
|
|
198
|
+
throw malformedDer("SEQUENCE length does not span the buffer");
|
|
199
|
+
}
|
|
200
|
+
if (derSignature[2] !== 0x02)
|
|
201
|
+
throw malformedDer("missing INTEGER tag for r");
|
|
202
|
+
const rLength = derSignature[3];
|
|
203
|
+
// A P-256 integer is at most 32 bytes plus one 0x00 sign pad.
|
|
204
|
+
if (rLength < 1 || rLength > 33)
|
|
205
|
+
throw malformedDer("r length out of range");
|
|
206
|
+
if (4 + rLength + 2 > derSignature.length) {
|
|
207
|
+
throw malformedDer("r overruns the buffer");
|
|
208
|
+
}
|
|
209
|
+
const r = derSignature.subarray(4, 4 + rLength);
|
|
210
|
+
const sTagOffset = 4 + rLength;
|
|
211
|
+
if (derSignature[sTagOffset] !== 0x02) {
|
|
212
|
+
throw malformedDer("missing INTEGER tag for s");
|
|
213
|
+
}
|
|
214
|
+
const sLength = derSignature[sTagOffset + 1];
|
|
215
|
+
if (sLength < 1 || sLength > 33)
|
|
216
|
+
throw malformedDer("s length out of range");
|
|
217
|
+
if (sTagOffset + 2 + sLength !== derSignature.length) {
|
|
218
|
+
throw malformedDer("s does not end exactly at the buffer end");
|
|
219
|
+
}
|
|
220
|
+
const s = derSignature.subarray(sTagOffset + 2, sTagOffset + 2 + sLength);
|
|
221
|
+
const rBigInt = BigInt("0x" + r.toString("hex"));
|
|
222
|
+
let sBigInt = BigInt("0x" + s.toString("hex"));
|
|
223
|
+
// Scalars must be in [1, n-1] — anything else can never verify on-chain.
|
|
224
|
+
if (rBigInt < 1n || rBigInt >= SECP256R1_CURVE_ORDER) {
|
|
225
|
+
throw malformedDer("r out of curve order range");
|
|
226
|
+
}
|
|
227
|
+
if (sBigInt < 1n || sBigInt >= SECP256R1_CURVE_ORDER) {
|
|
228
|
+
throw malformedDer("s out of curve order range");
|
|
229
|
+
}
|
|
230
|
+
// Enforce low-S.
|
|
231
|
+
const halfN = SECP256R1_CURVE_ORDER / 2n;
|
|
232
|
+
if (sBigInt > halfN) {
|
|
233
|
+
sBigInt = SECP256R1_CURVE_ORDER - sBigInt;
|
|
234
|
+
}
|
|
235
|
+
const rPadded = Buffer.from(rBigInt.toString(16).padStart(64, "0"), "hex");
|
|
236
|
+
const sLowS = Buffer.from(sBigInt.toString(16).padStart(64, "0"), "hex");
|
|
237
|
+
return new Uint8Array(Buffer.concat([rPadded, sLowS]));
|
|
238
|
+
}
|
|
239
|
+
// ============================================================================
|
|
240
|
+
// WebAuthn challenge
|
|
241
|
+
// ============================================================================
|
|
242
|
+
/**
|
|
243
|
+
* Generate a cryptographically-random base64url challenge for a WebAuthn
|
|
244
|
+
* ceremony.
|
|
245
|
+
*
|
|
246
|
+
* Replaces the old hard-coded `"stellaristhebetterblockchain"` challenge.
|
|
247
|
+
*/
|
|
248
|
+
export function generateChallenge() {
|
|
249
|
+
const bytes = new Uint8Array(WEBAUTHN_CHALLENGE_SIZE);
|
|
250
|
+
crypto.getRandomValues(bytes);
|
|
251
|
+
return base64url.encode(Buffer.from(bytes));
|
|
252
|
+
}
|
|
253
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAElE,OAAO,SAAS,MAAM,gBAAgB,CAAC;AACvC,OAAO,EACL,yBAAyB,EACzB,qBAAqB,EACrB,qBAAqB,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rypto failures. The smart wallet imposes no signer-count caps
|
|
6
|
+
* (unlike a policy-based account), so validation here is about shapes and
|
|
7
|
+
* ranges: addresses, amounts, expirations, and secp256r1 public keys.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Validate that a string is a Stellar account (`G…`) or contract (`C…`) address.
|
|
13
|
+
*
|
|
14
|
+
* @throws {ValidationError} If the address is missing or malformed.
|
|
15
|
+
*/
|
|
16
|
+
export declare function validateAddress(address: string, fieldName?: string): void;
|
|
17
|
+
/**
|
|
18
|
+
* Validate that an amount is a positive, finite number.
|
|
19
|
+
*
|
|
20
|
+
* @throws {ValidationError} If the amount is not a positive number.
|
|
21
|
+
*/
|
|
22
|
+
export declare function validateAmount(amount: number, fieldName?: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* Validate a signer expiration.
|
|
25
|
+
*
|
|
26
|
+
* The contract types signer expiration as `Option<u64>` UNIX seconds, so the
|
|
27
|
+
* accepted range here is the `u64`-compatible safe-integer range: a
|
|
28
|
+
* non-negative integer up to `Number.MAX_SAFE_INTEGER` (the kit carries the
|
|
29
|
+
* value as a JS number before converting to `BigInt`). `undefined` means "no
|
|
30
|
+
* expiration". Capping at `u32` (the old bound) would reject post-2106
|
|
31
|
+
* timestamps the contract accepts.
|
|
32
|
+
*
|
|
33
|
+
* @throws {ValidationError} If the expiration is out of range.
|
|
34
|
+
*/
|
|
35
|
+
export declare function validateExpiration(expiration: number | undefined, fieldName?: string): void;
|
|
36
|
+
/**
|
|
37
|
+
* Validate a secp256r1 public key: 65 bytes, uncompressed (`0x04`) prefix.
|
|
38
|
+
*
|
|
39
|
+
* @throws {ValidationError} If the key is not a valid uncompressed EC point.
|
|
40
|
+
*/
|
|
41
|
+
export declare function validateSecp256r1PublicKey(publicKey: Uint8Array, fieldName?: string): void;
|
|
42
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AASH;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,EACf,SAAS,SAAY,GACpB,IAAI,CAmBN;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,SAAW,GAAG,IAAI,CAezE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,SAAS,SAAe,GACvB,IAAI,CAaN;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,UAAU,EACrB,SAAS,SAAc,GACtB,IAAI,CAeN"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side input validation.
|
|
3
|
+
*
|
|
4
|
+
* Produces clear {@link ValidationError}s before submission instead of opaque
|
|
5
|
+
* on-chain or WebCrypto failures. The smart wallet imposes no signer-count caps
|
|
6
|
+
* (unlike a policy-based account), so validation here is about shapes and
|
|
7
|
+
* ranges: addresses, amounts, expirations, and secp256r1 public keys.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
import { StrKey } from "@stellar/stellar-sdk";
|
|
12
|
+
import { SECP256R1_PUBLIC_KEY_SIZE, UNCOMPRESSED_PUBKEY_PREFIX, } from "./constants.js";
|
|
13
|
+
import { PasskeyKitErrorCode, ValidationError } from "./errors.js";
|
|
14
|
+
/**
|
|
15
|
+
* Validate that a string is a Stellar account (`G…`) or contract (`C…`) address.
|
|
16
|
+
*
|
|
17
|
+
* @throws {ValidationError} If the address is missing or malformed.
|
|
18
|
+
*/
|
|
19
|
+
export function validateAddress(address, fieldName = "address") {
|
|
20
|
+
if (!address || typeof address !== "string") {
|
|
21
|
+
throw new ValidationError(`${fieldName} is required`, PasskeyKitErrorCode.INVALID_ADDRESS, { field: fieldName });
|
|
22
|
+
}
|
|
23
|
+
if (!StrKey.isValidEd25519PublicKey(address) &&
|
|
24
|
+
!StrKey.isValidContract(address)) {
|
|
25
|
+
throw new ValidationError(`Invalid ${fieldName}: must be a valid Stellar account (G…) or contract (C…) address`, PasskeyKitErrorCode.INVALID_ADDRESS, { field: fieldName, value: address.slice(0, 10) + "…" });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Validate that an amount is a positive, finite number.
|
|
30
|
+
*
|
|
31
|
+
* @throws {ValidationError} If the amount is not a positive number.
|
|
32
|
+
*/
|
|
33
|
+
export function validateAmount(amount, fieldName = "amount") {
|
|
34
|
+
if (typeof amount !== "number" || !Number.isFinite(amount)) {
|
|
35
|
+
throw new ValidationError(`${fieldName} must be a number`, PasskeyKitErrorCode.INVALID_AMOUNT, { field: fieldName });
|
|
36
|
+
}
|
|
37
|
+
if (amount <= 0) {
|
|
38
|
+
throw new ValidationError(`${fieldName} must be positive`, PasskeyKitErrorCode.INVALID_AMOUNT, { field: fieldName, value: amount });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Validate a signer expiration.
|
|
43
|
+
*
|
|
44
|
+
* The contract types signer expiration as `Option<u64>` UNIX seconds, so the
|
|
45
|
+
* accepted range here is the `u64`-compatible safe-integer range: a
|
|
46
|
+
* non-negative integer up to `Number.MAX_SAFE_INTEGER` (the kit carries the
|
|
47
|
+
* value as a JS number before converting to `BigInt`). `undefined` means "no
|
|
48
|
+
* expiration". Capping at `u32` (the old bound) would reject post-2106
|
|
49
|
+
* timestamps the contract accepts.
|
|
50
|
+
*
|
|
51
|
+
* @throws {ValidationError} If the expiration is out of range.
|
|
52
|
+
*/
|
|
53
|
+
export function validateExpiration(expiration, fieldName = "expiration") {
|
|
54
|
+
if (expiration === undefined)
|
|
55
|
+
return;
|
|
56
|
+
if (!Number.isInteger(expiration) ||
|
|
57
|
+
expiration < 0 ||
|
|
58
|
+
expiration > Number.MAX_SAFE_INTEGER) {
|
|
59
|
+
throw new ValidationError(`${fieldName} must be a non-negative integer (u64 UNIX seconds, within JS safe-integer range)`, PasskeyKitErrorCode.INVALID_INPUT, { field: fieldName, value: expiration });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Validate a secp256r1 public key: 65 bytes, uncompressed (`0x04`) prefix.
|
|
64
|
+
*
|
|
65
|
+
* @throws {ValidationError} If the key is not a valid uncompressed EC point.
|
|
66
|
+
*/
|
|
67
|
+
export function validateSecp256r1PublicKey(publicKey, fieldName = "publicKey") {
|
|
68
|
+
if (publicKey.length !== SECP256R1_PUBLIC_KEY_SIZE) {
|
|
69
|
+
throw new ValidationError(`${fieldName} must be ${SECP256R1_PUBLIC_KEY_SIZE} bytes (got ${publicKey.length})`, PasskeyKitErrorCode.INVALID_PUBLIC_KEY, { field: fieldName, length: publicKey.length });
|
|
70
|
+
}
|
|
71
|
+
if (publicKey[0] !== UNCOMPRESSED_PUBKEY_PREFIX) {
|
|
72
|
+
throw new ValidationError(`${fieldName} must be an uncompressed EC point (0x04 prefix)`, PasskeyKitErrorCode.INVALID_PUBLIC_KEY, { field: fieldName, prefix: publicKey[0] });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EACL,yBAAyB,EACzB,0BAA0B,GAC3B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnE;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAC7B,OAAe,EACf,SAAS,GAAG,SAAS;IAErB,IAAI,CAAC,OA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QAC7B,UAAU,GAAG,CAAC;QACd,UAAU,GAAG,MAAM,CAAC,gBAAgB,EACpC,CAAC;QACD,MAAM,IAAI,eAAe,CACvB,GAAG,SAAS,kFAAkF,EAC9F,mBAAmB,CAAC,aAAa,EACjC,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,CACxC,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,0BAA0B,CACxC,SAAqB,EACrB,SAAS,GAAG,WAAW;IAEvB,IAAI,SAAS,CAAC,MAAM,KAAK,yBAAyB,EAAE,CAAC;QACnD,MAAM,IAAI,eAAe,CACvB,GAAG,SAAS,YAAY,yBAAyB,eAAe,SAAS,CAAC,MAAM,GAAG,EACnF,mBAAmB,CAAC,kBAAkB,EACtC,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,CAC/C,CAAC;IACJ,CAAC;IACD,IAAI,SAAS,CAAC,CAAC,CAAC,KAAK,0BAA0B,EAAE,CAAC;QAChD,MAAM,IAAI,eAAe,CACvB,GAAG,SAAS,iDAAiD,EAC7D,mBAAmB,CAAC,kBAAkB,EACtC,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,CAC3C,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,eAAO,MAAM,OAAO,WAAW,CAAC;AAChC,eAAO,MAAM,IAAI,gBAAgB,CAAC"}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package version — auto-generated from package.json.
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
// This file is auto-generated. Do not edit manually.
|
|
6
|
+
// Run `pnpm run sync-version` (or `pnpm build`) to update.
|
|
7
|
+
export const VERSION = "0.14.0";
|
|
8
|
+
export const NAME = "passkey-kit";
|
|
9
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,qDAAqD;AACrD,2DAA2D;AAE3D,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC;AAChC,MAAM,CAAC,MAAM,IAAI,GAAG,aAAa,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,30 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "passkey-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "A helper library for creating and using smart wallet accounts on the Stellar blockchain.",
|
|
5
|
-
"author": "Tyler van der Hoeven",
|
|
5
|
+
"author": "Tyler van der Hoeven <tyler@stellar.org>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"main": "
|
|
9
|
-
"
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"module": "dist/index.js",
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"./storage": {
|
|
18
|
+
"import": "./dist/storage/index.js",
|
|
19
|
+
"types": "./dist/storage/index.d.ts"
|
|
20
|
+
},
|
|
21
|
+
"./server": {
|
|
22
|
+
"import": "./dist/server.js",
|
|
23
|
+
"types": "./dist/server.d.ts"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"README.md",
|
|
29
|
+
"LICENCE"
|
|
30
|
+
],
|
|
10
31
|
"dependencies": {
|
|
11
|
-
"@openzeppelin/relayer-plugin-channels": "^0.
|
|
12
|
-
"@simplewebauthn/browser": "^13.
|
|
13
|
-
"@stellar/stellar-sdk": "16.0.
|
|
32
|
+
"@openzeppelin/relayer-plugin-channels": "^0.20.0",
|
|
33
|
+
"@simplewebauthn/browser": "^13.3.0",
|
|
34
|
+
"@stellar/stellar-sdk": "16.0.1",
|
|
14
35
|
"base64url": "^3.0.1",
|
|
15
36
|
"buffer": "^6.0.3",
|
|
16
|
-
"
|
|
17
|
-
"
|
|
37
|
+
"sac-sdk": "0.4.3",
|
|
38
|
+
"passkey-kit-sdk": "0.8.0"
|
|
18
39
|
},
|
|
19
40
|
"devDependencies": {
|
|
20
41
|
"@types/node": "^24.6.0",
|
|
21
|
-
"
|
|
42
|
+
"fake-indexeddb": "^6.2.5",
|
|
43
|
+
"typescript": "^5.9.2",
|
|
44
|
+
"vitest": "^3.2.4"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@stellar/stellar-sdk": ">=16.0.0"
|
|
22
48
|
},
|
|
23
|
-
"workspaces": [
|
|
24
|
-
"packages/*"
|
|
25
|
-
],
|
|
26
49
|
"engines": {
|
|
27
|
-
"node": ">=22.
|
|
50
|
+
"node": ">=22.0.0"
|
|
28
51
|
},
|
|
29
52
|
"repository": {
|
|
30
53
|
"type": "git",
|
|
@@ -48,13 +71,17 @@
|
|
|
48
71
|
},
|
|
49
72
|
"homepage": "https://github.com/kalepail/passkey-kit/blob/main/README.md",
|
|
50
73
|
"scripts": {
|
|
74
|
+
"sync-version": "node scripts/sync-version.js",
|
|
75
|
+
"prebuild": "node scripts/sync-version.js",
|
|
76
|
+
"build:bindings": "pnpm --filter sac-sdk run build && pnpm --filter passkey-kit-sdk run build",
|
|
77
|
+
"bindings:regen": "bash scripts/bindings/build.sh",
|
|
78
|
+
"verify:bindings": "bash scripts/bindings/verify.sh",
|
|
79
|
+
"build": "pnpm run build:bindings && tsc && node scripts/verify-esm.mjs",
|
|
80
|
+
"verify:esm": "node scripts/verify-esm.mjs",
|
|
81
|
+
"test": "vitest",
|
|
82
|
+
"clean": "rm -rf dist packages/passkey-kit-sdk/dist packages/sac-sdk/dist",
|
|
51
83
|
"build:demo": "cd demo && pnpm --ignore-workspace install && pnpm run build",
|
|
52
84
|
"deploy:demo": "npx wrangler pages deploy",
|
|
53
|
-
"deploy:demo:prod": "npx wrangler pages deploy --
|
|
54
|
-
"test:p27-auth": "bun bun_tests/9.index.ts",
|
|
55
|
-
"build:sac": "pnpm --filter=sac-sdk run build",
|
|
56
|
-
"build:pks": "pnpm --filter=passkey-kit-sdk run build",
|
|
57
|
-
"build": "pnpm run build:sac && pnpm run build:pks && tsc",
|
|
58
|
-
"ext:cp": "./clone-js-sdk.sh"
|
|
85
|
+
"deploy:demo:prod": "npx wrangler pages deploy --branch production"
|
|
59
86
|
}
|
|
60
87
|
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"permissions": {
|
|
3
|
-
"allow": [
|
|
4
|
-
"WebSearch",
|
|
5
|
-
"mcp__context7__resolve-library-id",
|
|
6
|
-
"Bash(tree:*)",
|
|
7
|
-
"mcp__deepwiki__read_wiki_structure",
|
|
8
|
-
"mcp__context7__query-docs",
|
|
9
|
-
"mcp__deepwiki__read_wiki_contents",
|
|
10
|
-
"Bash(curl:*)",
|
|
11
|
-
"Bash(pnpm install:*)",
|
|
12
|
-
"Bash(pnpm run build:*)",
|
|
13
|
-
"mcp__github__get_file_contents",
|
|
14
|
-
"mcp__perplexity__perplexity_ask",
|
|
15
|
-
"mcp__perplexity__perplexity_search"
|
|
16
|
-
],
|
|
17
|
-
"deny": [],
|
|
18
|
-
"ask": []
|
|
19
|
-
}
|
|
20
|
-
}
|