@veridex/sdk 1.0.0-beta.22 → 1.0.0-beta.23
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/EVMClient-CoOR_ywD.d.mts +332 -0
- package/dist/auth/prepareAuth.d.mts +1 -1
- package/dist/auth/prepareAuth.js +749 -3
- package/dist/auth/prepareAuth.js.map +1 -1
- package/dist/auth/prepareAuth.mjs +25 -1404
- package/dist/auth/prepareAuth.mjs.map +1 -1
- package/dist/chains/aptos/index.d.mts +1 -1
- package/dist/chains/aptos/index.mjs +5 -574
- package/dist/chains/aptos/index.mjs.map +1 -1
- package/dist/chains/avalanche/index.d.mts +137 -0
- package/dist/chains/avalanche/index.js +1407 -0
- package/dist/chains/avalanche/index.js.map +1 -0
- package/dist/chains/avalanche/index.mjs +10 -0
- package/dist/chains/avalanche/index.mjs.map +1 -0
- package/dist/chains/evm/index.d.mts +4 -2
- package/dist/chains/evm/index.mjs +8 -1200
- package/dist/chains/evm/index.mjs.map +1 -1
- package/dist/chains/solana/index.d.mts +1 -1
- package/dist/chains/solana/index.mjs +4 -486
- package/dist/chains/solana/index.mjs.map +1 -1
- package/dist/chains/stacks/index.d.mts +1 -1
- package/dist/chains/stacks/index.mjs +36 -1114
- package/dist/chains/stacks/index.mjs.map +1 -1
- package/dist/chains/starknet/index.d.mts +1 -1
- package/dist/chains/starknet/index.mjs +5 -503
- package/dist/chains/starknet/index.mjs.map +1 -1
- package/dist/chains/sui/index.d.mts +1 -1
- package/dist/chains/sui/index.mjs +5 -529
- package/dist/chains/sui/index.mjs.map +1 -1
- package/dist/chunk-3Q34PMHU.mjs +840 -0
- package/dist/chunk-3Q34PMHU.mjs.map +1 -0
- package/dist/chunk-72ZA3OYQ.mjs +20 -0
- package/dist/chunk-72ZA3OYQ.mjs.map +1 -0
- package/dist/chunk-7IEUU6LD.mjs +549 -0
- package/dist/chunk-7IEUU6LD.mjs.map +1 -0
- package/dist/chunk-ABLEEC5N.mjs +38 -0
- package/dist/chunk-ABLEEC5N.mjs.map +1 -0
- package/dist/chunk-AORSW75A.mjs +1101 -0
- package/dist/chunk-AORSW75A.mjs.map +1 -0
- package/dist/chunk-BKTCPT7P.mjs +269 -0
- package/dist/chunk-BKTCPT7P.mjs.map +1 -0
- package/dist/chunk-CCHASDAI.mjs +330 -0
- package/dist/chunk-CCHASDAI.mjs.map +1 -0
- package/dist/chunk-FQ2WU7PX.mjs +509 -0
- package/dist/chunk-FQ2WU7PX.mjs.map +1 -0
- package/dist/chunk-JO74ENTF.mjs +417 -0
- package/dist/chunk-JO74ENTF.mjs.map +1 -0
- package/dist/chunk-K73Y36KS.mjs +407 -0
- package/dist/chunk-K73Y36KS.mjs.map +1 -0
- package/dist/chunk-KHV3EP3I.mjs +179 -0
- package/dist/chunk-KHV3EP3I.mjs.map +1 -0
- package/dist/chunk-MMSTOW4F.mjs +722 -0
- package/dist/chunk-MMSTOW4F.mjs.map +1 -0
- package/dist/chunk-MWZ5UHCF.mjs +1082 -0
- package/dist/chunk-MWZ5UHCF.mjs.map +1 -0
- package/dist/chunk-NU6JGI7L.mjs +565 -0
- package/dist/chunk-NU6JGI7L.mjs.map +1 -0
- package/dist/chunk-PIC2Y5DF.mjs +422 -0
- package/dist/chunk-PIC2Y5DF.mjs.map +1 -0
- package/dist/chunk-PPN7BG3A.mjs +464 -0
- package/dist/chunk-PPN7BG3A.mjs.map +1 -0
- package/dist/chunk-RSV7J43V.mjs +438 -0
- package/dist/chunk-RSV7J43V.mjs.map +1 -0
- package/dist/chunk-UTT6KI7N.mjs +216 -0
- package/dist/chunk-UTT6KI7N.mjs.map +1 -0
- package/dist/constants.mjs +16 -389
- package/dist/constants.mjs.map +1 -1
- package/dist/index-Du1PoZqu.d.mts +216 -0
- package/dist/index.d.mts +131 -9
- package/dist/index.js +12064 -11594
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4407 -12273
- package/dist/index.mjs.map +1 -1
- package/dist/passkey.d.mts +142 -0
- package/dist/passkey.js +807 -0
- package/dist/passkey.js.map +1 -0
- package/dist/passkey.mjs +15 -0
- package/dist/passkey.mjs.map +1 -0
- package/dist/payload.mjs +25 -244
- package/dist/payload.mjs.map +1 -1
- package/dist/portfolio-UV3LLWKI.mjs +13 -0
- package/dist/portfolio-UV3LLWKI.mjs.map +1 -0
- package/dist/queries/index.js +39 -1
- package/dist/queries/index.js.map +1 -1
- package/dist/queries/index.mjs +14 -1591
- package/dist/queries/index.mjs.map +1 -1
- package/dist/{types-DakHNZIP.d.ts → types-Bmk689Lw.d.mts} +1 -1
- package/dist/types.d.mts +10 -0
- package/dist/types.js.map +1 -1
- package/dist/utils.mjs +19 -385
- package/dist/utils.mjs.map +1 -1
- package/dist/wormhole.mjs +25 -397
- package/dist/wormhole.mjs.map +1 -1
- package/package.json +11 -1
- package/dist/auth/prepareAuth.d.ts +0 -25
- package/dist/chains/aptos/index.d.ts +0 -146
- package/dist/chains/evm/index.d.ts +0 -5
- package/dist/chains/solana/index.d.ts +0 -116
- package/dist/chains/stacks/index.d.ts +0 -559
- package/dist/chains/starknet/index.d.ts +0 -172
- package/dist/chains/sui/index.d.ts +0 -182
- package/dist/constants.d.ts +0 -150
- package/dist/index-Dy29mvBf.d.mts +0 -683
- package/dist/index-eXXqodd0.d.ts +0 -683
- package/dist/index.d.ts +0 -3442
- package/dist/payload.d.ts +0 -125
- package/dist/queries/index.d.ts +0 -148
- package/dist/types-DakHNZIP.d.mts +0 -571
- package/dist/types-DvFRnIBd.d.ts +0 -172
- package/dist/types.d.ts +0 -413
- package/dist/utils.d.ts +0 -81
- package/dist/wormhole.d.ts +0 -167
package/dist/passkey.js
ADDED
|
@@ -0,0 +1,807 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/passkey.ts
|
|
21
|
+
var passkey_exports = {};
|
|
22
|
+
__export(passkey_exports, {
|
|
23
|
+
PasskeyManager: () => PasskeyManager,
|
|
24
|
+
VERIDEX_RP_ID: () => VERIDEX_RP_ID,
|
|
25
|
+
detectRpId: () => detectRpId,
|
|
26
|
+
supportsRelatedOrigins: () => supportsRelatedOrigins
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(passkey_exports);
|
|
29
|
+
|
|
30
|
+
// src/core/PasskeyManager.ts
|
|
31
|
+
var import_browser = require("@simplewebauthn/browser");
|
|
32
|
+
var import_ethers2 = require("ethers");
|
|
33
|
+
|
|
34
|
+
// src/utils.ts
|
|
35
|
+
var import_ethers = require("ethers");
|
|
36
|
+
function base64URLEncode(buffer) {
|
|
37
|
+
const bytes = Array.from(buffer);
|
|
38
|
+
const binary = String.fromCharCode(...bytes);
|
|
39
|
+
const base64 = btoa(binary);
|
|
40
|
+
return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
41
|
+
}
|
|
42
|
+
function base64URLDecode(str) {
|
|
43
|
+
const base64 = str.replace(/-/g, "+").replace(/_/g, "/");
|
|
44
|
+
const padded = base64 + "=".repeat((4 - base64.length % 4) % 4);
|
|
45
|
+
const binary = atob(padded);
|
|
46
|
+
const bytes = new Uint8Array(binary.length);
|
|
47
|
+
for (let i = 0; i < binary.length; i++) {
|
|
48
|
+
bytes[i] = binary.charCodeAt(i);
|
|
49
|
+
}
|
|
50
|
+
return bytes;
|
|
51
|
+
}
|
|
52
|
+
function parseDERSignature(signature) {
|
|
53
|
+
let offset = 0;
|
|
54
|
+
if (signature[offset++] !== 48) {
|
|
55
|
+
throw new Error("Invalid signature format");
|
|
56
|
+
}
|
|
57
|
+
offset++;
|
|
58
|
+
if (signature[offset++] !== 2) {
|
|
59
|
+
throw new Error("Invalid signature format");
|
|
60
|
+
}
|
|
61
|
+
const rLength = signature[offset++];
|
|
62
|
+
if (rLength === void 0) {
|
|
63
|
+
throw new Error("Invalid signature format: missing r length");
|
|
64
|
+
}
|
|
65
|
+
let r = signature.slice(offset, offset + rLength);
|
|
66
|
+
offset += rLength;
|
|
67
|
+
if (r[0] === 0 && r.length > 32) {
|
|
68
|
+
r = r.slice(1);
|
|
69
|
+
}
|
|
70
|
+
if (r.length < 32) {
|
|
71
|
+
const padded = new Uint8Array(32);
|
|
72
|
+
padded.set(r, 32 - r.length);
|
|
73
|
+
r = padded;
|
|
74
|
+
}
|
|
75
|
+
if (signature[offset++] !== 2) {
|
|
76
|
+
throw new Error("Invalid signature format");
|
|
77
|
+
}
|
|
78
|
+
const sLength = signature[offset++];
|
|
79
|
+
if (sLength === void 0) {
|
|
80
|
+
throw new Error("Invalid signature format: missing s length");
|
|
81
|
+
}
|
|
82
|
+
let s = signature.slice(offset, offset + sLength);
|
|
83
|
+
if (s[0] === 0 && s.length > 32) {
|
|
84
|
+
s = s.slice(1);
|
|
85
|
+
}
|
|
86
|
+
if (s.length < 32) {
|
|
87
|
+
const padded = new Uint8Array(32);
|
|
88
|
+
padded.set(s, 32 - s.length);
|
|
89
|
+
s = padded;
|
|
90
|
+
}
|
|
91
|
+
return { r, s };
|
|
92
|
+
}
|
|
93
|
+
function computeKeyHash(publicKeyX, publicKeyY) {
|
|
94
|
+
return import_ethers.ethers.keccak256(
|
|
95
|
+
import_ethers.ethers.solidityPacked(["uint256", "uint256"], [publicKeyX, publicKeyY])
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// src/core/PasskeyManager.ts
|
|
100
|
+
var VERIDEX_RP_ID = "veridex.network";
|
|
101
|
+
function detectRpId(forceLocal) {
|
|
102
|
+
if (typeof window === "undefined") return "localhost";
|
|
103
|
+
const hostname = window.location.hostname;
|
|
104
|
+
if (hostname === "localhost" || hostname === "127.0.0.1" || /^\d+\.\d+\.\d+\.\d+$/.test(hostname)) {
|
|
105
|
+
return hostname;
|
|
106
|
+
}
|
|
107
|
+
if (forceLocal) {
|
|
108
|
+
const parts = hostname.split(".");
|
|
109
|
+
if (parts.length <= 2) {
|
|
110
|
+
return hostname;
|
|
111
|
+
}
|
|
112
|
+
return parts.slice(-2).join(".");
|
|
113
|
+
}
|
|
114
|
+
return VERIDEX_RP_ID;
|
|
115
|
+
}
|
|
116
|
+
async function supportsRelatedOrigins() {
|
|
117
|
+
if (typeof window === "undefined" || !window.PublicKeyCredential) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
if ("getClientCapabilities" in PublicKeyCredential) {
|
|
121
|
+
try {
|
|
122
|
+
const getCapabilities = PublicKeyCredential.getClientCapabilities;
|
|
123
|
+
const capabilities = await getCapabilities();
|
|
124
|
+
return capabilities?.relatedOrigins === true;
|
|
125
|
+
} catch {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
var PasskeyManager = class _PasskeyManager {
|
|
132
|
+
config;
|
|
133
|
+
credential = null;
|
|
134
|
+
constructor(config = {}) {
|
|
135
|
+
this.config = {
|
|
136
|
+
rpName: config.rpName ?? "Veridex Protocol",
|
|
137
|
+
rpId: config.rpId ?? detectRpId(),
|
|
138
|
+
timeout: config.timeout ?? 6e4,
|
|
139
|
+
userVerification: config.userVerification ?? "required",
|
|
140
|
+
authenticatorAttachment: config.authenticatorAttachment ?? "platform",
|
|
141
|
+
relayerUrl: config.relayerUrl ?? ""
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
static isSupported() {
|
|
145
|
+
return (0, import_browser.browserSupportsWebAuthn)();
|
|
146
|
+
}
|
|
147
|
+
static async isPlatformAuthenticatorAvailable() {
|
|
148
|
+
if (typeof window === "undefined" || !window.PublicKeyCredential) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
return await window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable();
|
|
152
|
+
}
|
|
153
|
+
async register(username, displayName) {
|
|
154
|
+
if (!_PasskeyManager.isSupported()) {
|
|
155
|
+
throw new Error("WebAuthn is not supported in this browser");
|
|
156
|
+
}
|
|
157
|
+
const challenge = import_ethers2.ethers.randomBytes(32);
|
|
158
|
+
const challengeBase64 = base64URLEncode(challenge);
|
|
159
|
+
const options = {
|
|
160
|
+
challenge: challengeBase64,
|
|
161
|
+
rp: {
|
|
162
|
+
name: this.config.rpName,
|
|
163
|
+
id: this.config.rpId
|
|
164
|
+
},
|
|
165
|
+
user: {
|
|
166
|
+
id: base64URLEncode(import_ethers2.ethers.toUtf8Bytes(username)),
|
|
167
|
+
name: username,
|
|
168
|
+
displayName
|
|
169
|
+
},
|
|
170
|
+
pubKeyCredParams: [
|
|
171
|
+
{ alg: -7, type: "public-key" },
|
|
172
|
+
// ES256 (P-256) - WebAuthn default
|
|
173
|
+
{ alg: -257, type: "public-key" },
|
|
174
|
+
// RS256 - Widely supported
|
|
175
|
+
{ alg: -8, type: "public-key" },
|
|
176
|
+
// EdDSA - Modern, efficient
|
|
177
|
+
{ alg: -35, type: "public-key" },
|
|
178
|
+
// ES384 (P-384)
|
|
179
|
+
{ alg: -36, type: "public-key" },
|
|
180
|
+
// ES512 (P-521)
|
|
181
|
+
{ alg: -37, type: "public-key" }
|
|
182
|
+
// PS256 - RSA PSS
|
|
183
|
+
],
|
|
184
|
+
authenticatorSelection: {
|
|
185
|
+
authenticatorAttachment: this.config.authenticatorAttachment,
|
|
186
|
+
userVerification: this.config.userVerification,
|
|
187
|
+
residentKey: "required",
|
|
188
|
+
requireResidentKey: true
|
|
189
|
+
},
|
|
190
|
+
timeout: this.config.timeout,
|
|
191
|
+
attestation: "none"
|
|
192
|
+
};
|
|
193
|
+
const response = await (0, import_browser.startRegistration)(options);
|
|
194
|
+
const publicKey = this.extractPublicKeyFromAttestation(response);
|
|
195
|
+
const keyHash = computeKeyHash(publicKey.x, publicKey.y);
|
|
196
|
+
this.credential = {
|
|
197
|
+
credentialId: response.id,
|
|
198
|
+
publicKeyX: publicKey.x,
|
|
199
|
+
publicKeyY: publicKey.y,
|
|
200
|
+
keyHash
|
|
201
|
+
};
|
|
202
|
+
return this.credential;
|
|
203
|
+
}
|
|
204
|
+
async sign(challenge) {
|
|
205
|
+
if (!this.credential) {
|
|
206
|
+
throw new Error("No credential set. Call register() or setCredential() first.");
|
|
207
|
+
}
|
|
208
|
+
const challengeBase64 = base64URLEncode(challenge);
|
|
209
|
+
const options = {
|
|
210
|
+
challenge: challengeBase64,
|
|
211
|
+
rpId: this.config.rpId,
|
|
212
|
+
allowCredentials: [
|
|
213
|
+
{
|
|
214
|
+
id: this.credential.credentialId,
|
|
215
|
+
type: "public-key",
|
|
216
|
+
transports: ["internal"]
|
|
217
|
+
}
|
|
218
|
+
],
|
|
219
|
+
userVerification: this.config.userVerification,
|
|
220
|
+
timeout: this.config.timeout
|
|
221
|
+
};
|
|
222
|
+
const response = await (0, import_browser.startAuthentication)(options);
|
|
223
|
+
return this.parseAuthenticationResponse(response);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Authenticate using a discoverable credential (passkey)
|
|
227
|
+
* This allows sign-in without knowing the credential ID ahead of time.
|
|
228
|
+
* The authenticator will show all available passkeys for this RP.
|
|
229
|
+
*
|
|
230
|
+
* @param challenge - Optional challenge bytes. If not provided, a random challenge is used.
|
|
231
|
+
* @returns The credential that was used to authenticate, along with the signature
|
|
232
|
+
*/
|
|
233
|
+
async authenticate(challenge) {
|
|
234
|
+
if (!_PasskeyManager.isSupported()) {
|
|
235
|
+
throw new Error("WebAuthn is not supported in this browser");
|
|
236
|
+
}
|
|
237
|
+
const actualChallenge = challenge ?? import_ethers2.ethers.randomBytes(32);
|
|
238
|
+
const challengeBase64 = base64URLEncode(actualChallenge);
|
|
239
|
+
const options = {
|
|
240
|
+
challenge: challengeBase64,
|
|
241
|
+
rpId: this.config.rpId,
|
|
242
|
+
userVerification: this.config.userVerification,
|
|
243
|
+
timeout: this.config.timeout
|
|
244
|
+
};
|
|
245
|
+
const response = await (0, import_browser.startAuthentication)(options);
|
|
246
|
+
const credentialId = response.id;
|
|
247
|
+
const signature = this.parseAuthenticationResponse(response);
|
|
248
|
+
let storedCredential = this.findCredentialById(credentialId);
|
|
249
|
+
if (storedCredential) {
|
|
250
|
+
this.credential = storedCredential;
|
|
251
|
+
return { credential: storedCredential, signature };
|
|
252
|
+
}
|
|
253
|
+
if (this.config.relayerUrl) {
|
|
254
|
+
storedCredential = await this.loadCredentialFromRelayer(credentialId);
|
|
255
|
+
if (storedCredential) {
|
|
256
|
+
this.credential = storedCredential;
|
|
257
|
+
this.addCredentialToStorage(storedCredential);
|
|
258
|
+
return { credential: storedCredential, signature };
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
const hasRelayer = !!this.config.relayerUrl;
|
|
262
|
+
throw new Error(
|
|
263
|
+
"Credential not found. This passkey was registered on a different device or the data was cleared. " + (hasRelayer ? "The credential was not found. Please register a new passkey." : "Please register a new passkey or ensure the relayer URL is configured.")
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Find a credential by ID in the list of stored credentials
|
|
268
|
+
*/
|
|
269
|
+
findCredentialById(credentialId) {
|
|
270
|
+
if (typeof window === "undefined") return null;
|
|
271
|
+
const stored = this.getAllStoredCredentials();
|
|
272
|
+
return stored.find((c) => c.credentialId === credentialId) || null;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Get all credentials stored in localStorage
|
|
276
|
+
*/
|
|
277
|
+
getAllStoredCredentials(key = "veridex_credentials") {
|
|
278
|
+
if (typeof window === "undefined") return [];
|
|
279
|
+
const stored = localStorage.getItem(key);
|
|
280
|
+
if (!stored) {
|
|
281
|
+
const legacy = localStorage.getItem("veridex_credential");
|
|
282
|
+
if (legacy) {
|
|
283
|
+
try {
|
|
284
|
+
const data = JSON.parse(legacy);
|
|
285
|
+
const cred = this.parseStoredCredential(data);
|
|
286
|
+
if (cred) {
|
|
287
|
+
this.saveCredentials([cred], key);
|
|
288
|
+
localStorage.removeItem("veridex_credential");
|
|
289
|
+
return [cred];
|
|
290
|
+
}
|
|
291
|
+
} catch (e) {
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return [];
|
|
295
|
+
}
|
|
296
|
+
try {
|
|
297
|
+
const data = JSON.parse(stored);
|
|
298
|
+
if (Array.isArray(data)) {
|
|
299
|
+
return data.map((item) => this.parseStoredCredential(item)).filter((c) => c !== null);
|
|
300
|
+
}
|
|
301
|
+
return [];
|
|
302
|
+
} catch (error) {
|
|
303
|
+
console.error("Failed to load credentials:", error);
|
|
304
|
+
return [];
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
parseStoredCredential(data) {
|
|
308
|
+
try {
|
|
309
|
+
return {
|
|
310
|
+
credentialId: data.credentialId,
|
|
311
|
+
publicKeyX: BigInt(data.publicKeyX),
|
|
312
|
+
publicKeyY: BigInt(data.publicKeyY),
|
|
313
|
+
keyHash: data.keyHash
|
|
314
|
+
};
|
|
315
|
+
} catch {
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Save a list of credentials to localStorage
|
|
321
|
+
*/
|
|
322
|
+
saveCredentials(credentials, key = "veridex_credentials") {
|
|
323
|
+
if (typeof window === "undefined") return;
|
|
324
|
+
const data = credentials.map((c) => ({
|
|
325
|
+
credentialId: c.credentialId,
|
|
326
|
+
publicKeyX: c.publicKeyX.toString(),
|
|
327
|
+
publicKeyY: c.publicKeyY.toString(),
|
|
328
|
+
keyHash: c.keyHash
|
|
329
|
+
}));
|
|
330
|
+
localStorage.setItem(key, JSON.stringify(data));
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Add a single credential to storage (append or update)
|
|
334
|
+
*/
|
|
335
|
+
addCredentialToStorage(credential, key = "veridex_credentials") {
|
|
336
|
+
const stored = this.getAllStoredCredentials(key);
|
|
337
|
+
const existingIndex = stored.findIndex((c) => c.credentialId === credential.credentialId);
|
|
338
|
+
if (existingIndex >= 0) {
|
|
339
|
+
stored[existingIndex] = credential;
|
|
340
|
+
} else {
|
|
341
|
+
stored.push(credential);
|
|
342
|
+
}
|
|
343
|
+
this.saveCredentials(stored, key);
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Check if there's ANY stored credential for this RP
|
|
347
|
+
*/
|
|
348
|
+
hasStoredCredential() {
|
|
349
|
+
return this.getAllStoredCredentials().length > 0;
|
|
350
|
+
}
|
|
351
|
+
getCredential() {
|
|
352
|
+
return this.credential;
|
|
353
|
+
}
|
|
354
|
+
setCredential(credential) {
|
|
355
|
+
this.credential = credential;
|
|
356
|
+
}
|
|
357
|
+
createCredentialFromPublicKey(credentialId, publicKeyX, publicKeyY) {
|
|
358
|
+
const keyHash = computeKeyHash(publicKeyX, publicKeyY);
|
|
359
|
+
this.credential = {
|
|
360
|
+
credentialId,
|
|
361
|
+
publicKeyX,
|
|
362
|
+
publicKeyY,
|
|
363
|
+
keyHash
|
|
364
|
+
};
|
|
365
|
+
return this.credential;
|
|
366
|
+
}
|
|
367
|
+
clearCredential() {
|
|
368
|
+
this.credential = null;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Save the current credential to localStorage (appends to list)
|
|
372
|
+
*/
|
|
373
|
+
saveToLocalStorage(key = "veridex_credentials") {
|
|
374
|
+
if (!this.credential) {
|
|
375
|
+
throw new Error("No credential to save");
|
|
376
|
+
}
|
|
377
|
+
this.addCredentialToStorage(this.credential, key);
|
|
378
|
+
}
|
|
379
|
+
loadFromLocalStorage(key = "veridex_credentials") {
|
|
380
|
+
if (typeof window === "undefined") {
|
|
381
|
+
return null;
|
|
382
|
+
}
|
|
383
|
+
const stored = this.getAllStoredCredentials(key);
|
|
384
|
+
if (stored.length > 0) {
|
|
385
|
+
this.credential = stored[stored.length - 1];
|
|
386
|
+
return this.credential;
|
|
387
|
+
}
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
390
|
+
removeFromLocalStorage(key = "veridex_credentials") {
|
|
391
|
+
if (typeof window !== "undefined") {
|
|
392
|
+
localStorage.removeItem(key);
|
|
393
|
+
localStorage.removeItem("veridex_credential");
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
// =========================================================================
|
|
397
|
+
// Relayer-based Credential Storage (Cross-Device Recovery)
|
|
398
|
+
// =========================================================================
|
|
399
|
+
/**
|
|
400
|
+
* Save the current credential to the relayer for cross-device recovery.
|
|
401
|
+
* This should be called after registration.
|
|
402
|
+
*/
|
|
403
|
+
async saveCredentialToRelayer() {
|
|
404
|
+
if (!this.credential) {
|
|
405
|
+
throw new Error("No credential to save");
|
|
406
|
+
}
|
|
407
|
+
if (!this.config.relayerUrl) {
|
|
408
|
+
console.warn("Relayer URL not configured; skipping remote credential storage");
|
|
409
|
+
return false;
|
|
410
|
+
}
|
|
411
|
+
try {
|
|
412
|
+
const response = await fetch(`${this.config.relayerUrl}/api/v1/credential`, {
|
|
413
|
+
method: "POST",
|
|
414
|
+
headers: { "Content-Type": "application/json" },
|
|
415
|
+
body: JSON.stringify({
|
|
416
|
+
keyHash: this.credential.keyHash,
|
|
417
|
+
credentialId: this.credential.credentialId,
|
|
418
|
+
publicKeyX: this.credential.publicKeyX.toString(),
|
|
419
|
+
publicKeyY: this.credential.publicKeyY.toString()
|
|
420
|
+
})
|
|
421
|
+
});
|
|
422
|
+
if (!response.ok) {
|
|
423
|
+
const errorData = await response.json().catch(() => ({}));
|
|
424
|
+
console.error("Failed to save credential to relayer:", errorData);
|
|
425
|
+
return false;
|
|
426
|
+
}
|
|
427
|
+
console.log("Credential saved to relayer for cross-device recovery");
|
|
428
|
+
return true;
|
|
429
|
+
} catch (error) {
|
|
430
|
+
console.error("Failed to save credential to relayer:", error);
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Load a credential from the relayer by credential ID.
|
|
436
|
+
* Used during discoverable credential authentication when localStorage is empty.
|
|
437
|
+
*/
|
|
438
|
+
async loadCredentialFromRelayer(credentialId) {
|
|
439
|
+
if (!this.config.relayerUrl) {
|
|
440
|
+
return null;
|
|
441
|
+
}
|
|
442
|
+
try {
|
|
443
|
+
const response = await fetch(
|
|
444
|
+
`${this.config.relayerUrl}/api/v1/credential/by-id/${encodeURIComponent(credentialId)}`
|
|
445
|
+
);
|
|
446
|
+
if (!response.ok) {
|
|
447
|
+
return null;
|
|
448
|
+
}
|
|
449
|
+
const data = await response.json();
|
|
450
|
+
if (!data.exists) {
|
|
451
|
+
return null;
|
|
452
|
+
}
|
|
453
|
+
if (!data.credentialId || !data.publicKeyX || !data.publicKeyY || !data.keyHash) {
|
|
454
|
+
console.warn("Relayer returned incomplete credential data:", {
|
|
455
|
+
hasCredentialId: !!data.credentialId,
|
|
456
|
+
hasPublicKeyX: !!data.publicKeyX,
|
|
457
|
+
hasPublicKeyY: !!data.publicKeyY,
|
|
458
|
+
hasKeyHash: !!data.keyHash
|
|
459
|
+
});
|
|
460
|
+
return null;
|
|
461
|
+
}
|
|
462
|
+
return {
|
|
463
|
+
credentialId: data.credentialId,
|
|
464
|
+
publicKeyX: BigInt(data.publicKeyX),
|
|
465
|
+
publicKeyY: BigInt(data.publicKeyY),
|
|
466
|
+
keyHash: data.keyHash
|
|
467
|
+
};
|
|
468
|
+
} catch (error) {
|
|
469
|
+
console.error("Failed to load credential from relayer:", error);
|
|
470
|
+
return null;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Load a credential from the relayer by keyHash.
|
|
475
|
+
* Useful when you know the user's keyHash but not their credential ID.
|
|
476
|
+
*/
|
|
477
|
+
async loadCredentialFromRelayerByKeyHash(keyHash) {
|
|
478
|
+
if (!this.config.relayerUrl) {
|
|
479
|
+
return null;
|
|
480
|
+
}
|
|
481
|
+
try {
|
|
482
|
+
const response = await fetch(
|
|
483
|
+
`${this.config.relayerUrl}/api/v1/credential/${encodeURIComponent(keyHash)}`
|
|
484
|
+
);
|
|
485
|
+
if (!response.ok) {
|
|
486
|
+
return null;
|
|
487
|
+
}
|
|
488
|
+
const data = await response.json();
|
|
489
|
+
if (!data.exists) {
|
|
490
|
+
return null;
|
|
491
|
+
}
|
|
492
|
+
if (!data.credentialId || !data.publicKeyX || !data.publicKeyY || !data.keyHash) {
|
|
493
|
+
console.warn("Relayer returned incomplete credential data for keyHash:", {
|
|
494
|
+
hasCredentialId: !!data.credentialId,
|
|
495
|
+
hasPublicKeyX: !!data.publicKeyX,
|
|
496
|
+
hasPublicKeyY: !!data.publicKeyY,
|
|
497
|
+
hasKeyHash: !!data.keyHash
|
|
498
|
+
});
|
|
499
|
+
return null;
|
|
500
|
+
}
|
|
501
|
+
return {
|
|
502
|
+
credentialId: data.credentialId,
|
|
503
|
+
publicKeyX: BigInt(data.publicKeyX),
|
|
504
|
+
publicKeyY: BigInt(data.publicKeyY),
|
|
505
|
+
keyHash: data.keyHash
|
|
506
|
+
};
|
|
507
|
+
} catch (error) {
|
|
508
|
+
console.error("Failed to load credential from relayer:", error);
|
|
509
|
+
return null;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
extractPublicKeyFromAttestation(response) {
|
|
513
|
+
const attestationObject = base64URLDecode(response.response.attestationObject);
|
|
514
|
+
let offset = 0;
|
|
515
|
+
if (attestationObject[offset] >= 160 && attestationObject[offset] <= 191) {
|
|
516
|
+
offset++;
|
|
517
|
+
}
|
|
518
|
+
while (offset < attestationObject.length - 37) {
|
|
519
|
+
if (attestationObject[offset] === 104 && // text string, 8 bytes
|
|
520
|
+
attestationObject[offset + 1] === 97 && // 'a'
|
|
521
|
+
attestationObject[offset + 2] === 117 && // 'u'
|
|
522
|
+
attestationObject[offset + 3] === 116 && // 't'
|
|
523
|
+
attestationObject[offset + 4] === 104 && // 'h'
|
|
524
|
+
attestationObject[offset + 5] === 68 && // 'D'
|
|
525
|
+
attestationObject[offset + 6] === 97 && // 'a'
|
|
526
|
+
attestationObject[offset + 7] === 116 && // 't'
|
|
527
|
+
attestationObject[offset + 8] === 97) {
|
|
528
|
+
offset += 9;
|
|
529
|
+
break;
|
|
530
|
+
}
|
|
531
|
+
offset++;
|
|
532
|
+
}
|
|
533
|
+
if (attestationObject[offset] === 88 || attestationObject[offset] === 89) {
|
|
534
|
+
const lengthBytes = attestationObject[offset] === 88 ? 1 : 2;
|
|
535
|
+
offset += 1 + lengthBytes;
|
|
536
|
+
}
|
|
537
|
+
offset += 32;
|
|
538
|
+
offset += 1;
|
|
539
|
+
offset += 4;
|
|
540
|
+
offset += 16;
|
|
541
|
+
const credIdLen = attestationObject[offset] << 8 | attestationObject[offset + 1];
|
|
542
|
+
offset += 2;
|
|
543
|
+
offset += credIdLen;
|
|
544
|
+
const coseKey = attestationObject.slice(offset);
|
|
545
|
+
console.log("COSE key length:", coseKey.length);
|
|
546
|
+
console.log("COSE key hex:", this.bytesToHex(coseKey.slice(0, Math.min(100, coseKey.length))));
|
|
547
|
+
const { x, y } = this.parseCOSEKey(coseKey);
|
|
548
|
+
return { x, y };
|
|
549
|
+
}
|
|
550
|
+
parseCOSEKey(coseKey) {
|
|
551
|
+
console.log("COSE key length:", coseKey.length);
|
|
552
|
+
console.log("COSE key hex:", this.bytesToHex(coseKey));
|
|
553
|
+
const parsed = this.tryParseCOSEKeyStrategies(coseKey);
|
|
554
|
+
if (parsed) {
|
|
555
|
+
return parsed;
|
|
556
|
+
}
|
|
557
|
+
return this.parseCOSEKeyWithCBORStructure(coseKey);
|
|
558
|
+
}
|
|
559
|
+
tryParseCOSEKeyStrategies(coseKey) {
|
|
560
|
+
const keyBytes = new Uint8Array(coseKey);
|
|
561
|
+
for (let i = 0; i < keyBytes.length - 40; i++) {
|
|
562
|
+
if (keyBytes[i] === 88 && keyBytes[i + 1] === 32) {
|
|
563
|
+
const potentialX = keyBytes.slice(i + 2, i + 34);
|
|
564
|
+
for (let j = i + 34; j < keyBytes.length - 34; j++) {
|
|
565
|
+
if (keyBytes[j] === 88 && keyBytes[j + 1] === 32) {
|
|
566
|
+
const potentialY = keyBytes.slice(j + 2, j + 34);
|
|
567
|
+
if (this.isValidCoordinate(potentialX) && this.isValidCoordinate(potentialY)) {
|
|
568
|
+
console.log("Found coordinates via pattern matching");
|
|
569
|
+
return {
|
|
570
|
+
x: this.bytesToBigInt(potentialX),
|
|
571
|
+
y: this.bytesToBigInt(potentialY)
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
return this.tryParseASN1Structure(keyBytes);
|
|
579
|
+
}
|
|
580
|
+
parseCOSEKeyWithCBORStructure(coseKey) {
|
|
581
|
+
const bytes = new Uint8Array(coseKey);
|
|
582
|
+
let xBytes = null;
|
|
583
|
+
let yBytes = null;
|
|
584
|
+
let i = 0;
|
|
585
|
+
while (i < bytes.length) {
|
|
586
|
+
if (bytes[i] === 88) {
|
|
587
|
+
const length = bytes[i + 1];
|
|
588
|
+
if (length === 32) {
|
|
589
|
+
const start = i + 2;
|
|
590
|
+
const end = start + 32;
|
|
591
|
+
if (end <= bytes.length) {
|
|
592
|
+
const coordinate = bytes.slice(start, end);
|
|
593
|
+
if (!xBytes) {
|
|
594
|
+
xBytes = coordinate;
|
|
595
|
+
console.log("Found x at offset", i);
|
|
596
|
+
} else if (!yBytes) {
|
|
597
|
+
yBytes = coordinate;
|
|
598
|
+
console.log("Found y at offset", i);
|
|
599
|
+
break;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
i = end;
|
|
603
|
+
} else {
|
|
604
|
+
i += length + 2;
|
|
605
|
+
}
|
|
606
|
+
} else if (bytes[i] === 66) {
|
|
607
|
+
if (i + 3 < bytes.length) {
|
|
608
|
+
const length = bytes[i + 1] << 8 | bytes[i + 2];
|
|
609
|
+
if (length === 32) {
|
|
610
|
+
const start = i + 3;
|
|
611
|
+
const end = start + 32;
|
|
612
|
+
if (end <= bytes.length) {
|
|
613
|
+
const coordinate = bytes.slice(start, end);
|
|
614
|
+
if (!xBytes) {
|
|
615
|
+
xBytes = coordinate;
|
|
616
|
+
console.log("Found x at offset", i);
|
|
617
|
+
} else if (!yBytes) {
|
|
618
|
+
yBytes = coordinate;
|
|
619
|
+
console.log("Found y at offset", i);
|
|
620
|
+
break;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
i = end;
|
|
624
|
+
} else {
|
|
625
|
+
i += length + 3;
|
|
626
|
+
}
|
|
627
|
+
} else {
|
|
628
|
+
i++;
|
|
629
|
+
}
|
|
630
|
+
} else if (bytes[i] === 64) {
|
|
631
|
+
i++;
|
|
632
|
+
while (i < bytes.length && bytes[i] !== 255) {
|
|
633
|
+
if (bytes[i] === 4 && i + 65 <= bytes.length) {
|
|
634
|
+
const x = bytes.slice(i + 1, i + 33);
|
|
635
|
+
const y = bytes.slice(i + 33, i + 65);
|
|
636
|
+
if (this.isValidCoordinate(x) && this.isValidCoordinate(y)) {
|
|
637
|
+
xBytes = x;
|
|
638
|
+
yBytes = y;
|
|
639
|
+
console.log("Found coordinates in uncompressed point format");
|
|
640
|
+
break;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
i++;
|
|
644
|
+
}
|
|
645
|
+
if (xBytes && yBytes) break;
|
|
646
|
+
} else {
|
|
647
|
+
i++;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
if (!xBytes || !yBytes) {
|
|
651
|
+
const potentialCoords = this.find32ByteSequences(bytes);
|
|
652
|
+
if (potentialCoords.length >= 2) {
|
|
653
|
+
xBytes = potentialCoords[0];
|
|
654
|
+
yBytes = potentialCoords[1];
|
|
655
|
+
console.log("Fallback: Using first two 32-byte sequences as coordinates");
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
if (!xBytes || !yBytes) {
|
|
659
|
+
console.error("Failed to find coordinates in COSE key. Full dump:");
|
|
660
|
+
console.error("Hex:", this.bytesToHex(bytes));
|
|
661
|
+
console.error("Structure analysis:");
|
|
662
|
+
this.analyzeCOSEStructure(bytes);
|
|
663
|
+
throw new Error("Failed to extract public key coordinates from COSE key. Check console for details.");
|
|
664
|
+
}
|
|
665
|
+
return {
|
|
666
|
+
x: this.bytesToBigInt(xBytes),
|
|
667
|
+
y: this.bytesToBigInt(yBytes)
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
tryParseASN1Structure(bytes) {
|
|
671
|
+
if (bytes[0] === 48) {
|
|
672
|
+
let offset = 2;
|
|
673
|
+
if (bytes[offset] === 3) {
|
|
674
|
+
offset += 2;
|
|
675
|
+
if (bytes[offset] === 48) {
|
|
676
|
+
offset += 2;
|
|
677
|
+
offset += 12;
|
|
678
|
+
if (bytes[offset] === 3 && bytes[offset + 2] === 4) {
|
|
679
|
+
offset += 3;
|
|
680
|
+
const x = bytes.slice(offset, offset + 32);
|
|
681
|
+
const y = bytes.slice(offset + 32, offset + 64);
|
|
682
|
+
if (x.length === 32 && y.length === 32) {
|
|
683
|
+
console.log("Found coordinates via ASN.1 parsing");
|
|
684
|
+
return {
|
|
685
|
+
x: this.bytesToBigInt(x),
|
|
686
|
+
y: this.bytesToBigInt(y)
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
return null;
|
|
694
|
+
}
|
|
695
|
+
find32ByteSequences(bytes) {
|
|
696
|
+
const sequences = [];
|
|
697
|
+
for (let i = 0; i <= bytes.length - 32; i++) {
|
|
698
|
+
const sequence = bytes.slice(i, i + 32);
|
|
699
|
+
if (this.isValidCoordinate(sequence)) {
|
|
700
|
+
sequences.push(sequence);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
return sequences;
|
|
704
|
+
}
|
|
705
|
+
isValidCoordinate(bytes) {
|
|
706
|
+
if (bytes.length !== 32) return false;
|
|
707
|
+
let allZeros = true;
|
|
708
|
+
let allOnes = true;
|
|
709
|
+
for (const byte of bytes) {
|
|
710
|
+
if (byte !== 0) allZeros = false;
|
|
711
|
+
if (byte !== 255) allOnes = false;
|
|
712
|
+
}
|
|
713
|
+
return !allZeros && !allOnes;
|
|
714
|
+
}
|
|
715
|
+
bytesToBigInt(bytes) {
|
|
716
|
+
return BigInt("0x" + this.bytesToHex(bytes));
|
|
717
|
+
}
|
|
718
|
+
bytesToHex(bytes) {
|
|
719
|
+
return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
720
|
+
}
|
|
721
|
+
analyzeCOSEStructure(bytes) {
|
|
722
|
+
console.log("COSE Structure Analysis:");
|
|
723
|
+
console.log("First 20 bytes:", this.bytesToHex(bytes.slice(0, 20)));
|
|
724
|
+
const firstByte = bytes[0];
|
|
725
|
+
console.log("First byte (0x" + firstByte.toString(16) + "):");
|
|
726
|
+
if (firstByte >= 160 && firstByte <= 191) {
|
|
727
|
+
console.log("- Definite length map with", firstByte & 31, "pairs");
|
|
728
|
+
} else if (firstByte === 191) {
|
|
729
|
+
console.log("- Indefinite length map");
|
|
730
|
+
} else if (firstByte === 4) {
|
|
731
|
+
console.log("- Byte string");
|
|
732
|
+
} else if (firstByte === 2) {
|
|
733
|
+
console.log("- Negative integer");
|
|
734
|
+
}
|
|
735
|
+
let count32 = 0;
|
|
736
|
+
for (let i = 0; i <= bytes.length - 32; i++) {
|
|
737
|
+
const chunk = bytes.slice(i, i + 32);
|
|
738
|
+
if (this.isValidCoordinate(chunk)) {
|
|
739
|
+
console.log(
|
|
740
|
+
`Found valid 32-byte sequence at offset ${i}:`,
|
|
741
|
+
this.bytesToHex(chunk.slice(0, 8)) + "..."
|
|
742
|
+
);
|
|
743
|
+
count32++;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
console.log(`Total valid 32-byte sequences: ${count32}`);
|
|
747
|
+
console.log("Looking for known markers:");
|
|
748
|
+
const markers = [
|
|
749
|
+
{ byte: 4, name: "Uncompressed point marker" },
|
|
750
|
+
{ byte: 3, name: "BIT STRING" },
|
|
751
|
+
{ byte: 48, name: "SEQUENCE" },
|
|
752
|
+
{ byte: 2, name: "INTEGER" },
|
|
753
|
+
{ byte: 6, name: "OBJECT IDENTIFIER" },
|
|
754
|
+
{ byte: 88, name: "Byte string with length byte" },
|
|
755
|
+
{ byte: 66, name: "Byte string with 2-byte length" },
|
|
756
|
+
{ byte: 64, name: "Byte string indefinite length" },
|
|
757
|
+
{ byte: 160, name: "Map start" },
|
|
758
|
+
{ byte: 191, name: "Indefinite map start" }
|
|
759
|
+
];
|
|
760
|
+
for (const marker of markers) {
|
|
761
|
+
const indices = [];
|
|
762
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
763
|
+
if (bytes[i] === marker.byte) {
|
|
764
|
+
indices.push(i);
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
if (indices.length > 0) {
|
|
768
|
+
console.log(` ${marker.name} (0x${marker.byte.toString(16)}) at positions:`, indices.slice(0, 5).join(", "));
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
parseAuthenticationResponse(response) {
|
|
773
|
+
const authenticatorData = base64URLDecode(response.response.authenticatorData);
|
|
774
|
+
const clientDataJSON = response.response.clientDataJSON;
|
|
775
|
+
const signature = base64URLDecode(response.response.signature);
|
|
776
|
+
const { r, s } = parseDERSignature(signature);
|
|
777
|
+
const P256_N = BigInt("0xFFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551");
|
|
778
|
+
const P256_N_DIV_2 = BigInt(
|
|
779
|
+
"0x7FFFFFFF800000007FFFFFFFFFFFFFFFDE737D56D38BCF4279DCE5617E3192A8"
|
|
780
|
+
);
|
|
781
|
+
const clientDataStr = new TextDecoder().decode(base64URLDecode(clientDataJSON));
|
|
782
|
+
const challengeIndex = clientDataStr.indexOf('"challenge"');
|
|
783
|
+
const typeIndex = clientDataStr.indexOf('"type"');
|
|
784
|
+
if (challengeIndex === -1 || typeIndex === -1) {
|
|
785
|
+
throw new Error("Invalid clientDataJSON format");
|
|
786
|
+
}
|
|
787
|
+
return {
|
|
788
|
+
authenticatorData: import_ethers2.ethers.hexlify(authenticatorData),
|
|
789
|
+
clientDataJSON: clientDataStr,
|
|
790
|
+
challengeIndex,
|
|
791
|
+
typeIndex,
|
|
792
|
+
r: this.bytesToBigInt(r),
|
|
793
|
+
s: (() => {
|
|
794
|
+
const sBig = this.bytesToBigInt(s);
|
|
795
|
+
return sBig > P256_N_DIV_2 ? P256_N - sBig : sBig;
|
|
796
|
+
})()
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
801
|
+
0 && (module.exports = {
|
|
802
|
+
PasskeyManager,
|
|
803
|
+
VERIDEX_RP_ID,
|
|
804
|
+
detectRpId,
|
|
805
|
+
supportsRelatedOrigins
|
|
806
|
+
});
|
|
807
|
+
//# sourceMappingURL=passkey.js.map
|