passkey-kit 0.2.3 → 0.2.5
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.
- package/README.md +52 -6
- package/TODO.md +2 -0
- package/package.json +1 -1
- package/src/kit.ts +14 -6
- package/types/kit.d.ts +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,44 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Passkey Kit
|
|
2
|
+
|
|
3
|
+
Passkey kit is a basic TypeScript SDK for creating and managing Stellar smart wallets. It's intended to be used in tandem with [Launchtube](https://github.com/kalepail/launchtube) for submitting passkey signed transactions onchain however this is not a requirement. This is both a client and a server side library. `PasskeyKit` on the client and `PasskeyBase` on the server.
|
|
4
|
+
|
|
5
|
+
Demo site: [passkey-kit-demo.pages.dev](https://passkey-kit-demo.pages.dev/)
|
|
6
|
+
|
|
7
|
+
To get started first install the package:
|
|
8
|
+
```
|
|
9
|
+
pnpm i passkey-kit
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
On the client:
|
|
13
|
+
```ts
|
|
14
|
+
const account = new PasskeyKit({
|
|
15
|
+
rpcUrl: env.RPC_URL,
|
|
16
|
+
networkPassphrase: env.NETWORK_PASSPHRASE
|
|
17
|
+
});
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
On the server:
|
|
21
|
+
```ts
|
|
22
|
+
const account = new PasskeyKit({
|
|
23
|
+
launchtubeUrl: env.LAUNCHTUBE_URL,
|
|
24
|
+
launchtubeJwt: env.LAUNCHTUBE_JWT,
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Note that while I don't recommend it you can use the server-intended `send` method on the client side by passing in the `launchtubeUrl` and `launchtubeJwt` values to the `PasskeyKit` constructor. We do this in the `./demo` site to ease demonstration, development and experimentation, however in a production environment you'll want to keep your secrets safe on the server.
|
|
29
|
+
|
|
30
|
+
This is a fully typed library so docs aren't provided, however there's a full example showcasing all the core public methods in the `./demo` directory. I also recommend reviewing the [Super Peach](https://github.com/kalepail/superpeach) repo for an example of how you could implement both the client and server side in a more real-world scenario.
|
|
31
|
+
|
|
32
|
+
Good luck, have fun, and change the world!
|
|
33
|
+
|
|
34
|
+
For any questions or to showcase your progress please join the `#passkeys` channel on our [Discord](https://discord.gg/stellardev).
|
|
35
|
+
|
|
36
|
+
## Contributing
|
|
37
|
+
|
|
38
|
+
Passkey kit consists of three primary directories:
|
|
39
|
+
- `./contracts` - Contains the Rust Soroban smart contracts of the smart wallet implementation.
|
|
40
|
+
- `./src` - Contains the TypeScript files for the actual TS SDK library.
|
|
41
|
+
- `./demo` - Contains a basic demo of the SDK in action.
|
|
2
42
|
|
|
3
43
|
To install dependencies:
|
|
4
44
|
|
|
@@ -12,10 +52,16 @@ To build:
|
|
|
12
52
|
pnpm run build
|
|
13
53
|
```
|
|
14
54
|
|
|
15
|
-
|
|
55
|
+
To run the demo:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
cd ./demo
|
|
59
|
+
pnpm i
|
|
60
|
+
pnpm run start
|
|
61
|
+
```
|
|
16
62
|
|
|
17
|
-
|
|
63
|
+
[!IMPORTANT]
|
|
64
|
+
> If you fiddle with contracts in `./contracts` you'll need to run the make commands. Just remember to update the `WEBAUTHN_FACTORY` and `WEBAUTHN_WASM` values from the `make deploy` command before running `make init`.
|
|
18
65
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
- [ ] Attach some meaningful metadata to signers so you know which one belongs to which domain
|
|
66
|
+
[!IMPORTANT]
|
|
67
|
+
> Keep in mind the bindings here in `./packages` have been _heavily_ modified. Be careful when rebuilding and updating. Likely you'll only want to update the `src/index.ts` files in each respective package vs swapping out entire directories.
|
package/TODO.md
ADDED
package/package.json
CHANGED
package/src/kit.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Client as PasskeyClient } from 'passkey-kit-sdk'
|
|
2
2
|
import { Client as FactoryClient, networks } from 'passkey-factory-sdk'
|
|
3
|
-
import { Address, Networks, StrKey, hash, xdr, Transaction, SorobanRpc, Operation, scValToNative, TransactionBuilder
|
|
3
|
+
import { Address, Networks, StrKey, hash, xdr, Transaction, SorobanRpc, Operation, scValToNative, TransactionBuilder } from '@stellar/stellar-sdk'
|
|
4
4
|
import { bufToBigint, bigintToBuf } from 'bigint-conversion'
|
|
5
5
|
import base64url from 'base64url'
|
|
6
6
|
import { startRegistration, startAuthentication } from "@simplewebauthn/browser"
|
|
@@ -38,7 +38,7 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
38
38
|
launchtubeUrl?: string,
|
|
39
39
|
launchtubeJwt?: string,
|
|
40
40
|
factoryContractId?: string,
|
|
41
|
-
networkPassphrase:
|
|
41
|
+
networkPassphrase: string,
|
|
42
42
|
}) {
|
|
43
43
|
const {
|
|
44
44
|
rpcUrl,
|
|
@@ -58,7 +58,7 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
58
58
|
|
|
59
59
|
this.rpcUrl = rpcUrl
|
|
60
60
|
this.rpc = new SorobanRpc.Server(rpcUrl)
|
|
61
|
-
this.networkPassphrase = networkPassphrase
|
|
61
|
+
this.networkPassphrase = networkPassphrase as Networks
|
|
62
62
|
this.factory = new FactoryClient({
|
|
63
63
|
contractId: this.factoryContractId,
|
|
64
64
|
networkPassphrase,
|
|
@@ -169,8 +169,8 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
169
169
|
}
|
|
170
170
|
// if that fails look up from the factory mapper
|
|
171
171
|
catch {
|
|
172
|
-
|
|
173
|
-
contractId = scValToNative(
|
|
172
|
+
const { val } = await this.rpc.getContractData(this.factoryContractId, xdr.ScVal.scvBytes(keyIdBuffer))
|
|
173
|
+
contractId = scValToNative(val.contractData().val())
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
this.wallet = new PasskeyClient({
|
|
@@ -295,7 +295,11 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
295
295
|
ledgersToLive?: number
|
|
296
296
|
}
|
|
297
297
|
) {
|
|
298
|
-
|
|
298
|
+
/* NOTE
|
|
299
|
+
- Hack to ensure we don't stack fees when simulating and assembling multiple times
|
|
300
|
+
AssembleTransaction always adds the resource fee onto the transaction fee.
|
|
301
|
+
This is bad in cases where you need to simulate multiple times
|
|
302
|
+
*/
|
|
299
303
|
txn = TransactionBuilder.cloneFrom(new Transaction(
|
|
300
304
|
typeof txn === 'string'
|
|
301
305
|
? txn
|
|
@@ -335,6 +339,10 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
335
339
|
public async getData(contractData?: SorobanRpc.Api.LedgerEntryResult) {
|
|
336
340
|
const data: Map<string, any> = new Map()
|
|
337
341
|
|
|
342
|
+
/* TODO
|
|
343
|
+
- Pretty easy to get into a state where there is no contractId and this we error at `this.wallet!.options.contractId,`
|
|
344
|
+
We should have a better error or maybe just handle no-wallet scenarios more gracefully
|
|
345
|
+
*/
|
|
338
346
|
const { val } = contractData || await this.rpc.getContractData(
|
|
339
347
|
this.wallet!.options.contractId,
|
|
340
348
|
xdr.ScVal.scvLedgerKeyContractInstance(),
|
package/types/kit.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare class PasskeyKit extends PasskeyBase {
|
|
|
17
17
|
launchtubeUrl?: string;
|
|
18
18
|
launchtubeJwt?: string;
|
|
19
19
|
factoryContractId?: string;
|
|
20
|
-
networkPassphrase:
|
|
20
|
+
networkPassphrase: string;
|
|
21
21
|
});
|
|
22
22
|
createWallet(name: string, user: string): Promise<{
|
|
23
23
|
keyId: Buffer;
|