@ixo/credentials-kit 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +469 -2
  2. package/dist/chunk-2SF56NEJ.js +1053 -0
  3. package/dist/chunk-2SF56NEJ.js.map +1 -0
  4. package/dist/chunk-46VRPQPD.js +176 -0
  5. package/dist/chunk-46VRPQPD.js.map +1 -0
  6. package/dist/chunk-AQ3IINHC.js +138 -0
  7. package/dist/chunk-AQ3IINHC.js.map +1 -0
  8. package/dist/chunk-FSKCDHZ7.js +613 -0
  9. package/dist/chunk-FSKCDHZ7.js.map +1 -0
  10. package/dist/chunk-I6GBYFIJ.js +89 -0
  11. package/dist/chunk-I6GBYFIJ.js.map +1 -0
  12. package/dist/chunk-JBUX6V2Q.js +210 -0
  13. package/dist/chunk-JBUX6V2Q.js.map +1 -0
  14. package/dist/chunk-Q3MZNMCK.js +183 -0
  15. package/dist/chunk-Q3MZNMCK.js.map +1 -0
  16. package/dist/chunk-RKKRO4ZK.js +133 -0
  17. package/dist/chunk-RKKRO4ZK.js.map +1 -0
  18. package/dist/chunk-STMMFNVW.js +391 -0
  19. package/dist/chunk-STMMFNVW.js.map +1 -0
  20. package/dist/chunk-VXKONZK4.js +189 -0
  21. package/dist/chunk-VXKONZK4.js.map +1 -0
  22. package/dist/chunk-WIEGZFUO.js +337 -0
  23. package/dist/chunk-WIEGZFUO.js.map +1 -0
  24. package/dist/chunk-WND2LZ4O.js +66 -0
  25. package/dist/chunk-WND2LZ4O.js.map +1 -0
  26. package/dist/chunk-XREZY53L.js +260 -0
  27. package/dist/chunk-XREZY53L.js.map +1 -0
  28. package/dist/chunk-ZZY4WGQ6.js +13 -0
  29. package/dist/chunk-ZZY4WGQ6.js.map +1 -0
  30. package/dist/did.d.ts +182 -0
  31. package/dist/did.js +6 -0
  32. package/dist/did.js.map +1 -0
  33. package/dist/display.d.ts +117 -0
  34. package/dist/display.js +5 -0
  35. package/dist/display.js.map +1 -0
  36. package/dist/errors-BKQmNpXX.d.ts +11 -0
  37. package/dist/holder.d.ts +85 -0
  38. package/dist/holder.js +8 -0
  39. package/dist/holder.js.map +1 -0
  40. package/dist/http-BhuJ_-RZ.d.ts +25 -0
  41. package/dist/index.d.ts +15 -0
  42. package/dist/index.js +16 -0
  43. package/dist/index.js.map +1 -0
  44. package/dist/jose.d.ts +134 -0
  45. package/dist/jose.js +4 -0
  46. package/dist/jose.js.map +1 -0
  47. package/dist/oid4vci.d.ts +428 -0
  48. package/dist/oid4vci.js +11 -0
  49. package/dist/oid4vci.js.map +1 -0
  50. package/dist/oid4vp.d.ts +416 -0
  51. package/dist/oid4vp.js +11 -0
  52. package/dist/oid4vp.js.map +1 -0
  53. package/dist/profile.d.ts +218 -0
  54. package/dist/profile.js +4 -0
  55. package/dist/profile.js.map +1 -0
  56. package/dist/sdjwt.d.ts +133 -0
  57. package/dist/sdjwt.js +5 -0
  58. package/dist/sdjwt.js.map +1 -0
  59. package/dist/sender.d.ts +8 -0
  60. package/dist/sender.js +7 -0
  61. package/dist/sender.js.map +1 -0
  62. package/dist/status.d.ts +108 -0
  63. package/dist/status.js +7 -0
  64. package/dist/status.js.map +1 -0
  65. package/dist/util-DOTEZgTt.d.ts +3 -0
  66. package/dist/verify.d.ts +144 -0
  67. package/dist/verify.js +9 -0
  68. package/dist/verify.js.map +1 -0
  69. package/dist/webhook.d.ts +62 -0
  70. package/dist/webhook.js +7 -0
  71. package/dist/webhook.js.map +1 -0
  72. package/package.json +168 -4
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/internal/bytes.ts"],"names":[],"mappings":";AAIA,IAAM,EAAA,GAAK,IAAI,WAAA,EAAY;AAC3B,IAAM,KAAK,IAAI,WAAA,CAAY,SAAS,EAAE,KAAA,EAAO,MAAM,CAAA;AAG5C,SAAS,KAAK,CAAA,EAAoC;AACvD,EAAA,OAAO,EAAA,CAAG,OAAO,CAAC,CAAA;AACp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AA,KAAA,CAAM,CAAC,IAAI,KAAA,GAAQ,GAAA;AACnB,MAAA,KAAA,KAAU,CAAA;AAAA,IACZ;AACA,IAAA,OAAO,QAAQ,CAAA,EAAG;AAChB,MAAA,KAAA,CAAM,IAAA,CAAK,QAAQ,GAAI,CAAA;AACvB,MAAA,KAAA,KAAU,CAAA;AAAA,IACZ;AAAA,EACF;AACA,EAAA,MAAM,GAAA,GAAM,IAAI,UAAA,CAAW,KAAA,GAAQ,MAAM,MAAM,CAAA;AAC/C,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,KAAA,CAAM,QAAQ,CAAA,EAAA,EAAK;AACrC,IAAA,GAAA,CAAI,QAAQ,CAAC,CAAA,GAAI,MAAM,KAAA,CAAM,MAAA,GAAS,IAAI,CAAC,CAAA;AAAA,EAC7C;AACA,EAAA,OAAO,GAAA;AACT;AAGO,SAAS,WAAA,CAAY,QAAQ,EAAA,EAAY;AAC9C,EAAA,OAAO,gBAAgB,MAAA,CAAO,eAAA,CAAgB,IAAI,UAAA,CAAW,KAAK,CAAC,CAAC,CAAA;AACtE","file":"chunk-AQ3IINHC.js","sourcesContent":["/**\n * Byte helpers shared by every module. Runtime-neutral: no Buffer, no Node built-ins.\n */\n\nconst te = new TextEncoder();\nconst td = new TextDecoder('utf-8', { fatal: true });\n\n/** UTF-8 bytes of a string. */\nexport function utf8(s: string): Uint8Array<ArrayBuffer> {\n return te.encode(s);\n}\n\n/** A string from UTF-8 bytes; throws on invalid UTF-8. */\nexport function fromUtf8(bytes: Uint8Array): string {\n return td.decode(bytes);\n}\n\nconst B64URL =\n 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';\nconst B64URL_LOOKUP = (() => {\n const t = new Int16Array(128).fill(-1);\n for (let i = 0; i < B64URL.length; i++) t[B64URL.charCodeAt(i)] = i;\n return t;\n})();\n\n/** base64url without padding (RFC 7515 §2). */\nexport function base64urlEncode(bytes: Uint8Array): string {\n let out = '';\n let i = 0;\n for (; i + 2 < bytes.length; i += 3) {\n const n = (bytes[i]! << 16) | (bytes[i + 1]! << 8) | bytes[i + 2]!;\n out +=\n B64URL[(n >> 18) & 63]! +\n B64URL[(n >> 12) & 63]! +\n B64URL[(n >> 6) & 63]! +\n B64URL[n & 63]!;\n }\n const rest = bytes.length - i;\n if (rest === 1) {\n const n = bytes[i]! << 16;\n out += B64URL[(n >> 18) & 63]! + B64URL[(n >> 12) & 63]!;\n } else if (rest === 2) {\n const n = (bytes[i]! << 16) | (bytes[i + 1]! << 8);\n out +=\n B64URL[(n >> 18) & 63]! +\n B64URL[(n >> 12) & 63]! +\n B64URL[(n >> 6) & 63]!;\n }\n return out;\n}\n\n/**\n * Strict base64url decode: only the URL-safe alphabet, no padding, no whitespace, and the\n * canonical encoding only (unused trailing bits must be zero), so one byte string has exactly\n * one accepted text form. Throws on anything else.\n */\nexport function base64urlDecode(s: string): Uint8Array<ArrayBuffer> {\n if (s.length % 4 === 1) throw new Error('invalid base64url');\n const out = new Uint8Array(Math.floor((s.length * 3) / 4));\n let buffer = 0;\n let bits = 0;\n let at = 0;\n for (let i = 0; i < s.length; i++) {\n const c = s.charCodeAt(i);\n const v = c < 128 ? B64URL_LOOKUP[c]! : -1;\n if (v < 0) throw new Error('invalid base64url');\n buffer = ((buffer << 6) | v) & 0x3fff; // at most 13 live bits\n bits += 6;\n if (bits >= 8) {\n bits -= 8;\n out[at++] = (buffer >> bits) & 0xff;\n }\n }\n if (bits > 0 && (buffer & ((1 << bits) - 1)) !== 0) {\n throw new Error('invalid base64url');\n }\n return out;\n}\n\n/** base64url of the UTF-8 bytes of a JSON value. */\nexport function base64urlJson(value: unknown): string {\n return base64urlEncode(utf8(JSON.stringify(value)));\n}\n\n/** Parse base64url-encoded UTF-8 JSON; throws when it is not. */\nexport function parseBase64urlJson(segment: string): unknown {\n return JSON.parse(fromUtf8(base64urlDecode(segment))) as unknown;\n}\n\nexport function concatBytes(...parts: Uint8Array[]): Uint8Array<ArrayBuffer> {\n const size = parts.reduce((n, p) => n + p.length, 0);\n const out = new Uint8Array(size);\n let at = 0;\n for (const p of parts) {\n out.set(p, at);\n at += p.length;\n }\n return out;\n}\n\n/** Constant-time equality for secrets of equal length (length itself is not secret). */\nexport function timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) return false;\n let diff = 0;\n for (let i = 0; i < a.length; i++) diff |= a[i]! ^ b[i]!;\n return diff === 0;\n}\n\nexport function bytesToHex(bytes: Uint8Array): string {\n let out = '';\n for (const b of bytes) out += b.toString(16).padStart(2, '0');\n return out;\n}\n\nexport function hexToBytes(hex: string): Uint8Array<ArrayBuffer> {\n if (!/^(?:[0-9a-fA-F]{2})*$/.test(hex)) throw new Error('invalid hex');\n const out = new Uint8Array(hex.length / 2);\n for (let i = 0; i < out.length; i++) {\n out[i] = Number.parseInt(hex.slice(i * 2, i * 2 + 2), 16);\n }\n return out;\n}\n\nconst B58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';\n\n/** base58btc (Bitcoin alphabet), as used by did:key, multibase `z` and IXO key ids. */\nexport function base58btcEncode(bytes: Uint8Array): string {\n let zeros = 0;\n while (zeros < bytes.length && bytes[zeros] === 0) zeros++;\n const digits: number[] = [];\n for (let i = zeros; i < bytes.length; i++) {\n let carry = bytes[i]!;\n for (let j = 0; j < digits.length; j++) {\n carry += digits[j]! << 8;\n digits[j] = carry % 58;\n carry = (carry / 58) | 0;\n }\n while (carry > 0) {\n digits.push(carry % 58);\n carry = (carry / 58) | 0;\n }\n }\n let out = '1'.repeat(zeros);\n for (let i = digits.length - 1; i >= 0; i--) out += B58[digits[i]!]!;\n return out;\n}\n\nexport function base58btcDecode(s: string): Uint8Array<ArrayBuffer> {\n let zeros = 0;\n while (zeros < s.length && s[zeros] === '1') zeros++;\n const bytes: number[] = [];\n for (let i = zeros; i < s.length; i++) {\n const v = B58.indexOf(s[i]!);\n if (v < 0) throw new Error('invalid base58btc');\n let carry = v;\n for (let j = 0; j < bytes.length; j++) {\n carry += bytes[j]! * 58;\n bytes[j] = carry & 0xff;\n carry >>= 8;\n }\n while (carry > 0) {\n bytes.push(carry & 0xff);\n carry >>= 8;\n }\n }\n const out = new Uint8Array(zeros + bytes.length);\n for (let i = 0; i < bytes.length; i++) {\n out[zeros + i] = bytes[bytes.length - 1 - i]!;\n }\n return out;\n}\n\n/** A cryptographically random base64url string of `bytes` random bytes. */\nexport function randomToken(bytes = 32): string {\n return base64urlEncode(crypto.getRandomValues(new Uint8Array(bytes)));\n}\n"]}
@@ -0,0 +1,613 @@
1
+ import { PRE_AUTHORIZED_CODE_GRANT, PROOF_JWT_TYP } from './chunk-I6GBYFIJ.js';
2
+ import { verifyIssuedCredential } from './chunk-STMMFNVW.js';
3
+ import { didFromKid, ResolverUnavailable, findKey } from './chunk-WIEGZFUO.js';
4
+ import { isFetchableUrl, request, HttpError } from './chunk-Q3MZNMCK.js';
5
+ import { CredentialsKitError, isRecord, decodeJws, isEd25519JwsAlg, toSeconds, clockMs, CLOCK_SKEW_S, verifyEd25519, publicJwkFromRaw, signJws } from './chunk-VXKONZK4.js';
6
+ import { utf8 } from './chunk-AQ3IINHC.js';
7
+
8
+ // src/oid4vci.ts
9
+ var OID4VCI_MESSAGES = {
10
+ invalid_offer: "The credential offer is not well formed.",
11
+ unsupported_offer: "The credential offer uses a feature this profile does not support.",
12
+ invalid_metadata: "The issuer's metadata is missing or not well formed.",
13
+ issuer_unavailable: "The issuer could not be reached.",
14
+ tx_code_unsupported: "The offer needs a transaction code, which this wallet does not support.",
15
+ token_error: "The issuer refused the pre-authorized code.",
16
+ issuer_error: "The issuer refused the request.",
17
+ invalid_response: "The issuer's answer is not well formed.",
18
+ invalid_proof: "The key proof is not valid.",
19
+ invalid_nonce: "The key proof does not carry a valid nonce.",
20
+ invalid_credential: "The issuer sent a credential that does not check out, so it was not kept."
21
+ };
22
+ var Oid4vciError = class extends CredentialsKitError {
23
+ /** The OAuth / OpenID4VCI error code the server answered (sanitised), when there was one. */
24
+ oauthError;
25
+ /**
26
+ * For `invalid_proof` / `invalid_nonce`: a constant cause for logs. For `invalid_credential`:
27
+ * the `verifyIssuedCredential` failure code (`bad_signature`, `wrong_subject`, …).
28
+ */
29
+ reason;
30
+ constructor(code, extra = {}) {
31
+ super(code, OID4VCI_MESSAGES[code]);
32
+ if (extra.oauthError !== void 0) this.oauthError = extra.oauthError;
33
+ if (extra.reason !== void 0) this.reason = extra.reason;
34
+ }
35
+ };
36
+ function insertWellKnown(identifier, suffix) {
37
+ const u = new URL(identifier);
38
+ const path = u.pathname === "/" ? "" : u.pathname.replace(/\/$/, "");
39
+ return `${u.origin}/.well-known/${suffix}${path}`;
40
+ }
41
+ function issuerMetadataUrl(credentialIssuer) {
42
+ return insertWellKnown(credentialIssuer, "openid-credential-issuer");
43
+ }
44
+ function authorizationServerMetadataUrl(issuer) {
45
+ return insertWellKnown(issuer, "oauth-authorization-server");
46
+ }
47
+ function buildIssuerMetadata(input) {
48
+ const base = input.credentialIssuer.replace(/\/$/, "");
49
+ const ep = input.endpoints ?? {};
50
+ const configurations = {};
51
+ for (const [id, c] of Object.entries(input.configurations)) {
52
+ configurations[id] = {
53
+ format: "dc+sd-jwt",
54
+ vct: c.vct,
55
+ ...input.includeScope ? { scope: id } : {},
56
+ cryptographic_binding_methods_supported: ["did:ixo"],
57
+ credential_signing_alg_values_supported: ["EdDSA", "Ed25519"],
58
+ proof_types_supported: {
59
+ jwt: { proof_signing_alg_values_supported: ["EdDSA", "Ed25519"] }
60
+ },
61
+ ...c.display || c.claims ? {
62
+ credential_metadata: {
63
+ ...c.display ? { display: c.display } : {},
64
+ ...c.claims ? { claims: c.claims } : {}
65
+ }
66
+ } : {}
67
+ };
68
+ }
69
+ return {
70
+ credential_issuer: input.credentialIssuer,
71
+ ...input.authorizationServers ? { authorization_servers: input.authorizationServers } : {},
72
+ credential_endpoint: ep.credential ?? `${base}/oid4vci/credential`,
73
+ nonce_endpoint: ep.nonce ?? `${base}/oid4vci/nonce`,
74
+ ...ep.deferred !== void 0 ? { deferred_credential_endpoint: ep.deferred } : {},
75
+ notification_endpoint: ep.notification ?? `${base}/oid4vci/notification`,
76
+ ...input.display ? { display: input.display } : {},
77
+ credential_configurations_supported: configurations
78
+ };
79
+ }
80
+ function buildAuthorizationServerMetadata(input) {
81
+ return {
82
+ issuer: input.issuer,
83
+ token_endpoint: input.tokenEndpoint ?? `${input.issuer.replace(/\/$/, "")}/oid4vci/token`,
84
+ grant_types_supported: [PRE_AUTHORIZED_CODE_GRANT],
85
+ // No client authentication at the token endpoint (RFC 8414 §2's default would be basic).
86
+ token_endpoint_auth_methods_supported: ["none"],
87
+ "pre-authorized_grant_anonymous_access_supported": true
88
+ };
89
+ }
90
+ function buildCredentialOffer(input) {
91
+ return validateCredentialOffer(
92
+ {
93
+ credential_issuer: input.credentialIssuer,
94
+ credential_configuration_ids: input.configurationIds,
95
+ grants: {
96
+ [PRE_AUTHORIZED_CODE_GRANT]: {
97
+ "pre-authorized_code": input.preAuthorizedCode,
98
+ ...input.txCode ? { tx_code: input.txCode } : {}
99
+ }
100
+ }
101
+ },
102
+ { allowHttp: true, allowLocal: true }
103
+ );
104
+ }
105
+ function validateCredentialOffer(v, opts = {}) {
106
+ const bad = () => new Oid4vciError("invalid_offer");
107
+ if (!isRecord(v)) throw bad();
108
+ const issuer = v.credential_issuer;
109
+ if (typeof issuer !== "string" || !isFetchableUrl(issuer, opts)) throw bad();
110
+ if (new URL(issuer).search !== "") throw bad();
111
+ const ids = v.credential_configuration_ids;
112
+ if (!Array.isArray(ids) || ids.length === 0 || !ids.every((i) => typeof i === "string" && i.length > 0 && i.length <= 256) || new Set(ids).size !== ids.length) {
113
+ throw bad();
114
+ }
115
+ const grants = isRecord(v.grants) ? v.grants : null;
116
+ const grant = grants ? grants[PRE_AUTHORIZED_CODE_GRANT] : void 0;
117
+ if (grant === void 0 && grants && Object.keys(grants).length > 0)
118
+ throw new Oid4vciError("unsupported_offer");
119
+ if (!isRecord(grant)) throw bad();
120
+ const code = grant["pre-authorized_code"];
121
+ if (typeof code !== "string" || code.length === 0 || code.length > 4096)
122
+ throw bad();
123
+ const out = { "pre-authorized_code": code };
124
+ if (grant.tx_code !== void 0) {
125
+ const t = grant.tx_code;
126
+ if (!isRecord(t)) throw bad();
127
+ const tx = {};
128
+ if (t.input_mode !== void 0) {
129
+ if (t.input_mode !== "numeric" && t.input_mode !== "text") throw bad();
130
+ tx.input_mode = t.input_mode;
131
+ }
132
+ if (t.length !== void 0) {
133
+ if (typeof t.length !== "number" || !Number.isInteger(t.length) || t.length <= 0)
134
+ throw bad();
135
+ tx.length = t.length;
136
+ }
137
+ if (t.description !== void 0) {
138
+ if (typeof t.description !== "string" || t.description.length > 300)
139
+ throw bad();
140
+ tx.description = t.description;
141
+ }
142
+ out.tx_code = tx;
143
+ }
144
+ if (grant.authorization_server !== void 0) {
145
+ if (typeof grant.authorization_server !== "string") throw bad();
146
+ out.authorization_server = grant.authorization_server;
147
+ }
148
+ return {
149
+ credential_issuer: issuer,
150
+ credential_configuration_ids: [...ids],
151
+ grants: { [PRE_AUTHORIZED_CODE_GRANT]: out }
152
+ };
153
+ }
154
+ async function verifyProofJwt(jwt, opts) {
155
+ const invalid = (reason) => new Oid4vciError("invalid_proof", { reason });
156
+ let jws;
157
+ try {
158
+ jws = decodeJws(typeof jwt === "string" ? jwt.trim() : "");
159
+ } catch {
160
+ throw invalid("malformed");
161
+ }
162
+ const { header, payload } = jws;
163
+ if (header.typ !== PROOF_JWT_TYP) throw invalid("wrong_typ");
164
+ if (!isEd25519JwsAlg(header.alg)) throw invalid("unsupported_alg");
165
+ if (header.jwk !== void 0 || header.x5c !== void 0)
166
+ throw invalid("key_not_by_kid");
167
+ const kid = header.kid;
168
+ if (typeof kid !== "string" || !kid.startsWith("did:") || !kid.includes("#")) {
169
+ throw invalid("kid_not_did_url");
170
+ }
171
+ if (payload.aud !== opts.audience) throw invalid("wrong_audience");
172
+ const nowS = toSeconds(clockMs(opts.now));
173
+ const maxAge = opts.maxAgeSeconds ?? 300;
174
+ if (typeof payload.iat !== "number" || payload.iat > nowS + CLOCK_SKEW_S || payload.iat < nowS - maxAge - CLOCK_SKEW_S) {
175
+ throw invalid("stale");
176
+ }
177
+ const nonce = payload.nonce;
178
+ if (opts.nonce !== void 0) {
179
+ if (typeof nonce !== "string" || nonce.length === 0) {
180
+ throw new Oid4vciError("invalid_proof", { reason: "no_nonce" });
181
+ }
182
+ } else if (nonce !== void 0 && typeof nonce !== "string") {
183
+ throw invalid("malformed");
184
+ }
185
+ const did = didFromKid(kid);
186
+ let doc;
187
+ try {
188
+ doc = await opts.resolver(did);
189
+ } catch (e) {
190
+ if (e instanceof ResolverUnavailable) throw e;
191
+ throw invalid("unknown_did");
192
+ }
193
+ const key = doc ? findKey(doc, kid, "authentication") : null;
194
+ if (!key) throw invalid("key_not_on_did");
195
+ if (!verifyEd25519(jws.signature, utf8(jws.signingInput), key.publicKey)) {
196
+ throw invalid("bad_signature");
197
+ }
198
+ if (opts.nonce !== void 0) {
199
+ const ok = typeof opts.nonce === "string" ? nonce === opts.nonce : await opts.nonce(nonce);
200
+ if (!ok) throw new Oid4vciError("invalid_nonce", { reason: "wrong_nonce" });
201
+ }
202
+ return {
203
+ did,
204
+ kid: key.id,
205
+ publicKey: key.publicKey,
206
+ jwk: publicJwkFromRaw(key.publicKey),
207
+ ...typeof nonce === "string" ? { nonce } : {}
208
+ };
209
+ }
210
+ function createProofJwt(input) {
211
+ return signJws(
212
+ { alg: input.alg ?? "EdDSA", typ: PROOF_JWT_TYP, kid: input.signer.kid },
213
+ {
214
+ aud: input.audience,
215
+ iat: toSeconds(clockMs(input.now)),
216
+ ...input.nonce !== void 0 ? { nonce: input.nonce } : {}
217
+ },
218
+ input.signer
219
+ );
220
+ }
221
+ var MAX_METADATA_BYTES = 256 * 1024;
222
+ var MAX_TOKEN_RESPONSE_BYTES = 64 * 1024;
223
+ var MAX_CREDENTIAL_RESPONSE_BYTES = 256 * 1024;
224
+ var OAUTH_ERROR = /^[\x20-\x21\x23-\x5b\x5d-\x7e]{1,64}$/;
225
+ function httpOf(opts) {
226
+ return {
227
+ fetch: opts.fetch,
228
+ allowHttp: opts.allowHttp ?? false,
229
+ allowLocal: opts.allowLocal ?? false,
230
+ ...opts.timeoutMs !== void 0 ? { timeoutMs: opts.timeoutMs } : {}
231
+ };
232
+ }
233
+ async function call(http, url, init) {
234
+ if (!isFetchableUrl(url, http)) throw new Oid4vciError("invalid_metadata");
235
+ let res;
236
+ try {
237
+ res = await request(http.fetch, url, {
238
+ method: init.method,
239
+ headers: init.headers,
240
+ ...init.body !== void 0 ? { body: init.body } : {},
241
+ maxBytes: init.maxBytes,
242
+ ...http.timeoutMs !== void 0 ? { timeoutMs: http.timeoutMs } : {}
243
+ });
244
+ } catch (e) {
245
+ if (e instanceof HttpError && e.kind === "too_large") {
246
+ throw new Oid4vciError("invalid_response");
247
+ }
248
+ throw new Oid4vciError("issuer_unavailable");
249
+ }
250
+ if (res.status >= 500) throw new Oid4vciError("issuer_unavailable");
251
+ if (res.text.length === 0) return { status: res.status, json: null };
252
+ try {
253
+ return { status: res.status, json: JSON.parse(res.text) };
254
+ } catch {
255
+ if (res.status >= 200 && res.status < 300)
256
+ throw new Oid4vciError("invalid_response");
257
+ return { status: res.status, json: null };
258
+ }
259
+ }
260
+ function oauthErrorOf(json) {
261
+ if (isRecord(json) && typeof json.error === "string" && OAUTH_ERROR.test(json.error)) {
262
+ return json.error;
263
+ }
264
+ return void 0;
265
+ }
266
+ function refused(code, json) {
267
+ const oauthError = oauthErrorOf(json);
268
+ return new Oid4vciError(code, oauthError !== void 0 ? { oauthError } : {});
269
+ }
270
+ async function fetchIssuerMetadata(credentialIssuer, opts) {
271
+ const http = httpOf(opts);
272
+ const { status, json } = await call(
273
+ http,
274
+ issuerMetadataUrl(credentialIssuer),
275
+ {
276
+ method: "GET",
277
+ headers: { accept: "application/json" },
278
+ maxBytes: MAX_METADATA_BYTES
279
+ }
280
+ );
281
+ if (status !== 200 || !isRecord(json))
282
+ throw new Oid4vciError("invalid_metadata");
283
+ if (json.credential_issuer !== credentialIssuer)
284
+ throw new Oid4vciError("invalid_metadata");
285
+ const endpointOk = (v) => v === void 0 || typeof v === "string" && isFetchableUrl(v, http);
286
+ if (typeof json.credential_endpoint !== "string" || !endpointOk(json.credential_endpoint) || !endpointOk(json.nonce_endpoint) || !endpointOk(json.deferred_credential_endpoint) || !endpointOk(json.notification_endpoint) || !isRecord(json.credential_configurations_supported)) {
287
+ throw new Oid4vciError("invalid_metadata");
288
+ }
289
+ if (json.authorization_servers !== void 0 && (!Array.isArray(json.authorization_servers) || json.authorization_servers.length === 0 || !json.authorization_servers.every((a) => typeof a === "string"))) {
290
+ throw new Oid4vciError("invalid_metadata");
291
+ }
292
+ return json;
293
+ }
294
+ async function tokenEndpointOf(http, metadata, grant) {
295
+ const servers = metadata.authorization_servers;
296
+ let as;
297
+ if (grant.authorization_server !== void 0) {
298
+ if (!servers?.includes(grant.authorization_server))
299
+ throw new Oid4vciError("invalid_offer");
300
+ as = grant.authorization_server;
301
+ } else if (servers) {
302
+ if (servers.length !== 1) throw new Oid4vciError("unsupported_offer");
303
+ as = servers[0];
304
+ } else {
305
+ as = metadata.credential_issuer;
306
+ }
307
+ if (!isFetchableUrl(as, http)) throw new Oid4vciError("invalid_metadata");
308
+ const { status, json } = await call(
309
+ http,
310
+ authorizationServerMetadataUrl(as),
311
+ {
312
+ method: "GET",
313
+ headers: { accept: "application/json" },
314
+ maxBytes: MAX_METADATA_BYTES
315
+ }
316
+ );
317
+ if (status !== 200 || !isRecord(json) || json.issuer !== as || typeof json.token_endpoint !== "string" || !isFetchableUrl(json.token_endpoint, http)) {
318
+ throw new Oid4vciError("invalid_metadata");
319
+ }
320
+ return json.token_endpoint;
321
+ }
322
+ function readCredentialResponse(json) {
323
+ if (!isRecord(json) || !Array.isArray(json.credentials) || json.credentials.length !== 1) {
324
+ throw new Oid4vciError("invalid_response");
325
+ }
326
+ const first = json.credentials[0];
327
+ if (!isRecord(first) || typeof first.credential !== "string" || first.credential.length === 0) {
328
+ throw new Oid4vciError("invalid_response");
329
+ }
330
+ if (json.notification_id !== void 0 && typeof json.notification_id !== "string") {
331
+ throw new Oid4vciError("invalid_response");
332
+ }
333
+ return {
334
+ credential: first.credential,
335
+ ...typeof json.notification_id === "string" ? { notificationId: json.notification_id } : {}
336
+ };
337
+ }
338
+ function readDeferredResponse(json) {
339
+ if (!isRecord(json) || typeof json.transaction_id !== "string" || json.transaction_id.length === 0 || typeof json.interval !== "number" || !(json.interval > 0)) {
340
+ throw new Oid4vciError("invalid_response");
341
+ }
342
+ return { transactionId: json.transaction_id, interval: json.interval };
343
+ }
344
+ var MAX_OFFER_BYTES = 64 * 1024;
345
+ async function fetchCredentialOffer(credentialOfferUri, opts) {
346
+ const http = httpOf(opts);
347
+ if (!isFetchableUrl(credentialOfferUri, http)) {
348
+ throw new Oid4vciError("invalid_offer");
349
+ }
350
+ const res = await call(http, credentialOfferUri, {
351
+ method: "GET",
352
+ headers: { accept: "application/json", "cache-control": "no-store" },
353
+ maxBytes: MAX_OFFER_BYTES
354
+ });
355
+ if (res.status !== 200) throw refused("issuer_error", res.json);
356
+ return validateCredentialOffer(res.json, http);
357
+ }
358
+ async function holderKeyOf(signer, resolver) {
359
+ if (signer.publicKey instanceof Uint8Array && signer.publicKey.length === 32)
360
+ return signer.publicKey;
361
+ const doc = await resolver(didFromKid(signer.kid));
362
+ const key = doc ? findKey(doc, signer.kid, "authentication") : null;
363
+ if (!key)
364
+ throw new Oid4vciError("invalid_proof", { reason: "key_not_on_did" });
365
+ return key.publicKey;
366
+ }
367
+ async function checkCredential(credential, verification, now, onFailure) {
368
+ const result = await verifyIssuedCredential(credential, {
369
+ ...verification,
370
+ ...now !== void 0 ? { now } : {}
371
+ });
372
+ if (result.ok) return result;
373
+ await onFailure().catch(() => void 0);
374
+ throw new Oid4vciError("invalid_credential", { reason: result.code });
375
+ }
376
+ async function redeemOffer(input) {
377
+ const http = httpOf(input);
378
+ const verify = input.verify ?? true;
379
+ if (verify && input.resolver === void 0) {
380
+ throw new TypeError(
381
+ "redeemOffer needs a resolver to check the credential (or verify: false)."
382
+ );
383
+ }
384
+ const expectedIssuer = input.expectedIssuer;
385
+ if (verify && expectedIssuer !== false && (typeof expectedIssuer !== "string" || expectedIssuer.length === 0)) {
386
+ throw new TypeError(
387
+ "redeemOffer needs expectedIssuer (the DID that should have issued the credential), or expectedIssuer: false to accept any issuer."
388
+ );
389
+ }
390
+ if (input.offer === void 0 === (input.credentialOfferUri === void 0)) {
391
+ throw new TypeError("Give exactly one of offer and credentialOfferUri.");
392
+ }
393
+ const offer = input.credentialOfferUri !== void 0 ? await fetchCredentialOffer(input.credentialOfferUri, http) : validateCredentialOffer(input.offer, http);
394
+ if (offer.credential_configuration_ids.length !== 1) {
395
+ throw new Oid4vciError("unsupported_offer");
396
+ }
397
+ const configurationId = offer.credential_configuration_ids[0];
398
+ const grant = offer.grants[PRE_AUTHORIZED_CODE_GRANT];
399
+ if (grant.tx_code !== void 0)
400
+ throw new Oid4vciError("tx_code_unsupported");
401
+ const metadata = await fetchIssuerMetadata(offer.credential_issuer, http);
402
+ const configuration = metadata.credential_configurations_supported[configurationId];
403
+ if (!isRecord(configuration) || configuration.format !== "dc+sd-jwt") {
404
+ throw new Oid4vciError("unsupported_offer");
405
+ }
406
+ const holderDid = didFromKid(input.signer.kid);
407
+ const bindingMethods = configuration.cryptographic_binding_methods_supported;
408
+ if (bindingMethods !== void 0) {
409
+ const method = /^did:[a-z0-9]+/.exec(holderDid)?.[0];
410
+ if (!Array.isArray(bindingMethods) || method === void 0 || !bindingMethods.includes(method))
411
+ throw new Oid4vciError("unsupported_offer");
412
+ }
413
+ let proofAlg = "EdDSA";
414
+ const proofTypes = configuration.proof_types_supported;
415
+ if (proofTypes !== void 0) {
416
+ const jwtProof = isRecord(proofTypes) ? proofTypes.jwt : void 0;
417
+ const algs = isRecord(jwtProof) ? jwtProof.proof_signing_alg_values_supported : void 0;
418
+ if (!Array.isArray(algs)) throw new Oid4vciError("unsupported_offer");
419
+ if (algs.includes("EdDSA")) proofAlg = "EdDSA";
420
+ else if (algs.includes("Ed25519")) proofAlg = "Ed25519";
421
+ else throw new Oid4vciError("unsupported_offer");
422
+ }
423
+ if (typeof configuration.vct !== "string" || configuration.vct.length === 0)
424
+ throw new Oid4vciError("invalid_metadata");
425
+ const verification = verify && input.resolver ? {
426
+ subject: holderDid,
427
+ holderKey: await holderKeyOf(input.signer, input.resolver),
428
+ vct: configuration.vct,
429
+ resolver: input.resolver,
430
+ issuer: typeof expectedIssuer === "string" ? expectedIssuer : false
431
+ } : null;
432
+ const tokenEndpoint = await tokenEndpointOf(http, metadata, grant);
433
+ const form = new URLSearchParams({
434
+ grant_type: PRE_AUTHORIZED_CODE_GRANT,
435
+ "pre-authorized_code": grant["pre-authorized_code"]
436
+ });
437
+ const token = await call(http, tokenEndpoint, {
438
+ method: "POST",
439
+ headers: {
440
+ "content-type": "application/x-www-form-urlencoded",
441
+ accept: "application/json"
442
+ },
443
+ body: form.toString(),
444
+ maxBytes: MAX_TOKEN_RESPONSE_BYTES
445
+ });
446
+ if (token.status !== 200) throw refused("token_error", token.json);
447
+ const tj = token.json;
448
+ if (!isRecord(tj) || typeof tj.access_token !== "string" || tj.access_token.length === 0 || typeof tj.token_type !== "string" || tj.token_type.toLowerCase() !== "bearer") {
449
+ throw new Oid4vciError("invalid_response");
450
+ }
451
+ const accessToken = tj.access_token;
452
+ let credentialIdentifier;
453
+ if (Array.isArray(tj.authorization_details)) {
454
+ const detail = tj.authorization_details.find(
455
+ (d) => isRecord(d) && d.type === "openid_credential" && d.credential_configuration_id === configurationId
456
+ );
457
+ if (isRecord(detail) && Array.isArray(detail.credential_identifiers)) {
458
+ const first = detail.credential_identifiers[0];
459
+ if (typeof first !== "string") throw new Oid4vciError("invalid_response");
460
+ credentialIdentifier = first;
461
+ }
462
+ }
463
+ const getNonce = async () => {
464
+ if (metadata.nonce_endpoint === void 0) return void 0;
465
+ const res2 = await call(http, metadata.nonce_endpoint, {
466
+ method: "POST",
467
+ headers: { accept: "application/json" },
468
+ maxBytes: MAX_TOKEN_RESPONSE_BYTES
469
+ });
470
+ if (res2.status !== 200 || !isRecord(res2.json) || typeof res2.json.c_nonce !== "string") {
471
+ throw new Oid4vciError("invalid_response");
472
+ }
473
+ return res2.json.c_nonce;
474
+ };
475
+ const requestCredential = async (nonce) => {
476
+ const proof = await createProofJwt({
477
+ signer: input.signer,
478
+ audience: metadata.credential_issuer,
479
+ alg: proofAlg,
480
+ ...nonce !== void 0 ? { nonce } : {},
481
+ ...input.now !== void 0 ? { now: input.now } : {}
482
+ });
483
+ const body = credentialIdentifier !== void 0 ? {
484
+ credential_identifier: credentialIdentifier,
485
+ proofs: { jwt: [proof] }
486
+ } : {
487
+ credential_configuration_id: configurationId,
488
+ proofs: { jwt: [proof] }
489
+ };
490
+ return call(http, metadata.credential_endpoint, {
491
+ method: "POST",
492
+ headers: {
493
+ authorization: `Bearer ${accessToken}`,
494
+ "content-type": "application/json",
495
+ accept: "application/json"
496
+ },
497
+ body: JSON.stringify(body),
498
+ maxBytes: MAX_CREDENTIAL_RESPONSE_BYTES
499
+ });
500
+ };
501
+ let res = await requestCredential(await getNonce());
502
+ if (res.status === 400 && oauthErrorOf(res.json) === "invalid_nonce") {
503
+ res = await requestCredential(await getNonce());
504
+ }
505
+ const notificationEndpoint = metadata.notification_endpoint;
506
+ if (res.status === 200) {
507
+ const issued = readCredentialResponse(res.json);
508
+ let verified;
509
+ if (verification) {
510
+ verified = await checkCredential(
511
+ issued.credential,
512
+ verification,
513
+ input.now,
514
+ async () => {
515
+ if (notificationEndpoint && issued.notificationId)
516
+ await sendNotification({
517
+ notificationEndpoint,
518
+ accessToken,
519
+ notificationId: issued.notificationId,
520
+ event: "credential_failure",
521
+ eventDescription: "credential did not verify",
522
+ ...http
523
+ });
524
+ }
525
+ );
526
+ }
527
+ return {
528
+ status: "issued",
529
+ ...issued,
530
+ accessToken,
531
+ ...notificationEndpoint !== void 0 ? { notificationEndpoint } : {},
532
+ ...verified ? { verified } : {}
533
+ };
534
+ }
535
+ if (res.status === 202) {
536
+ const deferredEndpoint = metadata.deferred_credential_endpoint;
537
+ if (deferredEndpoint === void 0)
538
+ throw new Oid4vciError("invalid_metadata");
539
+ return {
540
+ status: "deferred",
541
+ ...readDeferredResponse(res.json),
542
+ accessToken,
543
+ deferredEndpoint,
544
+ ...notificationEndpoint !== void 0 ? { notificationEndpoint } : {},
545
+ verification
546
+ };
547
+ }
548
+ throw refused("issuer_error", res.json);
549
+ }
550
+ async function pollDeferred(input) {
551
+ if (input.verification === void 0 || input.verification === null)
552
+ throw new TypeError(
553
+ "pollDeferred needs the verification from redeemOffer (or false)."
554
+ );
555
+ const http = httpOf(input);
556
+ const body = {
557
+ transaction_id: input.transactionId
558
+ };
559
+ const res = await call(http, input.deferredEndpoint, {
560
+ method: "POST",
561
+ headers: {
562
+ authorization: `Bearer ${input.accessToken}`,
563
+ "content-type": "application/json",
564
+ accept: "application/json"
565
+ },
566
+ body: JSON.stringify(body),
567
+ maxBytes: MAX_CREDENTIAL_RESPONSE_BYTES
568
+ });
569
+ if (res.status === 200) {
570
+ const issued = readCredentialResponse(res.json);
571
+ if (input.verification === false) return { status: "issued", ...issued };
572
+ const verified = await checkCredential(
573
+ issued.credential,
574
+ input.verification,
575
+ input.now,
576
+ () => Promise.resolve()
577
+ );
578
+ return { status: "issued", ...issued, verified };
579
+ }
580
+ if (res.status === 202)
581
+ return { status: "deferred", ...readDeferredResponse(res.json) };
582
+ throw refused("issuer_error", res.json);
583
+ }
584
+ var EVENT_DESCRIPTION = /^[\x20-\x21\x23-\x5b\x5d-\x7e]*$/;
585
+ async function sendNotification(input) {
586
+ if (input.eventDescription !== void 0 && !EVENT_DESCRIPTION.test(input.eventDescription)) {
587
+ throw new TypeError(
588
+ 'eventDescription must be printable ASCII without " and \\'
589
+ );
590
+ }
591
+ const http = httpOf(input);
592
+ const body = {
593
+ notification_id: input.notificationId,
594
+ event: input.event,
595
+ ...input.eventDescription !== void 0 ? { event_description: input.eventDescription } : {}
596
+ };
597
+ const res = await call(http, input.notificationEndpoint, {
598
+ method: "POST",
599
+ headers: {
600
+ authorization: `Bearer ${input.accessToken}`,
601
+ "content-type": "application/json",
602
+ accept: "application/json"
603
+ },
604
+ body: JSON.stringify(body),
605
+ maxBytes: MAX_TOKEN_RESPONSE_BYTES
606
+ });
607
+ if (res.status < 200 || res.status >= 300)
608
+ throw refused("issuer_error", res.json);
609
+ }
610
+
611
+ export { Oid4vciError, authorizationServerMetadataUrl, buildAuthorizationServerMetadata, buildCredentialOffer, buildIssuerMetadata, createProofJwt, fetchCredentialOffer, fetchIssuerMetadata, issuerMetadataUrl, pollDeferred, redeemOffer, sendNotification, validateCredentialOffer, verifyProofJwt };
612
+ //# sourceMappingURL=chunk-FSKCDHZ7.js.map
613
+ //# sourceMappingURL=chunk-FSKCDHZ7.js.map