diff --git a/.gitignore b/.gitignore index 211c841..79fccad 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ npm-debug.log* yarn-debug.log* yarn-error.log* lerna-debug.log* -.idea # Diagnostic reports (https://nodejs.org/api/report.html) report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json @@ -82,7 +81,7 @@ web_modules/ # Nuxt.js build / generate output .nuxt -dist +# dist # Gatsby files .cache/ @@ -115,8 +114,8 @@ dist .yarn/build-state.yml .pnp.* -build -prebuilds +# build +# prebuilds # Mac storage .DS_Store diff --git a/.gitignore.prebuild b/.gitignore.main similarity index 98% rename from .gitignore.prebuild rename to .gitignore.main index 79fccad..211c841 100644 --- a/.gitignore.prebuild +++ b/.gitignore.main @@ -5,6 +5,7 @@ npm-debug.log* yarn-debug.log* yarn-error.log* lerna-debug.log* +.idea # Diagnostic reports (https://nodejs.org/api/report.html) report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json @@ -81,7 +82,7 @@ web_modules/ # Nuxt.js build / generate output .nuxt -# dist +dist # Gatsby files .cache/ @@ -114,8 +115,8 @@ web_modules/ .yarn/build-state.yml .pnp.* -# build -# prebuilds +build +prebuilds # Mac storage .DS_Store diff --git a/dist/demo/electron-demo.d.ts b/dist/demo/electron-demo.d.ts new file mode 100644 index 0000000..de804c3 --- /dev/null +++ b/dist/demo/electron-demo.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=electron-demo.d.ts.map \ No newline at end of file diff --git a/dist/demo/electron-demo.d.ts.map b/dist/demo/electron-demo.d.ts.map new file mode 100644 index 0000000..edc3513 --- /dev/null +++ b/dist/demo/electron-demo.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"electron-demo.d.ts","sourceRoot":"","sources":["../../src/demo/electron-demo.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/demo/electron-demo.js b/dist/demo/electron-demo.js new file mode 100644 index 0000000..40e6e7b --- /dev/null +++ b/dist/demo/electron-demo.js @@ -0,0 +1,30 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const path_1 = require("path"); +const electron_1 = require("electron"); +const __1 = __importDefault(require("..")); +// https://github.com/electron/electron/issues/25153 +// app.disableHardwareAcceleration(); +__1.default.getInstance().attachHandlersToMain('google.com', electron_1.ipcMain); +let window; +function createWindow() { + window = new electron_1.BrowserWindow({ + width: 1400, + height: 900, + webPreferences: { + nodeIntegration: true, + contextIsolation: false, + preload: (0, path_1.join)(__dirname, 'preload.js'), + }, + }); + window.loadURL('https://thirdweb.com/login?next=%2Fdashboard%2Fconnect%2Fin-app-wallets'); + window.webContents.openDevTools(); + console.log(__1.default.getPackageName()); +} +electron_1.app.on('ready', () => { + setTimeout(createWindow, 500); +}); +//# sourceMappingURL=electron-demo.js.map \ No newline at end of file diff --git a/dist/demo/electron-demo.js.map b/dist/demo/electron-demo.js.map new file mode 100644 index 0000000..eb1ad18 --- /dev/null +++ b/dist/demo/electron-demo.js.map @@ -0,0 +1 @@ +{"version":3,"file":"electron-demo.js","sourceRoot":"","sources":["../../src/demo/electron-demo.ts"],"names":[],"mappings":";;;;;AAAA,+BAA4B;AAC5B,uCAAuD;AACvD,2CAAyB;AAEzB,oDAAoD;AACpD,qCAAqC;AAErC,WAAO,CAAC,WAAW,EAAE,CAAC,oBAAoB,CAAC,YAAY,EAAE,kBAAO,CAAC,CAAC;AAElE,IAAI,MAAqB,CAAC;AAE1B,SAAS,YAAY;IACnB,MAAM,GAAG,IAAI,wBAAa,CAAC;QACzB,KAAK,EAAE,IAAI;QACX,MAAM,EAAE,GAAG;QACX,cAAc,EAAE;YACd,eAAe,EAAE,IAAI;YACrB,gBAAgB,EAAE,KAAK;YACvB,OAAO,EAAE,IAAA,WAAI,EAAC,SAAS,EAAE,YAAY,CAAC;SACvC;KACF,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CACZ,yEAAyE,CAC1E,CAAC;IAEF,MAAM,CAAC,WAAW,CAAC,YAAY,EAAE,CAAC;IAElC,OAAO,CAAC,GAAG,CAAC,WAAO,CAAC,cAAc,EAAE,CAAC,CAAC;AACxC,CAAC;AAED,cAAG,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;IACnB,UAAU,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC;AAChC,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/demo/preload.d.ts b/dist/demo/preload.d.ts new file mode 100644 index 0000000..d5a3c49 --- /dev/null +++ b/dist/demo/preload.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=preload.d.ts.map \ No newline at end of file diff --git a/dist/demo/preload.d.ts.map b/dist/demo/preload.d.ts.map new file mode 100644 index 0000000..dbccddb --- /dev/null +++ b/dist/demo/preload.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"preload.d.ts","sourceRoot":"","sources":["../../src/demo/preload.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/demo/preload.js b/dist/demo/preload.js new file mode 100644 index 0000000..adee99a --- /dev/null +++ b/dist/demo/preload.js @@ -0,0 +1,10 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const electron_1 = require("electron"); +const __1 = __importDefault(require("..")); +navigator.credentials.create = (options) => __1.default.getInstance().attachCreateToRenderer(electron_1.ipcRenderer, options); +navigator.credentials.get = (options) => __1.default.getInstance().attachGetToRenderer(electron_1.ipcRenderer, options); +//# sourceMappingURL=preload.js.map \ No newline at end of file diff --git a/dist/demo/preload.js.map b/dist/demo/preload.js.map new file mode 100644 index 0000000..be7bcde --- /dev/null +++ b/dist/demo/preload.js.map @@ -0,0 +1 @@ +{"version":3,"file":"preload.js","sourceRoot":"","sources":["../../src/demo/preload.ts"],"names":[],"mappings":";;;;;AAAA,uCAAuC;AACvC,2CAAyB;AAEzB,SAAS,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,OAAO,EAAE,EAAE,CACzC,WAAO,CAAC,WAAW,EAAE,CAAC,sBAAsB,CAAC,sBAAW,EAAE,OAAO,CAAC,CAAC;AACrE,SAAS,CAAC,WAAW,CAAC,GAAG,GAAG,CAAC,OAAO,EAAE,EAAE,CACtC,WAAO,CAAC,WAAW,EAAE,CAAC,mBAAmB,CAAC,sBAAW,EAAE,OAAO,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..032df0a --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,17 @@ +import type { IpcMain, IpcRenderer } from 'electron'; +declare class Passkey { + private static instance; + private handler; + private platform; + private domain; + private constructor(); + static getInstance(): Passkey; + private handlePasskeyCreate; + private handlePasskeyGet; + attachCreateToRenderer(ipcRenderer: IpcRenderer, options: any): Promise; + attachGetToRenderer(ipcRenderer: IpcRenderer, options: any): Promise; + attachHandlersToMain(domain: string, ipcMain: IpcMain): void; + static getPackageName(): string; +} +export = Passkey; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/index.d.ts.map b/dist/index.d.ts.map new file mode 100644 index 0000000..4ca81a9 --- /dev/null +++ b/dist/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAYrD,cAAM,OAAO;IAEX,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAU;IAEjC,OAAO,CAAC,OAAO,CAAiB;IAEhC,OAAO,CAAC,QAAQ,CAAiB;IAEjC,OAAO,CAAC,MAAM,CAAc;IAE5B,OAAO;IAKP,MAAM,CAAC,WAAW,IAAI,OAAO;IAO7B,OAAO,CAAC,mBAAmB;IAoB3B,OAAO,CAAC,gBAAgB;IAWlB,sBAAsB,CAC1B,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,GAAG,GACX,OAAO,CAAC,mBAAmB,CAAC;IAQzB,mBAAmB,CACvB,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,GAAG,GACX,OAAO,CAAC,mBAAmB,CAAC;IAQ/B,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAW5D,MAAM,CAAC,cAAc,IAAI,MAAM;CAGhC;AAED,SAAS,OAAO,CAAC"} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js new file mode 100644 index 0000000..ef886a9 --- /dev/null +++ b/dist/index.js @@ -0,0 +1,59 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +const node_path_1 = require("node:path"); +const node_os_1 = __importDefault(require("node:os")); +const utils_1 = require("./utils"); +const lib = require('node-gyp-build')((0, node_path_1.join)(__dirname, '..')); +class Passkey { + constructor() { + this.platform = node_os_1.default.platform(); + this.domain = ''; + this.handler = new lib.PasskeyHandler(); // Create an instance of PasskeyHandler + } + // Singleton pattern: ensures only one instance is created + static getInstance() { + if (!Passkey.instance) { + Passkey.instance = new Passkey(); + } + return Passkey.instance; + } + handlePasskeyCreate(options) { + if (this.platform !== 'darwin') { + throw new Error(`electron-passkey is meant for macOS only and should NOT be run on ${this.platform}`); + } + options.publicKey.challenge = (0, utils_1.arrayBufferToBase64)(options.publicKey.challenge); + options.publicKey.rp.id = + this.domain; + options.publicKey.user.id = + (0, utils_1.arrayBufferToBase64)(options.publicKey.user + .id); + return this.handler.HandlePasskeyCreate(JSON.stringify(options)); + } + handlePasskeyGet(options) { + if (this.platform !== 'darwin') { + throw new Error(`electron-passkey is meant for macOS only and should NOT be run on ${this.platform}`); + } + options.publicKey.rpId = this.domain; + return this.handler.HandlePasskeyGet(JSON.stringify(options)); + } + async attachCreateToRenderer(ipcRenderer, options) { + const rawString = await ipcRenderer.invoke(utils_1.PassKeyMethods.createPasskey, options); + return (0, utils_1.mapPublicKey)(rawString, true); + } + async attachGetToRenderer(ipcRenderer, options) { + const rawString = await ipcRenderer.invoke(utils_1.PassKeyMethods.getPasskey, options); + return (0, utils_1.mapPublicKey)(rawString, false); + } + attachHandlersToMain(domain, ipcMain) { + this.domain = domain; + ipcMain.handle(utils_1.PassKeyMethods.createPasskey, (_event, options) => this.handlePasskeyCreate(options)); + ipcMain.handle(utils_1.PassKeyMethods.getPasskey, (_event, options) => this.handlePasskeyGet(options)); + } + static getPackageName() { + return 'electron-passkey'; + } +} +module.exports = Passkey; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/index.js.map b/dist/index.js.map new file mode 100644 index 0000000..2872406 --- /dev/null +++ b/dist/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,yCAAiC;AACjC,sDAAyB;AASzB,mCAA4E;AAE5E,MAAM,GAAG,GAAqB,OAAO,CAAC,gBAAgB,CAAC,CAAC,IAAA,gBAAI,EAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;AAE/E,MAAM,OAAO;IAUX;QAJQ,aAAQ,GAAG,iBAAE,CAAC,QAAQ,EAAE,CAAC;QAEzB,WAAM,GAAW,EAAE,CAAC;QAG1B,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,CAAC,cAAc,EAAE,CAAC,CAAC,uCAAuC;IAClF,CAAC;IAED,0DAA0D;IAC1D,MAAM,CAAC,WAAW;QAChB,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YACtB,OAAO,CAAC,QAAQ,GAAG,IAAI,OAAO,EAAE,CAAC;QACnC,CAAC;QACD,OAAO,OAAO,CAAC,QAAQ,CAAC;IAC1B,CAAC;IAEO,mBAAmB,CAAC,OAAuB;QACjD,IAAI,IAAI,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CACb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BAAY,EAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC;IAED,oBAAoB,CAAC,MAAc,EAAE,OAAgB;QACnD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,OAAO,CAAC,MAAM,CAAC,sBAAc,CAAC,aAAa,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAC/D,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAClC,CAAC;QACF,OAAO,CAAC,MAAM,CAAC,sBAAc,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAC5D,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAC/B,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,cAAc;QACnB,OAAO,kBAAkB,CAAC;IAC5B,CAAC;CACF;AAED,iBAAS,OAAO,CAAC"} \ No newline at end of file diff --git a/dist/types.d.ts b/dist/types.d.ts new file mode 100644 index 0000000..4efd217 --- /dev/null +++ b/dist/types.d.ts @@ -0,0 +1,51 @@ +export interface PublicKeyCredentialCreationOptions { + rp: { + id: string; + name: string; + }; + user: { + id: ArrayBuffer | string; + name: string; + displayName: string; + }; + challenge: ArrayBuffer | string; + pubKeyCredParams: Array<{ + type: string; + alg: number; + }>; + timeout?: number; + authenticatorSelection?: { + authenticatorAttachment?: 'platform' | 'cross-platform'; + requireResidentKey?: boolean; + userVerification?: 'required' | 'preferred' | 'discouraged'; + }; + attestation?: 'none' | 'indirect' | 'direct' | 'enterprise'; + extensions?: AuthenticationExtensionsClientInputs; +} +type ExtendedAuthenticatorTransport = AuthenticatorTransport | 'smart-card'; +interface CredentialDescriptor { + id: string; + transports: ExtendedAuthenticatorTransport[]; +} +export interface PublicKeyCredentialRequestOptions { + rpId?: string; + challenge: Buffer; + allowCredentials?: Array; + userVerification?: 'required' | 'preferred' | 'discouraged'; + timeout?: number; + extensions?: AuthenticationExtensionsClientInputs; +} +export interface PasskeyOptions { + publicKey: PublicKeyCredentialCreationOptions | PublicKeyCredentialRequestOptions; + mediation?: 'conditional'; + signal?: AbortSignal; +} +export interface PasskeyHandler { + HandlePasskeyCreate(options: string): Promise; + HandlePasskeyGet(options: string): Promise; +} +export interface PasskeyInterface { + PasskeyHandler: new () => PasskeyHandler; +} +export {}; +//# sourceMappingURL=types.d.ts.map \ No newline at end of file diff --git a/dist/types.d.ts.map b/dist/types.d.ts.map new file mode 100644 index 0000000..03cc98c --- /dev/null +++ b/dist/types.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kCAAkC;IACjD,EAAE,EAAE;QACF,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,IAAI,EAAE;QACJ,EAAE,EAAE,WAAW,GAAG,MAAM,CAAC;QACzB,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,SAAS,EAAE,WAAW,GAAG,MAAM,CAAC;IAChC,gBAAgB,EAAE,KAAK,CAAC;QACtB,IAAI,EAAE,MAAM,CAAC;QACb,GAAG,EAAE,MAAM,CAAC;KACb,CAAC,CAAC;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sBAAsB,CAAC,EAAE;QACvB,uBAAuB,CAAC,EAAE,UAAU,GAAG,gBAAgB,CAAC;QACxD,kBAAkB,CAAC,EAAE,OAAO,CAAC;QAC7B,gBAAgB,CAAC,EAAE,UAAU,GAAG,WAAW,GAAG,aAAa,CAAC;KAC7D,CAAC;IACF,WAAW,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,QAAQ,GAAG,YAAY,CAAC;IAC5D,UAAU,CAAC,EAAE,oCAAoC,CAAC;CACnD;AAED,KAAK,8BAA8B,GAAG,sBAAsB,GAAG,YAAY,CAAC;AAE5E,UAAU,oBAAoB;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,8BAA8B,EAAE,CAAC;CAC9C;AAED,MAAM,WAAW,iCAAiC;IAChD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,KAAK,CAAC,oBAAoB,CAAC,CAAC;IAC/C,gBAAgB,CAAC,EAAE,UAAU,GAAG,WAAW,GAAG,aAAa,CAAC;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,oCAAoC,CAAC;CACnD;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,EACL,kCAAkC,GAClC,iCAAiC,CAAC;IACtC,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,cAAc;IAC7B,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACtD,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACpD;AAED,MAAM,WAAW,gBAAgB;IAC/B,cAAc,EAAE,UAAU,cAAc,CAAC;CAC1C"} \ No newline at end of file diff --git a/dist/types.js b/dist/types.js new file mode 100644 index 0000000..11e638d --- /dev/null +++ b/dist/types.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=types.js.map \ No newline at end of file diff --git a/dist/types.js.map b/dist/types.js.map new file mode 100644 index 0000000..c768b79 --- /dev/null +++ b/dist/types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/utils.d.ts b/dist/utils.d.ts new file mode 100644 index 0000000..8682b40 --- /dev/null +++ b/dist/utils.d.ts @@ -0,0 +1,8 @@ +export declare function arrayBufferToBase64(buffer: ArrayBuffer): string; +export declare function base64ToArrayBuffer(base64: string): ArrayBuffer; +export declare function mapPublicKey(rawString: string, isCreate: boolean): PublicKeyCredential; +export declare enum PassKeyMethods { + createPasskey = "create-passkey", + getPasskey = "get-passkey" +} +//# sourceMappingURL=utils.d.ts.map \ No newline at end of file diff --git a/dist/utils.d.ts.map b/dist/utils.d.ts.map new file mode 100644 index 0000000..ab98195 --- /dev/null +++ b/dist/utils.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAQ/D;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAQ/D;AAWD,wBAAgB,YAAY,CAC1B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,OAAO,GAChB,mBAAmB,CAgGrB;AAED,oBAAY,cAAc;IACxB,aAAa,mBAAmB;IAChC,UAAU,gBAAgB;CAC3B"} \ No newline at end of file diff --git a/dist/utils.js b/dist/utils.js new file mode 100644 index 0000000..3bcff62 --- /dev/null +++ b/dist/utils.js @@ -0,0 +1,116 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.PassKeyMethods = void 0; +exports.arrayBufferToBase64 = arrayBufferToBase64; +exports.base64ToArrayBuffer = base64ToArrayBuffer; +exports.mapPublicKey = mapPublicKey; +function arrayBufferToBase64(buffer) { + let binary = ''; + const bytes = new Uint8Array(buffer); + const len = bytes.byteLength; + for (let i = 0; i < len; i += 1) { + binary += String.fromCharCode(bytes[i]); + } + return btoa(binary); +} +function base64ToArrayBuffer(base64) { + const binaryString = atob(base64); + const len = binaryString.length; + const bytes = new Uint8Array(len); + for (let i = 0; i < len; i += 1) { + bytes[i] = binaryString.charCodeAt(i); + } + return bytes.buffer; +} +function parseBuffer(buffer) { + return String.fromCharCode(...new Uint8Array(buffer)); +} +function toBase64url(buffer) { + const txt = btoa(parseBuffer(buffer)); + return txt.replaceAll('+', '-').replaceAll('/', '_'); +} +function mapPublicKey(rawString, isCreate) { + const raw = JSON.parse(rawString); + const mapped = { ...raw }; + mapped.rawId = base64ToArrayBuffer(raw.id); + mapped.getClientExtensionResults = () => raw.clientExtensionResults; + const { response } = raw; + if (isCreate) { + mapped.response.clientDataJSON = base64ToArrayBuffer(mapped.response.clientDataJSON); + mapped.response.attestationObject = base64ToArrayBuffer(mapped.response.attestationObject); + mapped.response = { + ...response, + getAuthenticatorData() { + // Extract authenticator data from attestationObject + const cborData = new Uint8Array(this.attestationObject); + // Example: Assume authenticator data starts at byte 0 + const authenticatorData = cborData.subarray(0, 37); // Adjust length as needed + return authenticatorData.buffer; + }, + getPublicKey() { + // Extract public key from attestationObject + const cborData = new Uint8Array(this.attestationObject); + // Example: Assume public key starts at byte 37 + const publicKeyData = cborData.subarray(37, 69); // Adjust length as needed + return publicKeyData.buffer; + }, + getPublicKeyAlgorithm() { + // Return a dummy COSE algorithm identifier (e.g., -7 for ES256) + return -7; + }, + getTransports() { + // Return an empty array or fetch actual transports from rawJson if available + return raw.transports || []; + }, + }; + mapped.response.toJson = () => { + return { + type: raw.type, + id: raw.id, + rawId: mapped.rawId, // Same as ID, but useful in tests + authenticatorAttachment: raw.authenticatorAttachment, + clientExtensionResults: raw.getClientExtensionResults(), + response: { + attestationObject: toBase64url(response.attestationObject), + authenticatorData: toBase64url(response.getAuthenticatorData()), + clientDataJSON: toBase64url(response.clientDataJSON), + publicKey: toBase64url(response.getPublicKey()), + publicKeyAlgorithm: response.getPublicKeyAlgorithm(), + transports: response.getTransports(), + }, + }; + }; + } + else { + mapped.response.clientDataJSON = base64ToArrayBuffer(mapped.response.clientDataJSON); + mapped.response.authenticatorData = base64ToArrayBuffer(mapped.response.authenticatorData); + mapped.response.signature = base64ToArrayBuffer(mapped.response.signature); + if (mapped.response.userHandle) { + mapped.response.userHandle = base64ToArrayBuffer(mapped.response.userHandle); + } + mapped.response.toJson = () => { + return { + clientExtensionResults: raw.getClientExtensionResults(), + id: raw.id, + rawId: mapped.rawId, + type: raw.type, + authenticatorAttachment: raw.authenticatorAttachment, + response: { + authenticatorData: toBase64url(response.authenticatorData), + clientDataJSON: toBase64url(response.clientDataJSON), + signature: toBase64url(response.signature), + userHandle: response.userHandle + ? toBase64url(response.userHandle) + : undefined, + }, + }; + }; + } + return mapped; +} +var PassKeyMethods; +(function (PassKeyMethods) { + PassKeyMethods["createPasskey"] = "create-passkey"; + PassKeyMethods["getPasskey"] = "get-passkey"; +})(PassKeyMethods || (exports.PassKeyMethods = PassKeyMethods = {})); +//# sourceMappingURL=utils.js.map \ No newline at end of file diff --git a/dist/utils.js.map b/dist/utils.js.map new file mode 100644 index 0000000..2bbeb59 --- /dev/null +++ b/dist/utils.js.map @@ -0,0 +1 @@ +{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,kDAQC;AAED,kDAQC;AAWD,oCAmGC;AAhID,SAAgB,mBAAmB,CAAC,MAAmB;IACrD,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IACrC,MAAM,GAAG,GAAG,KAAK,CAAC,UAAU,CAAC;IAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;AACtB,CAAC;AAED,SAAgB,mBAAmB,CAAC,MAAc;IAChD,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IAClC,MAAM,GAAG,GAAG,YAAY,CAAC,MAAM,CAAC;IAChC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;IAClC,KAAK,IAAI,CAAC,GAAG,CAAC,E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ACF,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,kDAAgC,CAAA;IAChC,4CAA0B,CAAA;AAC5B,CAAC,EAHW,cAAc,8BAAd,cAAc,QAGzB"} \ No newline at end of file diff --git a/prebuilds/darwin-arm64/electron-passkey.node b/prebuilds/darwin-arm64/electron-passkey.node new file mode 100644 index 0000000..ac9f108 Binary files /dev/null and b/prebuilds/darwin-arm64/electron-passkey.node differ diff --git a/prebuilds/darwin-x64/electron-passkey.node b/prebuilds/darwin-x64/electron-passkey.node new file mode 100644 index 0000000..e5e35ce Binary files /dev/null and b/prebuilds/darwin-x64/electron-passkey.node differ