Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[passkey] initial draft #474

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[passkey] Add passkey support
  • Loading branch information
alex4506 committed Aug 25, 2024
commit 739ad74f4cb1600b7e8a008cbf816a670722da82
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -56,6 +56,8 @@
"@noble/hashes": "^1.4.0",
"@scure/bip32": "^1.4.0",
"@scure/bip39": "^1.3.0",
"@simplewebauthn/browser": "^10.0.0",
"@simplewebauthn/server": "^10.0.0",
"eventemitter3": "^5.0.1",
"form-data": "^4.0.0",
"js-base64": "^3.7.7",
99 changes: 90 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions src/api/aptos.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { Passkey } from "./passkey";
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { Account } from "./account";
import { ANS } from "./ans";
import { AptosConfig } from "./aptosConfig";
import { Coin } from "./coin";
import { DigitalAsset } from "./digitalAsset";
import { Event } from "./event";
import { Faucet } from "./faucet";
import { FungibleAsset } from "./fungibleAsset";
import { General } from "./general";
import { ANS } from "./ans";
import { Staking } from "./staking";
import { Transaction } from "./transaction";
import { Table } from "./table";
import { Keyless } from "./keyless";
import { AptosObject } from "./object";
import { Staking } from "./staking";
import { Table } from "./table";
import { Transaction } from "./transaction";

/**
* This class is the main entry point into Aptos's
@@ -46,6 +47,8 @@ export class Aptos {

readonly general: General;

readonly passkey: Passkey;

readonly staking: Staking;

readonly transaction: Transaction;
@@ -66,6 +69,7 @@ export class Aptos {
this.faucet = new Faucet(this.config);
this.fungibleAsset = new FungibleAsset(this.config);
this.general = new General(this.config);
this.passkey = new Passkey(this.config);
this.staking = new Staking(this.config);
this.transaction = new Transaction(this.config);
this.table = new Table(this.config);
@@ -85,6 +89,7 @@ export interface Aptos
Faucet,
FungibleAsset,
General,
Passkey,
Keyless,
Staking,
Table,
@@ -120,6 +125,7 @@ applyMixin(Aptos, Event, "event");
applyMixin(Aptos, Faucet, "faucet");
applyMixin(Aptos, FungibleAsset, "fungibleAsset");
applyMixin(Aptos, General, "general");
applyMixin(Aptos, Passkey, "passkey");
applyMixin(Aptos, Staking, "staking");
applyMixin(Aptos, Transaction, "transaction");
applyMixin(Aptos, Table, "table");
77 changes: 77 additions & 0 deletions src/api/passkey.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* eslint-disable class-methods-use-this */
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import type { PublicKeyCredentialCreationOptionsJSON, RegistrationResponseJSON } from "@simplewebauthn/server/esm/deps";
import { AccountAddress, PublicKey } from "../core";
import {
generateRegistrationOptions,
getPasskeyAccountAddress,
parsePublicKey,
registerCredential,
signAndSubmitWithPasskey,
} from "../internal/passkey";
import { AnyRawTransaction } from "../transactions";
import { HexInput, PendingTransactionResponse } from "../types";
import { AllowCredentialOption } from "../types/passkey";
import { AptosConfig } from "./aptosConfig";

/**
* A class for all `Passkeys` related operations on Aptos on the browser.
*/
export class Passkey {
readonly config: AptosConfig;

constructor(config: AptosConfig) {
this.config = config;
}

/**
* Given a credentialId and a transaction, it prompts the client to sign the transaction
*
* @param args.credentialId The credential ID of the passkey
* @param args.publicKey The public key associated with the passkey
* @param args.transaction The transaction to sign
* @returns The pending transaction response
*/
async signAndSubmitWithPasskey(args: {
credentialId: string | Uint8Array;
publicKey: PublicKey;
transaction: AnyRawTransaction;
timeout?: number;
rpID: string;
options?: {
allowCredentials?: AllowCredentialOption[];
};
}): Promise<PendingTransactionResponse> {
return signAndSubmitWithPasskey({ aptosConfig: this.config, ...args });
}

async getPasskeyAccountAddress(args: { publicKey: HexInput }): Promise<AccountAddress> {
return getPasskeyAccountAddress(args);
}

async generateRegistrationOptions(args: {
rpName: string;
rpID: string;
userID?: Uint8Array;
userName: string;
challenge?: string | Uint8Array;
userDisplayName?: string;
timeout?: number;
attestationType?: AttestationConveyancePreference;
authenticatorAttachment?: AuthenticatorAttachment;
}): Promise<PublicKeyCredentialCreationOptionsJSON> {
return generateRegistrationOptions(args);
}

async registerCredential(
creationOptionsJSON: PublicKeyCredentialCreationOptionsJSON,
): Promise<RegistrationResponseJSON> {
return registerCredential(creationOptionsJSON);
}

parsePublicKey(response: RegistrationResponseJSON): PublicKey {
return parsePublicKey(response);
}
}
7 changes: 5 additions & 2 deletions src/core/crypto/index.ts
Original file line number Diff line number Diff line change
@@ -2,13 +2,16 @@
// SPDX-License-Identifier: Apache-2.0

export * from "./ed25519";
export * from "./ephemeral";
export * from "./hdKey";
export * from "./keyless";
export * from "./multiEd25519";
export * from "./multiKey";
export * from "./ephemeral";
export * from "./keyless";
export * from "./passkey";
export * from "./privateKey";
export * from "./publicKey";
export * from "./secp256k1";
export * from "./secp256r1";
export * from "./signature";
export * from "./singleKey";
export * from "./webauthn";
Loading