passkey-kit 0.10.15 → 0.10.17

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "passkey-kit",
3
- "version": "0.10.15",
3
+ "version": "0.10.17",
4
4
  "description": "A helper library for creating and using smart wallet accounts on the Stellar blockchain.",
5
5
  "author": "Tyler van der Hoeven",
6
6
  "license": "MIT",
package/src/kit.ts CHANGED
@@ -136,7 +136,7 @@ export class PasskeyKit extends PasskeyBase {
136
136
  rpId?: string,
137
137
  keyId?: string | Uint8Array,
138
138
  getContractId?: (keyId: string) => Promise<string | undefined>,
139
- walletPublicKey?: string // TEMP for backwards compatibility when we seeded wallets from a factory address
139
+ walletPublicKey?: string // TEMP for backwards compatibility for when we seeded wallets from a factory address
140
140
  }) {
141
141
  let { keyId, rpId, getContractId, walletPublicKey } = opts || {}
142
142
  let keyIdBuffer: Buffer
@@ -164,17 +164,7 @@ export class PasskeyKit extends PasskeyBase {
164
164
  this.keyId = keyId
165
165
 
166
166
  // Check for the contractId on-chain as a derivation from the keyId. This is the easiest and "cheapest" check however it will only work for the initially deployed passkey if it was used as derivation
167
- let contractId: string | undefined = StrKey.encodeContract(hash(xdr.HashIdPreimage.envelopeTypeContractId(
168
- new xdr.HashIdPreimageContractId({
169
- networkId: hash(Buffer.from(this.networkPassphrase)),
170
- contractIdPreimage: xdr.ContractIdPreimage.contractIdPreimageFromAddress(
171
- new xdr.ContractIdPreimageFromAddress({
172
- address: Address.fromString(walletPublicKey || this.walletPublicKey).toScAddress(),
173
- salt: hash(keyIdBuffer),
174
- })
175
- )
176
- })
177
- ).toXDR()));
167
+ let contractId: string | undefined = this.encodeContract(this.walletPublicKey, keyIdBuffer);
178
168
 
179
169
  // attempt passkey id derivation
180
170
  try {
@@ -186,6 +176,19 @@ export class PasskeyKit extends PasskeyBase {
186
176
  contractId = getContractId && await getContractId(keyId)
187
177
  }
188
178
 
179
+ ////
180
+ // TEMP for backwards compatibility for when we seeded wallets from a factory address
181
+ if (!contractId && walletPublicKey) {
182
+ contractId = this.encodeContract(walletPublicKey, keyIdBuffer);
183
+
184
+ try {
185
+ await this.rpc.getContractData(contractId, xdr.ScVal.scvLedgerKeyContractInstance())
186
+ } catch {
187
+ contractId = undefined
188
+ }
189
+ }
190
+ ////
191
+
189
192
  if (!contractId)
190
193
  throw new Error('Failed to connect wallet')
191
194
 
@@ -556,6 +559,22 @@ export class PasskeyKit extends PasskeyBase {
556
559
  return signer_key
557
560
  }
558
561
 
562
+ private encodeContract(walletPublicKey: string, keyIdBuffer: Buffer) {
563
+ let contractId: string | undefined = StrKey.encodeContract(hash(xdr.HashIdPreimage.envelopeTypeContractId(
564
+ new xdr.HashIdPreimageContractId({
565
+ networkId: hash(Buffer.from(this.networkPassphrase)),
566
+ contractIdPreimage: xdr.ContractIdPreimage.contractIdPreimageFromAddress(
567
+ new xdr.ContractIdPreimageFromAddress({
568
+ address: Address.fromString(walletPublicKey).toScAddress(),
569
+ salt: hash(keyIdBuffer),
570
+ })
571
+ )
572
+ })
573
+ ).toXDR()));
574
+
575
+ return contractId
576
+ }
577
+
559
578
  private async getPublicKey(response: AuthenticatorAttestationResponseJSON) {
560
579
  let publicKey: Buffer | undefined
561
580
 
package/src/server.ts CHANGED
@@ -1,10 +1,11 @@
1
- import { Transaction, xdr, Networks, Operation } from "@stellar/stellar-sdk/minimal"
1
+ import { xdr } from "@stellar/stellar-sdk/minimal"
2
2
  import { PasskeyBase } from "./base"
3
3
  import base64url from "base64url"
4
4
  import type { Tx } from "@stellar/stellar-sdk/minimal/contract"
5
5
  import type { Signer } from "./types"
6
6
  import { AssembledTransaction } from "@stellar/stellar-sdk/minimal/contract"
7
7
  import { Durability } from "@stellar/stellar-sdk/minimal/rpc"
8
+ import { version } from '../package.json'
8
9
 
9
10
  export class PasskeyServer extends PasskeyBase {
10
11
  private launchtubeJwt: string | undefined
@@ -149,7 +150,7 @@ export class PasskeyServer extends PasskeyBase {
149
150
  - Add a method for getting a paginated or filtered list of all a wallet's events
150
151
  */
151
152
 
152
- public async send<T>(txn: AssembledTransaction<T> | Tx | string, fee?: number) {
153
+ public async send<T>(txn: AssembledTransaction<T> | Tx | string, fee?: number, headers?: Record<string, string>) {
153
154
  if (!this.launchtubeUrl || !this.launchtubeJwt)
154
155
  throw new Error('Launchtube service not configured')
155
156
 
@@ -170,11 +171,14 @@ export class PasskeyServer extends PasskeyBase {
170
171
  method: 'POST',
171
172
  headers: {
172
173
  authorization: `Bearer ${this.launchtubeJwt}`,
174
+ 'X-Client-Name': 'passkey-kit',
175
+ 'X-Client-Version': version,
176
+ ...headers
173
177
  },
174
178
  body: data
175
179
  }).then(async (res) => {
176
180
  if (res.ok)
177
- return res.json()
181
+ return res.json()
178
182
  else throw await res.json()
179
183
  })
180
184
  }
package/types/kit.d.ts CHANGED
@@ -76,6 +76,7 @@ export declare class PasskeyKit extends PasskeyBase {
76
76
  private policy;
77
77
  private getSignerLimits;
78
78
  private getSignerKey;
79
+ private encodeContract;
79
80
  private getPublicKey;
80
81
  private compactSignature;
81
82
  }
@@ -0,0 +1,6 @@
1
+ import { Server } from "@stellar/stellar-sdk/minimal/rpc";
2
+ export declare class PasskeyBase {
3
+ rpcUrl: string | undefined;
4
+ rpc: Server | undefined;
5
+ constructor(rpcUrl?: string);
6
+ }
@@ -0,0 +1,5 @@
1
+ export { SignerStore, SignerKey, type Signer, type SignerLimits } from './types';
2
+ export { PasskeyKit } from "./kit";
3
+ export { PasskeyServer } from "./server";
4
+ export { SACClient } from "./sac";
5
+ export { Client as PasskeyClient } from 'passkey-kit-sdk';
@@ -0,0 +1,82 @@
1
+ import { Client as PasskeyClient } from 'passkey-kit-sdk';
2
+ import { xdr, Keypair } from '@stellar/stellar-sdk/minimal';
3
+ import type { AuthenticatorSelectionCriteria } from "@simplewebauthn/types";
4
+ import { startRegistration, startAuthentication } from "@simplewebauthn/browser";
5
+ import { Buffer } from 'buffer';
6
+ import type { SignerKey, SignerLimits, SignerStore } from './types';
7
+ import { PasskeyBase } from './base';
8
+ import { AssembledTransaction, type Tx } from '@stellar/stellar-sdk/minimal/contract';
9
+ import type { Server } from '@stellar/stellar-sdk/minimal/rpc';
10
+ export declare class PasskeyKit extends PasskeyBase {
11
+ rpc: Server;
12
+ rpcUrl: string;
13
+ private walletKeypair;
14
+ private walletPublicKey;
15
+ private walletWasmHash;
16
+ private WebAuthn;
17
+ keyId: string | undefined;
18
+ networkPassphrase: string;
19
+ wallet: PasskeyClient | undefined;
20
+ constructor(options: {
21
+ rpcUrl: string;
22
+ networkPassphrase: string;
23
+ walletWasmHash: string;
24
+ WebAuthn?: {
25
+ startRegistration: typeof startRegistration;
26
+ startAuthentication: typeof startAuthentication;
27
+ };
28
+ });
29
+ createWallet(app: string, user: string): Promise<{
30
+ keyId: Buffer<ArrayBufferLike>;
31
+ keyIdBase64: string;
32
+ contractId: string;
33
+ signedTx: Tx;
34
+ }>;
35
+ createKey(app: string, user: string, settings?: {
36
+ rpId?: string;
37
+ authenticatorSelection?: AuthenticatorSelectionCriteria;
38
+ }): Promise<{
39
+ keyId: Buffer<ArrayBufferLike>;
40
+ keyIdBase64: string;
41
+ publicKey: Buffer<ArrayBufferLike>;
42
+ }>;
43
+ connectWallet(opts?: {
44
+ rpId?: string;
45
+ keyId?: string | Uint8Array;
46
+ getContractId?: (keyId: string) => Promise<string | undefined>;
47
+ walletPublicKey?: string;
48
+ }): Promise<{
49
+ keyId: Buffer<ArrayBufferLike>;
50
+ keyIdBase64: string;
51
+ contractId: string;
52
+ }>;
53
+ signAuthEntry(entry: xdr.SorobanAuthorizationEntry, options?: {
54
+ rpId?: string;
55
+ keyId?: 'any' | string | Uint8Array;
56
+ keypair?: Keypair;
57
+ policy?: string;
58
+ expiration?: number;
59
+ }): Promise<xdr.SorobanAuthorizationEntry>;
60
+ sign<T>(txn: AssembledTransaction<T> | Tx | string, options?: {
61
+ rpId?: string;
62
+ keyId?: 'any' | string | Uint8Array;
63
+ keypair?: Keypair;
64
+ policy?: string;
65
+ expiration?: number;
66
+ }): Promise<AssembledTransaction<T>>;
67
+ addSecp256r1(keyId: string | Uint8Array, publicKey: string | Uint8Array, limits: SignerLimits, store: SignerStore, expiration?: number): Promise<AssembledTransaction<null>>;
68
+ addEd25519(publicKey: string, limits: SignerLimits, store: SignerStore, expiration?: number): Promise<AssembledTransaction<null>>;
69
+ addPolicy(policy: string, limits: SignerLimits, store: SignerStore, expiration?: number): Promise<AssembledTransaction<null>>;
70
+ updateSecp256r1(keyId: string | Uint8Array, publicKey: string | Uint8Array, limits: SignerLimits, store: SignerStore, expiration?: number): Promise<AssembledTransaction<null>>;
71
+ updateEd25519(publicKey: string, limits: SignerLimits, store: SignerStore, expiration?: number): Promise<AssembledTransaction<null>>;
72
+ updatePolicy(policy: string, limits: SignerLimits, store: SignerStore, expiration?: number): Promise<AssembledTransaction<null>>;
73
+ remove(signer: SignerKey): Promise<AssembledTransaction<null>>;
74
+ private secp256r1;
75
+ private ed25519;
76
+ private policy;
77
+ private getSignerLimits;
78
+ private getSignerKey;
79
+ private encodeContract;
80
+ private getPublicKey;
81
+ private compactSignature;
82
+ }
@@ -0,0 +1,13 @@
1
+ import { Client as SacClient } from 'sac-sdk';
2
+ import { PasskeyBase } from "./base";
3
+ import type { Server } from '@stellar/stellar-sdk/minimal/rpc';
4
+ export declare class SACClient extends PasskeyBase {
5
+ rpc: Server;
6
+ rpcUrl: string;
7
+ networkPassphrase: string;
8
+ constructor(options: {
9
+ networkPassphrase: string;
10
+ rpcUrl: string;
11
+ });
12
+ getSACClient(SACContractId: string): SacClient;
13
+ }
@@ -0,0 +1,28 @@
1
+ import { PasskeyBase } from "./base";
2
+ import type { Tx } from "@stellar/stellar-sdk/minimal/contract";
3
+ import type { Signer } from "./types";
4
+ import { AssembledTransaction } from "@stellar/stellar-sdk/minimal/contract";
5
+ export declare class PasskeyServer extends PasskeyBase {
6
+ private launchtubeJwt;
7
+ private mercuryJwt;
8
+ private mercuryKey;
9
+ launchtubeUrl: string | undefined;
10
+ mercuryProjectName: string | undefined;
11
+ mercuryUrl: string | undefined;
12
+ constructor(options: {
13
+ rpcUrl?: string;
14
+ launchtubeUrl?: string;
15
+ launchtubeJwt?: string;
16
+ mercuryProjectName?: string;
17
+ mercuryUrl?: string;
18
+ mercuryJwt?: string;
19
+ mercuryKey?: string;
20
+ });
21
+ getSigners(contractId: string): Promise<Signer[]>;
22
+ getContractId(options: {
23
+ keyId?: string;
24
+ publicKey?: string;
25
+ policy?: string;
26
+ }, index?: number): Promise<string>;
27
+ send<T>(txn: AssembledTransaction<T> | Tx | string, fee?: number, headers?: Record<string, string>): Promise<any>;
28
+ }
@@ -0,0 +1,22 @@
1
+ export type Signer = {
2
+ kind: string;
3
+ key: string;
4
+ val: string;
5
+ expiration: number | null;
6
+ storage: "Persistent" | "Temporary";
7
+ limits: string;
8
+ evicted?: boolean;
9
+ };
10
+ export declare class SignerKey {
11
+ key: "Policy" | "Ed25519" | "Secp256r1";
12
+ value: string;
13
+ private constructor();
14
+ static Policy(policy: string): SignerKey;
15
+ static Ed25519(publicKey: string): SignerKey;
16
+ static Secp256r1(id: string): SignerKey;
17
+ }
18
+ export type SignerLimits = Map<string, SignerKey[] | undefined> | undefined;
19
+ export declare enum SignerStore {
20
+ Persistent = "Persistent",
21
+ Temporary = "Temporary"
22
+ }