passkey-kit 0.7.11 → 0.7.12
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 +3 -3
- package/src/index.ts +2 -2
- package/src/kit.ts +138 -9
- package/types/index.d.ts +2 -2
- package/types/kit.d.ts +20 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "passkey-kit",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.12",
|
|
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,9 +13,9 @@
|
|
|
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",
|
|
18
|
-
"sac-sdk": "0.1.1"
|
|
17
|
+
"sac-sdk": "0.1.1",
|
|
18
|
+
"passkey-kit-sdk": "0.3.4"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@simplewebauthn/types": "^10.0.0",
|
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,37 @@
|
|
|
1
|
-
import { Client as PasskeyClient, type Signature, type
|
|
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 {
|
|
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
|
|
9
|
+
import { AssembledTransaction, DEFAULT_TIMEOUT } from '@stellar/stellar-sdk/contract'
|
|
10
|
+
|
|
11
|
+
// TODO ensure we're outputting a built transaction that's actually useful in the case you don't intend to use Launchtube
|
|
12
|
+
|
|
13
|
+
export class SignerKey {
|
|
14
|
+
private constructor(public type: "Policy" | "Ed25519" | "Secp256r1", public value: string | Buffer) { }
|
|
15
|
+
|
|
16
|
+
static Policy(value: string): SignerKey {
|
|
17
|
+
return new SignerKey("Policy", value);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static Ed25519(value: Buffer): SignerKey {
|
|
21
|
+
return new SignerKey("Ed25519", value);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static Secp256r1(value: Buffer): SignerKey {
|
|
25
|
+
return new SignerKey("Secp256r1", value);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type SignerLimits = Map<string, SignerKey[] | undefined>
|
|
30
|
+
|
|
31
|
+
export enum SignerStore {
|
|
32
|
+
Persistent = 'Persistent',
|
|
33
|
+
Temporary = 'Temporary',
|
|
34
|
+
}
|
|
10
35
|
|
|
11
36
|
export class PasskeyKit extends PasskeyBase {
|
|
12
37
|
declare public rpc: SorobanRpc.Server
|
|
@@ -194,7 +219,7 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
194
219
|
if ([keyId, keypair, policy].filter((arg) => !!arg).length > 1)
|
|
195
220
|
throw new Error('Exactly one of `options.keyId`, `options.keypair`, or `options.policy` must be provided.');
|
|
196
221
|
|
|
197
|
-
const credentials = entry.credentials().address();
|
|
222
|
+
const credentials = entry.credentials().address(); // TODO review this for using the Signatures type again. Might be just `credentials`
|
|
198
223
|
|
|
199
224
|
if (!expiration) {
|
|
200
225
|
expiration = credentials.signatureExpirationLedger()
|
|
@@ -219,7 +244,7 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
219
244
|
const payload = hash(preimage.toXDR())
|
|
220
245
|
|
|
221
246
|
// let signatures: Signatures
|
|
222
|
-
let key:
|
|
247
|
+
let key: SDKSignerKey
|
|
223
248
|
let val: Signature | undefined
|
|
224
249
|
|
|
225
250
|
// const scSpecTypeDefSignatures = xdr.ScSpecTypeDef.scSpecTypeUdt(
|
|
@@ -367,7 +392,7 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
367
392
|
return entry
|
|
368
393
|
}
|
|
369
394
|
|
|
370
|
-
public
|
|
395
|
+
public sign<T>(
|
|
371
396
|
txn: AssembledTransaction<T>,
|
|
372
397
|
options?: {
|
|
373
398
|
rpId?: string,
|
|
@@ -377,22 +402,126 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
377
402
|
expiration?: number
|
|
378
403
|
}
|
|
379
404
|
) {
|
|
380
|
-
|
|
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
|
-
|
|
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(key: SignerKey) {
|
|
453
|
+
let signer_key: SDKSignerKey
|
|
454
|
+
|
|
455
|
+
switch (key.type) {
|
|
456
|
+
case 'Policy':
|
|
457
|
+
signer_key = {
|
|
458
|
+
tag: key.type,
|
|
459
|
+
values: [key.value as string]
|
|
460
|
+
}
|
|
461
|
+
break;
|
|
462
|
+
case 'Ed25519':
|
|
463
|
+
signer_key = {
|
|
464
|
+
tag: key.type,
|
|
465
|
+
values: [key.value as Buffer]
|
|
466
|
+
}
|
|
467
|
+
break;
|
|
468
|
+
case 'Secp256r1':
|
|
469
|
+
signer_key = {
|
|
470
|
+
tag: key.type,
|
|
471
|
+
values: [key.value as Buffer]
|
|
472
|
+
}
|
|
473
|
+
break;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
return this.wallet!.remove({
|
|
477
|
+
signer_key,
|
|
478
|
+
});
|
|
479
|
+
}
|
|
390
480
|
|
|
391
481
|
/* LATER
|
|
392
482
|
- Add a getKeyInfo action to get info about a specific passkey
|
|
393
483
|
Specifically looking for name, type, etc. data so a user could grok what signer mapped to what passkey
|
|
394
484
|
*/
|
|
395
485
|
|
|
486
|
+
private getSignerLimits(limits: SignerLimits) {
|
|
487
|
+
const sdk_limits: SDKSignerLimits = [new Map()]
|
|
488
|
+
|
|
489
|
+
for (const [contract, signer_keys] of limits.entries()) {
|
|
490
|
+
let sdk_signer_keys: SDKSignerKey[] | undefined
|
|
491
|
+
|
|
492
|
+
if (signer_keys?.length) {
|
|
493
|
+
sdk_signer_keys = []
|
|
494
|
+
|
|
495
|
+
for (const signer_key of signer_keys) {
|
|
496
|
+
switch (signer_key.type) {
|
|
497
|
+
case 'Policy':
|
|
498
|
+
sdk_signer_keys.push({
|
|
499
|
+
tag: signer_key.type,
|
|
500
|
+
values: [signer_key.value as string]
|
|
501
|
+
})
|
|
502
|
+
break;
|
|
503
|
+
case 'Ed25519':
|
|
504
|
+
sdk_signer_keys.push({
|
|
505
|
+
tag: signer_key.type,
|
|
506
|
+
values: [signer_key.value as Buffer]
|
|
507
|
+
})
|
|
508
|
+
break;
|
|
509
|
+
case 'Secp256r1':
|
|
510
|
+
sdk_signer_keys.push({
|
|
511
|
+
tag: signer_key.type,
|
|
512
|
+
values: [signer_key.value as Buffer]
|
|
513
|
+
})
|
|
514
|
+
break;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
sdk_limits[0].set(contract, sdk_signer_keys)
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
return sdk_limits
|
|
523
|
+
}
|
|
524
|
+
|
|
396
525
|
private async getPublicKey(response: AuthenticatorAttestationResponseJSON) {
|
|
397
526
|
let publicKey: Buffer | undefined
|
|
398
527
|
|
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
|
|
8
|
+
import { AssembledTransaction } from '@stellar/stellar-sdk/contract';
|
|
9
|
+
export declare class SignerKey {
|
|
10
|
+
type: "Policy" | "Ed25519" | "Secp256r1";
|
|
11
|
+
value: string | Buffer;
|
|
12
|
+
private constructor();
|
|
13
|
+
static Policy(value: string): SignerKey;
|
|
14
|
+
static Ed25519(value: Buffer): SignerKey;
|
|
15
|
+
static Secp256r1(value: Buffer): 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,11 @@ 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(key: SignerKey): Promise<AssembledTransaction<import("@stellar/stellar-sdk/contract").Result<void, import("@stellar/stellar-sdk/contract").ErrorMessage>>>;
|
|
80
|
+
private getSignerLimits;
|
|
63
81
|
private getPublicKey;
|
|
64
82
|
private compactSignature;
|
|
65
83
|
}
|