passkey-kit 0.0.1 → 0.0.2

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.
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
@@ -1,169 +0,0 @@
1
- <script lang="ts">
2
- import { PasskeyAccount } from "passkey-kit";
3
- import { Networks, Transaction } from "@stellar/stellar-sdk";
4
- import base64url from "base64url";
5
- import { Buffer } from "buffer";
6
- import { fund, getBalance, transfer } from "./lib/account";
7
- import { sequenceKeypair } from "./lib/common";
8
- import { arraysEqual } from "./lib/utils";
9
-
10
- let walletData: Map<string, any> = new Map();
11
- let contractId: string;
12
- let balance: string;
13
-
14
- const account = new PasskeyAccount({
15
- sequencePublicKey: sequenceKeypair.publicKey(),
16
- networkPassphrase: import.meta.env.VITE_networkPassphrase as Networks,
17
- horizonUrl: import.meta.env.VITE_horizonUrl,
18
- rpcUrl: import.meta.env.VITE_rpcUrl,
19
- feeBumpUrl: import.meta.env.VITE_feeBumpUrl,
20
- feeBumpJwt: import.meta.env.VITE_feeBumpJwt,
21
- });
22
-
23
- async function register() {
24
- const user = prompt("Give this passkey a name");
25
-
26
- if (!user) return;
27
-
28
- const { contractId: cid, xdr } = await account.createWallet("Super Peach", user);
29
-
30
- const txn = new Transaction(xdr, import.meta.env.VITE_networkPassphrase)
31
-
32
- txn.sign(sequenceKeypair);
33
-
34
- const res = await account.send(txn);
35
-
36
- contractId = cid;
37
- console.log(contractId);
38
- console.log(res);
39
- }
40
- async function signIn() {
41
- contractId = await account.connectWallet();
42
- console.log(contractId);
43
- }
44
- async function addSigner() {
45
- /* TODO
46
- - Add existing signer vs always creating a new one
47
- Will require a lookup onchain for the existing passkey public key on an existing wallet
48
- I also think this currently will require removing that signer from its current wallet in order to add it as a signer to an alternative wallet
49
- @Later
50
- */
51
-
52
- const user = prompt("Give this passkey a name");
53
-
54
- if (!user) return;
55
-
56
- const { keyId, publicKey } = await account.createKey("Super Peach", user);
57
-
58
- const { built } = await account.wallet!.add_sig({
59
- id: keyId,
60
- pk: publicKey!,
61
- });
62
-
63
- // xdr to txn funk due to TypeError: XDR Write Error: [object Object] is not a DecoratedSignature
64
- const xdr = await account.sign(built!, { id: 'sudo' });
65
- const txn = new Transaction(xdr, import.meta.env.VITE_networkPassphrase)
66
-
67
- txn.sign(sequenceKeypair);
68
-
69
- const res = await account.send(txn);
70
-
71
- console.log(res);
72
- }
73
- async function removeSigner(signer: Uint8Array) {
74
- const { built } = await account.wallet!.rm_sig({
75
- id: Buffer.from(signer),
76
- });
77
-
78
- const xdr = await account.sign(built!, { id: 'sudo' });
79
- const txn = new Transaction(xdr, import.meta.env.VITE_networkPassphrase)
80
-
81
- txn.sign(sequenceKeypair);
82
-
83
- const res = await account.send(txn);
84
-
85
- console.log(res);
86
- }
87
- async function resudo(signer: Uint8Array) {
88
- const { built } = await account.wallet!.resudo({
89
- id: Buffer.from(signer)
90
- });
91
-
92
- const xdr = await account.sign(built!, { id: "sudo" });
93
- const txn = new Transaction(xdr, import.meta.env.VITE_networkPassphrase)
94
-
95
- txn.sign(sequenceKeypair);
96
-
97
- const res = await account.send(txn);
98
-
99
- console.log(res);
100
-
101
- // update the sudo signer
102
- account.sudo = base64url(signer);
103
- }
104
-
105
- async function getWalletData() {
106
- walletData = await account.getData();
107
- }
108
- async function fundWallet() {
109
- const res = await fund(contractId);
110
- console.log(res);
111
- }
112
- async function getWalletBalance() {
113
- balance = await getBalance(contractId);
114
- console.log(balance);
115
- }
116
- async function walletTransfer(signer: Uint8Array) {
117
- const built = await transfer(
118
- contractId,
119
- account.factory.options.contractId,
120
- );
121
-
122
- const xdr = await account.sign(built, { id: signer });
123
- const txn = new Transaction(xdr, import.meta.env.VITE_networkPassphrase)
124
-
125
- txn.sign(sequenceKeypair);
126
-
127
- const res = await account.send(txn);
128
-
129
- console.log(res);
130
- }
131
- </script>
132
-
133
- <main>
134
- <button on:click={register}>Register</button>
135
- <button on:click={signIn}>Sign In</button>
136
-
137
- {#if contractId}
138
- <p>{contractId}</p>
139
-
140
- {#if balance}
141
- <p>{parseFloat((Number(balance) / 10_000_000).toFixed(7))} XLM</p>
142
- {/if}
143
-
144
- <button on:click={fundWallet}>Add Funds</button>
145
- <button on:click={getWalletBalance}>Get Balance</button>
146
- <button on:click={getWalletData}>Get Wallet Data</button>
147
- <button on:click={addSigner}>Add Signer</button>
148
- {/if}
149
-
150
- <ul>
151
- {#each walletData.size ? walletData.get("sigs") : [] as signer}
152
- <li>
153
- {base64url(signer)}
154
-
155
- <button on:click={() => walletTransfer(signer)}>Transfer 1 XLM</button
156
- >
157
-
158
- {#if walletData.size && !arraysEqual(signer, walletData.get("sudo_sig"))}
159
- <button on:click={() => resudo(signer)}>Make Sudo</button>
160
- <button on:click={() => removeSigner(signer)}>Remove</button
161
- >
162
- {/if}
163
- </li>
164
- {/each}
165
- </ul>
166
- </main>
167
-
168
- <style>
169
- </style>
package/demo/src/app.css DELETED
@@ -1,14 +0,0 @@
1
- :root {
2
- font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
3
- line-height: 1.5;
4
- font-weight: 400;
5
-
6
- color-scheme: light dark;
7
- color: rgba(255, 255, 255, 0.87);
8
- background-color: #242424;
9
-
10
- font-synthesis: none;
11
- text-rendering: optimizeLegibility;
12
- -webkit-font-smoothing: antialiased;
13
- -moz-osx-font-smoothing: grayscale;
14
- }
@@ -1,81 +0,0 @@
1
- import { xdr, Account, Operation, SorobanRpc, TransactionBuilder, nativeToScVal, scValToNative } from '@stellar/stellar-sdk'
2
- import { rpc, horizon, fundKeypair, fundPubkey, sequencePubkey } from './common'
3
-
4
- export async function fund(to: string) {
5
- const account = await rpc.getAccount(fundPubkey).then((res) => new Account(res.accountId(), res.sequenceNumber()))
6
-
7
- const simTxn = new TransactionBuilder(account, {
8
- fee: (10_000_000).toString(),
9
- networkPassphrase: import.meta.env.VITE_networkPassphrase
10
- })
11
- .addOperation(Operation.invokeContractFunction({
12
- contract: import.meta.env.VITE_nativeContractId,
13
- function: 'transfer',
14
- args: [
15
- nativeToScVal(fundPubkey, { type: 'address' }),
16
- nativeToScVal(to, { type: 'address' }),
17
- nativeToScVal(100 * 10_000_000, { type: 'i128' })
18
- ]
19
- }))
20
- .setTimeout(0)
21
- .build()
22
-
23
- const sim = await rpc.simulateTransaction(simTxn)
24
-
25
- if (
26
- SorobanRpc.Api.isSimulationError(sim)
27
- || SorobanRpc.Api.isSimulationRestore(sim)
28
- ) throw sim
29
-
30
- const transaction = SorobanRpc
31
- .assembleTransaction(simTxn, sim)
32
- .build()
33
-
34
- transaction.sign(fundKeypair)
35
-
36
- return horizon.submitTransaction(transaction)
37
- }
38
-
39
- export async function getBalance(id: string) {
40
- const val = xdr.ScVal.scvVec([
41
- nativeToScVal('Balance', { type: 'symbol' }),
42
- nativeToScVal(id, { type: 'address' }),
43
- ])
44
-
45
- const { amount } = await rpc
46
- .getContractData(import.meta.env.VITE_nativeContractId, val)
47
- .then((res) => scValToNative(res.val.contractData().val()))
48
-
49
- return (amount as BigInt).toString()
50
- }
51
-
52
- export async function transfer(from: string, to: string, amount: number = 10_000_000) {
53
- const account = await rpc.getAccount(sequencePubkey).then((res) => new Account(res.accountId(), res.sequenceNumber()))
54
-
55
- const simTxn = new TransactionBuilder(account, {
56
- fee: '0',
57
- networkPassphrase: import.meta.env.VITE_networkPassphrase
58
- })
59
- .addOperation(Operation.invokeContractFunction({
60
- contract: import.meta.env.VITE_nativeContractId,
61
- function: 'transfer',
62
- args: [
63
- nativeToScVal(from, { type: 'address' }),
64
- nativeToScVal(to, { type: 'address' }),
65
- nativeToScVal(amount, { type: 'i128' })
66
- ]
67
- }))
68
- .setTimeout(0)
69
- .build()
70
-
71
- const sim = await rpc.simulateTransaction(simTxn)
72
-
73
- if (
74
- SorobanRpc.Api.isSimulationError(sim)
75
- || SorobanRpc.Api.isSimulationRestore(sim)
76
- ) throw sim
77
-
78
- const authTxn = SorobanRpc.assembleTransaction(simTxn, sim).build()
79
-
80
- return authTxn
81
- }
@@ -1,10 +0,0 @@
1
- import { Horizon, Keypair, SorobanRpc } from "@stellar/stellar-sdk"
2
-
3
- export const rpc = new SorobanRpc.Server(import.meta.env.VITE_rpcUrl);
4
- export const horizon = new Horizon.Server(import.meta.env.VITE_horizonUrl)
5
-
6
- export const sequenceKeypair = Keypair.fromSecret(import.meta.env.VITE_sequenceSecret);
7
- export const sequencePubkey = sequenceKeypair.publicKey()
8
-
9
- export const fundKeypair = Keypair.fromSecret(import.meta.env.VITE_fundSecret)
10
- export const fundPubkey = fundKeypair.publicKey()
@@ -1,6 +0,0 @@
1
- export function arraysEqual(arr1: Uint8Array, arr2: Uint8Array) {
2
- return (
3
- arr1?.length === arr2?.length &&
4
- arr1.every((value, index) => value === arr2[index])
5
- );
6
- }
package/demo/src/main.ts DELETED
@@ -1,15 +0,0 @@
1
- import './app.css'
2
- import App from './App.svelte'
3
- import { fundPubkey, rpc } from './lib/common'
4
-
5
- (async () => {
6
- try {
7
- await rpc.requestAirdrop(fundPubkey)
8
- } catch {}
9
- })()
10
-
11
- const app = new App({
12
- target: document.getElementById('app')!,
13
- })
14
-
15
- export default app
@@ -1,17 +0,0 @@
1
- /// <reference types="svelte" />
2
- /// <reference types="vite/client" />
3
-
4
- interface ImportMetaEnv {
5
- readonly VITE_networkPassphrase: string;
6
- readonly VITE_nativeContractId: string;
7
- readonly VITE_rpcUrl: string;
8
- readonly VITE_horizonUrl: string;
9
- readonly VITE_fundSecret: string;
10
- readonly VITE_sequenceSecret: string;
11
- readonly VITE_feeBumpUrl: string;
12
- readonly VITE_feeBumpJwt: string;
13
- }
14
-
15
- interface ImportMeta {
16
- readonly env: ImportMetaEnv;
17
- }
@@ -1,7 +0,0 @@
1
- import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
2
-
3
- export default {
4
- // Consult https://svelte.dev/docs#compile-time-svelte-preprocess
5
- // for more information about preprocessors
6
- preprocess: vitePreprocess(),
7
- }
@@ -1,22 +0,0 @@
1
- {
2
- "extends": "@tsconfig/svelte/tsconfig.json",
3
- "compilerOptions": {
4
- "target": "ESNext",
5
- "useDefineForClassFields": true,
6
- "module": "ESNext",
7
- "resolveJsonModule": true,
8
- /**
9
- * Typecheck JS in `.svelte` and `.js` files by default.
10
- * Disable checkJs if you'd like to use dynamic types in JS.
11
- * Note that setting allowJs false does not prevent the use
12
- * of JS in `.svelte` files.
13
- */
14
- "allowJs": true,
15
- "checkJs": true,
16
- "isolatedModules": true,
17
- // "types": ["src/passkey-key"]
18
- },
19
- // "exclude": ["src/passkey-kit/**/*"],
20
- "include": ["src/**/*.ts", "src/**/*.js", "src/**/*.svelte"],
21
- "references": [{ "path": "./tsconfig.node.json" }]
22
- }
@@ -1,10 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "composite": true,
4
- "skipLibCheck": true,
5
- "module": "ESNext",
6
- "moduleResolution": "bundler",
7
- "strict": true
8
- },
9
- "include": ["vite.config.ts"]
10
- }
@@ -1,7 +0,0 @@
1
- import { defineConfig } from 'vite'
2
- import { svelte } from '@sveltejs/vite-plugin-svelte'
3
-
4
- // https://vitejs.dev/config/
5
- export default defineConfig({
6
- plugins: [svelte()],
7
- })
package/esbuild.js DELETED
@@ -1,20 +0,0 @@
1
- import { build } from 'esbuild'
2
- import fs from 'fs'
3
- // import { polyfillNode } from "esbuild-plugin-polyfill-node";
4
-
5
- const result = await build({
6
- metafile: true,
7
- bundle: true,
8
- format: 'esm',
9
- charset: 'utf8',
10
- outdir: 'passkey-kit',
11
- entryPoints: ['src/index.ts'],
12
- minify: true,
13
- sourcemap: true,
14
- logLevel: 'silent',
15
- resolveExtensions: ['.tsx', '.ts', '.jsx', '.mjs', '.js', '.json'],
16
- platform: 'browser',
17
- // plugins: [polyfillNode()],
18
- })
19
-
20
- fs.writeFileSync('meta.json', JSON.stringify(result.metafile))
@@ -1,46 +0,0 @@
1
- import { Client as PasskeyClient } from 'passkey-kit-sdk';
2
- import { Client as FactoryClient } from 'passkey-factory-sdk';
3
- import { Networks, Transaction, Horizon, SorobanRpc } from '@stellar/stellar-sdk';
4
- import { Buffer } from 'buffer';
5
- export declare class PasskeyAccount {
6
- id: string | undefined;
7
- sudo: string | undefined;
8
- wallet: PasskeyClient | undefined;
9
- factory: FactoryClient;
10
- sequencePublicKey: string;
11
- networkPassphrase: Networks;
12
- horizonUrl: string;
13
- horizon: Horizon.Server;
14
- rpcUrl: string;
15
- rpc: SorobanRpc.Server;
16
- feeBumpUrl: string;
17
- feeBumpJwt: string;
18
- factoryContractId: string;
19
- constructor(options: {
20
- sequencePublicKey: string;
21
- networkPassphrase: Networks;
22
- horizonUrl: string;
23
- rpcUrl: string;
24
- feeBumpUrl: string;
25
- feeBumpJwt: string;
26
- factoryContractId?: string;
27
- });
28
- createWallet(name: string, user: string): Promise<{
29
- contractId: string;
30
- xdr: string;
31
- }>;
32
- createKey(name: string, user: string): Promise<{
33
- keyId: Buffer;
34
- publicKey: Buffer | undefined;
35
- }>;
36
- connectWallet(): Promise<string>;
37
- sign(txn: Transaction | string, options?: {
38
- id?: 'any' | 'sudo' | string | Uint8Array;
39
- ttl?: number;
40
- }): Promise<string>;
41
- send(txn: Transaction, fee?: number): Promise<Horizon.HorizonApi.SubmitTransactionResponse>;
42
- getData(): Promise<Map<string, any>>;
43
- private getKey;
44
- private getPublicKeyObject;
45
- private convertEcdsaSignatureAsnToCompact;
46
- }