passkey-kit 0.7.11 → 0.7.13

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.7.11",
3
+ "version": "0.7.13",
4
4
  "description": "A helper library for creating and using passkey accounts on the Stellar blockchain.",
5
5
  "author": "Tyler van der Hoeven",
6
6
  "license": "MIT",
@@ -13,8 +13,8 @@
13
13
  "@stellar/stellar-sdk": "file:./ext/@stellar/stellar-sdk",
14
14
  "base64url": "^3.0.1",
15
15
  "buffer": "^6.0.3",
16
- "passkey-kit-sdk": "0.3.4",
17
16
  "passkey-factory-sdk": "0.3.4",
17
+ "passkey-kit-sdk": "0.3.4",
18
18
  "sac-sdk": "0.1.1"
19
19
  },
20
20
  "devDependencies": {
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { PasskeyServer } from "./server"
2
- import { PasskeyKit } from "./kit"
2
+ import { PasskeyKit, SignerStore, SignerKey, type SignerLimits } from "./kit"
3
3
  import { SACClient } from "./sac"
4
4
 
5
- export { PasskeyServer, PasskeyKit, SACClient }
5
+ export { PasskeyServer, PasskeyKit, SACClient, SignerStore, SignerKey, type SignerLimits }
package/src/kit.ts CHANGED
@@ -1,12 +1,35 @@
1
- import { Client as PasskeyClient, type Signature, type Signatures, type SignerKey } from 'passkey-kit-sdk'
1
+ import { Client as PasskeyClient, type Signature, type SignerKey as SDKSignerKey, type SignerLimits as SDKSignerLimits } from 'passkey-kit-sdk'
2
2
  import { Client as FactoryClient } from 'passkey-factory-sdk'
3
- import { Address, StrKey, hash, xdr, SorobanRpc, Keypair, Transaction, Operation, nativeToScVal } from '@stellar/stellar-sdk'
3
+ import { StrKey, hash, xdr, SorobanRpc, Keypair, Address } from '@stellar/stellar-sdk'
4
4
  import base64url from 'base64url'
5
5
  import { startRegistration, startAuthentication } from "@simplewebauthn/browser"
6
6
  import type { AuthenticatorAttestationResponseJSON, AuthenticatorSelectionCriteria } from "@simplewebauthn/types"
7
7
  import { Buffer } from 'buffer'
8
8
  import { PasskeyBase } from './base'
9
- import { AssembledTransaction, DEFAULT_TIMEOUT, type Tx } from '@stellar/stellar-sdk/contract'
9
+ import { AssembledTransaction, DEFAULT_TIMEOUT } from '@stellar/stellar-sdk/contract'
10
+
11
+ export class SignerKey {
12
+ private constructor(public key: "Policy" | "Ed25519" | "Secp256r1", public value: string) { }
13
+
14
+ static Policy(policy: string): SignerKey {
15
+ return new SignerKey("Policy", policy);
16
+ }
17
+
18
+ static Ed25519(publicKey: string): SignerKey {
19
+ return new SignerKey("Ed25519", publicKey);
20
+ }
21
+
22
+ static Secp256r1(id: string): SignerKey {
23
+ return new SignerKey("Secp256r1", id);
24
+ }
25
+ }
26
+
27
+ export type SignerLimits = Map<string, SignerKey[] | undefined>
28
+
29
+ export enum SignerStore {
30
+ Persistent = 'Persistent',
31
+ Temporary = 'Temporary',
32
+ }
10
33
 
11
34
  export class PasskeyKit extends PasskeyBase {
12
35
  declare public rpc: SorobanRpc.Server
@@ -219,7 +242,7 @@ export class PasskeyKit extends PasskeyBase {
219
242
  const payload = hash(preimage.toXDR())
220
243
 
221
244
  // let signatures: Signatures
222
- let key: SignerKey
245
+ let key: SDKSignerKey
223
246
  let val: Signature | undefined
224
247
 
225
248
  // const scSpecTypeDefSignatures = xdr.ScSpecTypeDef.scSpecTypeUdt(
@@ -367,7 +390,7 @@ export class PasskeyKit extends PasskeyBase {
367
390
  return entry
368
391
  }
369
392
 
370
- public async sign<T>(
393
+ public sign<T>(
371
394
  txn: AssembledTransaction<T>,
372
395
  options?: {
373
396
  rpId?: string,
@@ -377,22 +400,115 @@ export class PasskeyKit extends PasskeyBase {
377
400
  expiration?: number
378
401
  }
379
402
  ) {
380
- await txn.signAuthEntries({
403
+ // TODO ensure we're outputting a built transaction that's actually useful in the case you don't intend to use launchtube
404
+ // Pretty sure we'll always be woefully under budget
405
+ return txn.signAuthEntries({
381
406
  address: this.wallet!.options.contractId,
382
407
  authorizeEntry: (entry) => {
383
408
  const clone = xdr.SorobanAuthorizationEntry.fromXDR(entry.toXDR())
384
- return this.signAuthEntry(clone, options)
409
+ return this.signAuthEntry(clone, options)
385
410
  },
386
411
  })
387
412
  }
388
413
 
389
- // Add little utility helpers for adding and removing signers
414
+ public addSecp256r1(keyId: Uint8Array, publicKey: Uint8Array, limits: SignerLimits, store: SignerStore) {
415
+ return this.wallet!.add({
416
+ signer: {
417
+ tag: "Secp256r1",
418
+ values: [
419
+ Buffer.from(keyId),
420
+ Buffer.from(publicKey),
421
+ this.getSignerLimits(limits),
422
+ { tag: store, values: undefined },
423
+ ],
424
+ },
425
+ });
426
+ }
427
+ public addEd25519(publicKey: string, limits: SignerLimits, store: SignerStore) {
428
+ return this.wallet!.add({
429
+ signer: {
430
+ tag: "Ed25519",
431
+ values: [
432
+ Keypair.fromPublicKey(publicKey).rawPublicKey(),
433
+ this.getSignerLimits(limits),
434
+ { tag: store, values: undefined },
435
+ ],
436
+ },
437
+ });
438
+ }
439
+ public addPolicy(policy: string, limits: SignerLimits, store: SignerStore) {
440
+ return this.wallet!.add({
441
+ signer: {
442
+ tag: "Policy",
443
+ values: [
444
+ policy,
445
+ this.getSignerLimits(limits),
446
+ { tag: store, values: undefined },
447
+ ],
448
+ },
449
+ });
450
+ }
451
+
452
+ public remove(signer: SignerKey) {
453
+ return this.wallet!.remove({
454
+ signer_key: this.getSignerKey(signer)
455
+ });
456
+ }
390
457
 
391
458
  /* LATER
392
459
  - Add a getKeyInfo action to get info about a specific passkey
393
460
  Specifically looking for name, type, etc. data so a user could grok what signer mapped to what passkey
394
461
  */
395
462
 
463
+ private getSignerLimits(limits: SignerLimits) {
464
+ const sdk_limits: SDKSignerLimits = [new Map()]
465
+
466
+ for (const [contract, signer_keys] of limits.entries()) {
467
+ let sdk_signer_keys: SDKSignerKey[] | undefined
468
+
469
+ if (signer_keys?.length) {
470
+ sdk_signer_keys = []
471
+
472
+ for (const signer_key of signer_keys) {
473
+ sdk_signer_keys.push(
474
+ this.getSignerKey(signer_key)
475
+ )
476
+ }
477
+ }
478
+
479
+ sdk_limits[0].set(contract, sdk_signer_keys)
480
+ }
481
+
482
+ return sdk_limits
483
+ }
484
+
485
+ private getSignerKey({ key: tag, value }: SignerKey) {
486
+ let signer_key: SDKSignerKey
487
+
488
+ switch (tag) {
489
+ case 'Policy':
490
+ signer_key = {
491
+ tag,
492
+ values: [value]
493
+ }
494
+ break;
495
+ case 'Ed25519':
496
+ signer_key = {
497
+ tag,
498
+ values: [Keypair.fromPublicKey(value).rawPublicKey()]
499
+ }
500
+ break;
501
+ case 'Secp256r1':
502
+ signer_key = {
503
+ tag,
504
+ values: [base64url.toBuffer(value)]
505
+ }
506
+ break;
507
+ }
508
+
509
+ return signer_key
510
+ }
511
+
396
512
  private async getPublicKey(response: AuthenticatorAttestationResponseJSON) {
397
513
  let publicKey: Buffer | undefined
398
514
 
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { PasskeyServer } from "./server";
2
- import { PasskeyKit } from "./kit";
2
+ import { PasskeyKit, SignerStore, SignerKey, type SignerLimits } from "./kit";
3
3
  import { SACClient } from "./sac";
4
- export { PasskeyServer, PasskeyKit, SACClient };
4
+ export { PasskeyServer, PasskeyKit, SACClient, SignerStore, SignerKey, type SignerLimits };
package/types/kit.d.ts CHANGED
@@ -5,7 +5,20 @@ import { startRegistration, startAuthentication } from "@simplewebauthn/browser"
5
5
  import type { AuthenticatorSelectionCriteria } from "@simplewebauthn/types";
6
6
  import { Buffer } from 'buffer';
7
7
  import { PasskeyBase } from './base';
8
- import { AssembledTransaction, type Tx } from '@stellar/stellar-sdk/contract';
8
+ import { AssembledTransaction } from '@stellar/stellar-sdk/contract';
9
+ export declare class SignerKey {
10
+ key: "Policy" | "Ed25519" | "Secp256r1";
11
+ value: string;
12
+ private constructor();
13
+ static Policy(policy: string): SignerKey;
14
+ static Ed25519(publicKey: string): SignerKey;
15
+ static Secp256r1(id: string): SignerKey;
16
+ }
17
+ export type SignerLimits = Map<string, SignerKey[] | undefined>;
18
+ export declare enum SignerStore {
19
+ Persistent = "Persistent",
20
+ Temporary = "Temporary"
21
+ }
9
22
  export declare class PasskeyKit extends PasskeyBase {
10
23
  rpc: SorobanRpc.Server;
11
24
  rpcUrl: string;
@@ -29,7 +42,7 @@ export declare class PasskeyKit extends PasskeyBase {
29
42
  createWallet(app: string, user: string): Promise<{
30
43
  keyId: Buffer;
31
44
  contractId: string;
32
- built: Tx;
45
+ built: import("@stellar/stellar-sdk/contract").Tx;
33
46
  }>;
34
47
  createKey(app: string, user: string, settings?: {
35
48
  rpId?: string;
@@ -60,6 +73,12 @@ export declare class PasskeyKit extends PasskeyBase {
60
73
  policy?: string;
61
74
  expiration?: number;
62
75
  }): Promise<void>;
76
+ addSecp256r1(keyId: Uint8Array, publicKey: Uint8Array, limits: SignerLimits, store: SignerStore): Promise<AssembledTransaction<import("@stellar/stellar-sdk/contract").Result<void, import("@stellar/stellar-sdk/contract").ErrorMessage>>>;
77
+ addEd25519(publicKey: string, limits: SignerLimits, store: SignerStore): Promise<AssembledTransaction<import("@stellar/stellar-sdk/contract").Result<void, import("@stellar/stellar-sdk/contract").ErrorMessage>>>;
78
+ addPolicy(policy: string, limits: SignerLimits, store: SignerStore): Promise<AssembledTransaction<import("@stellar/stellar-sdk/contract").Result<void, import("@stellar/stellar-sdk/contract").ErrorMessage>>>;
79
+ remove(signer: SignerKey): Promise<AssembledTransaction<import("@stellar/stellar-sdk/contract").Result<void, import("@stellar/stellar-sdk/contract").ErrorMessage>>>;
80
+ private getSignerLimits;
81
+ private getSignerKey;
63
82
  private getPublicKey;
64
83
  private compactSignature;
65
84
  }