@moon-x/core 0.2.0 → 0.3.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.
@@ -5,12 +5,7 @@ import {
5
5
  import {
6
6
  PostMessageClient,
7
7
  PostMessageServer
8
- } from "../chunk-SOKLPX7V.mjs";
9
- import {
10
- fromB64url,
11
- toB64url
12
- } from "../chunk-CDT4MC7S.mjs";
13
- import "../chunk-GQKIA37O.mjs";
8
+ } from "../chunk-VVL65GIB.mjs";
14
9
 
15
10
  // src/web/iframe-transport.ts
16
11
  var clientCache = /* @__PURE__ */ new WeakMap();
@@ -49,74 +44,43 @@ var createIframeTransport = ({
49
44
  });
50
45
 
51
46
  // src/web/webauthn-passkey.ts
47
+ import { startAuthentication } from "@simplewebauthn/browser";
52
48
  var createWebAuthnPasskey = () => ({
53
49
  assert: async ({ rpId, challenge }) => {
54
- const challengeBytes = fromB64url(challenge);
55
- const credential = await navigator.credentials.get({
56
- publicKey: {
57
- challenge: challengeBytes,
50
+ const result = await startAuthentication({
51
+ optionsJSON: {
52
+ challenge,
58
53
  rpId,
59
54
  userVerification: "preferred",
60
- // Empty allowCredentials → discoverable login → userHandle is
61
- // REQUIRED on the response. See `parent-passkey-assert.ts`
62
- // for the full rationale.
63
55
  allowCredentials: []
64
56
  }
65
57
  });
66
- if (!credential) throw new Error("passkey_assertion_cancelled");
67
- const assertion = credential.response;
68
- if (!assertion.userHandle) {
58
+ if (!result.response.userHandle) {
69
59
  throw new Error("user_handle_missing");
70
60
  }
71
61
  return {
72
- rawIdB64url: toB64url(new Uint8Array(credential.rawId)),
73
- userHandleB64url: toB64url(new Uint8Array(assertion.userHandle))
62
+ rawIdB64url: result.rawId,
63
+ userHandleB64url: result.response.userHandle
74
64
  };
75
65
  },
76
- create: async ({
77
- rpId,
78
- rpName,
79
- userId,
80
- userName,
81
- userDisplayName,
82
- challenge,
83
- excludeCredentials
84
- }) => {
85
- const challengeBytes = fromB64url(challenge);
86
- const credential = await navigator.credentials.create({
87
- publicKey: {
88
- rp: { id: rpId, name: rpName },
89
- user: {
90
- id: userId,
91
- name: userName,
92
- displayName: userDisplayName
93
- },
94
- challenge: challengeBytes,
95
- pubKeyCredParams: [
96
- { type: "public-key", alg: -7 },
97
- // ES256
98
- { type: "public-key", alg: -257 }
99
- // RS256
100
- ],
101
- authenticatorSelection: {
102
- residentKey: "required",
103
- userVerification: "preferred"
104
- },
105
- excludeCredentials: (excludeCredentials ?? []).map((id) => ({
106
- id: fromB64url(id),
107
- type: "public-key"
108
- }))
109
- }
66
+ assertForServer: async ({ optionsJSON }) => {
67
+ const result = await startAuthentication({
68
+ optionsJSON
110
69
  });
111
- if (!credential) throw new Error("passkey_registration_cancelled");
112
- const attestation = credential.response;
113
- return {
114
- rawIdB64url: toB64url(new Uint8Array(credential.rawId)),
115
- clientDataJSONB64url: toB64url(new Uint8Array(attestation.clientDataJSON)),
116
- attestationObjectB64url: toB64url(
117
- new Uint8Array(attestation.attestationObject)
118
- )
70
+ const sanitized = {
71
+ id: result.id,
72
+ rawId: result.rawId,
73
+ type: result.type,
74
+ response: {
75
+ clientDataJSON: result.response.clientDataJSON,
76
+ authenticatorData: result.response.authenticatorData,
77
+ signature: result.response.signature,
78
+ userHandle: void 0
79
+ },
80
+ clientExtensionResults: result.clientExtensionResults,
81
+ authenticatorAttachment: result.authenticatorAttachment
119
82
  };
83
+ return sanitized;
120
84
  }
121
85
  });
122
86
 
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@moon-x/core",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
+ "license": "UNLICENSED",
4
5
  "main": "dist/index.js",
5
6
  "types": "dist/index.d.ts",
6
7
  "exports": {
@@ -56,12 +57,15 @@
56
57
  "publishConfig": {
57
58
  "access": "public"
58
59
  },
60
+ "dependencies": {
61
+ "@simplewebauthn/browser": "^13.2.2"
62
+ },
59
63
  "devDependencies": {
60
64
  "@testing-library/react": "16.3.2",
61
65
  "@types/react": "19.2.14",
62
66
  "@types/react-dom": "19.2.3",
63
67
  "@vitest/ui": "1.6.1",
64
- "happy-dom": "13.10.1",
68
+ "happy-dom": "20.8.9",
65
69
  "react": "18.3.1",
66
70
  "react-dom": "18.3.1",
67
71
  "tsup": "8.5.1",