passkey-kit 0.7.3 → 0.7.4
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/kit.ts +26 -40
- package/src/server.ts +3 -3
- package/types/kit.d.ts +10 -8
- package/types/server.d.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "passkey-kit",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.4",
|
|
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",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"base64url": "^3.0.1",
|
|
15
15
|
"buffer": "^6.0.3",
|
|
16
16
|
"passkey-factory-sdk": "0.3.1",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
17
|
+
"passkey-kit-sdk": "0.3.1",
|
|
18
|
+
"sac-sdk": "0.1.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@simplewebauthn/types": "^10.0.0",
|
package/src/kit.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Client as PasskeyClient, type Signature, type SignerKey } from 'passkey-kit-sdk'
|
|
2
2
|
import { Client as FactoryClient } from 'passkey-factory-sdk'
|
|
3
|
-
import { Address, StrKey, hash, xdr,
|
|
3
|
+
import { Address, StrKey, hash, xdr, SorobanRpc, Keypair, Transaction } 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 { DEFAULT_TIMEOUT } from '@stellar/stellar-sdk/contract'
|
|
9
|
+
import { DEFAULT_TIMEOUT, type Tx } from '@stellar/stellar-sdk/contract'
|
|
10
10
|
|
|
11
11
|
export class PasskeyKit extends PasskeyBase {
|
|
12
12
|
declare public rpc: SorobanRpc.Server
|
|
@@ -75,7 +75,7 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
75
75
|
return {
|
|
76
76
|
keyId,
|
|
77
77
|
contractId,
|
|
78
|
-
|
|
78
|
+
built
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
|
|
@@ -214,6 +214,7 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
214
214
|
invocation: entry.rootInvocation()
|
|
215
215
|
})
|
|
216
216
|
)
|
|
217
|
+
|
|
217
218
|
const payload = hash(preimage.toXDR())
|
|
218
219
|
|
|
219
220
|
let key: SignerKey
|
|
@@ -310,8 +311,6 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
310
311
|
default:
|
|
311
312
|
throw new Error('Unsupported signature')
|
|
312
313
|
}
|
|
313
|
-
|
|
314
|
-
return entry
|
|
315
314
|
}
|
|
316
315
|
|
|
317
316
|
public async signAuthEntries(
|
|
@@ -335,12 +334,10 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
335
334
|
await this.signAuthEntry(auth, options)
|
|
336
335
|
}
|
|
337
336
|
}
|
|
338
|
-
|
|
339
|
-
return entries
|
|
340
337
|
}
|
|
341
338
|
|
|
342
339
|
public async sign(
|
|
343
|
-
txn: Transaction
|
|
340
|
+
txn: Transaction,
|
|
344
341
|
options?: {
|
|
345
342
|
rpId?: string,
|
|
346
343
|
keyId?: 'any' | string | Uint8Array
|
|
@@ -348,41 +345,29 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
348
345
|
validUntilLedgerSeq?: number
|
|
349
346
|
}
|
|
350
347
|
) {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
// Only need to sign auth for `invokeHostFunction` operations
|
|
354
|
-
if (txn.operations[0].type === 'invokeHostFunction') {
|
|
355
|
-
const entries = txn.operations[0].auth
|
|
356
|
-
|
|
357
|
-
if (entries)
|
|
358
|
-
await this.signAuthEntries(entries, options)
|
|
359
|
-
}
|
|
348
|
+
const entries = this.getAuthEntries(txn)
|
|
360
349
|
|
|
361
|
-
|
|
350
|
+
if (entries)
|
|
351
|
+
await this.signAuthEntries(entries, options)
|
|
362
352
|
}
|
|
363
353
|
|
|
364
354
|
public async attachPolicy(
|
|
365
|
-
txn: Transaction
|
|
355
|
+
txn: Transaction,
|
|
366
356
|
index: number,
|
|
367
357
|
policy: string
|
|
368
358
|
) {
|
|
369
|
-
txn = this.getTxn(txn)
|
|
370
|
-
|
|
371
|
-
// Only need to sign auth for `invokeHostFunction` operations
|
|
372
|
-
if (txn.operations[0].type !== 'invokeHostFunction')
|
|
373
|
-
return txn.toXDR()
|
|
374
|
-
|
|
375
359
|
if (!this.wallet)
|
|
376
360
|
throw new Error('Wallet not connected')
|
|
377
361
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
const auth = txn.operations[0].auth?.[index]
|
|
362
|
+
const entries = this.getAuthEntries(txn)
|
|
363
|
+
const auth = entries?.[index]
|
|
381
364
|
const context = auth?.rootInvocation().function()
|
|
382
365
|
|
|
383
|
-
if (!auth || !context)
|
|
366
|
+
if (!entries || !auth || !context)
|
|
384
367
|
throw new Error('No context found')
|
|
385
368
|
|
|
369
|
+
let context_arg: xdr.ScVal
|
|
370
|
+
|
|
386
371
|
switch (context.switch().name) {
|
|
387
372
|
case 'sorobanAuthorizedFunctionTypeContractFn':
|
|
388
373
|
switch (context.contractFn().contractAddress().switch().name) {
|
|
@@ -463,19 +448,14 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
463
448
|
rootInvocation: __check_auth_invocation,
|
|
464
449
|
});
|
|
465
450
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
return txn.toXDR()
|
|
451
|
+
entries.push(__check_auth)
|
|
469
452
|
}
|
|
470
453
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
? txn
|
|
475
|
-
: txn.toXDR(),
|
|
476
|
-
this.networkPassphrase
|
|
477
|
-
), { fee: '0' }).build()
|
|
454
|
+
public prepareTransaction(txn: Tx) {
|
|
455
|
+
return new Transaction(txn.toXDR(), this.networkPassphrase);
|
|
456
|
+
}
|
|
478
457
|
|
|
458
|
+
private getAuthEntries(txn: Transaction) {
|
|
479
459
|
if (txn.operations.length !== 1)
|
|
480
460
|
throw new Error('Must include only one Soroban operation')
|
|
481
461
|
|
|
@@ -487,7 +467,13 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
487
467
|
) throw new Error('Must include only one operation of type `invokeHostFunction` or `extendFootprintTtl` or `restoreFootprint`')
|
|
488
468
|
}
|
|
489
469
|
|
|
490
|
-
|
|
470
|
+
// Only need to sign auth for `invokeHostFunction` operations
|
|
471
|
+
if (txn.operations[0].type === 'invokeHostFunction') {
|
|
472
|
+
const entries = txn.operations[0].auth
|
|
473
|
+
|
|
474
|
+
if (entries && entries.length)
|
|
475
|
+
return entries
|
|
476
|
+
}
|
|
491
477
|
}
|
|
492
478
|
|
|
493
479
|
/* LATER
|
package/src/server.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SorobanRpc, xdr } from "@stellar/stellar-sdk"
|
|
1
|
+
import { SorobanRpc, Transaction, xdr } from "@stellar/stellar-sdk"
|
|
2
2
|
import { PasskeyBase } from "./base"
|
|
3
3
|
import base64url from "base64url"
|
|
4
4
|
|
|
@@ -123,13 +123,13 @@ export class PasskeyServer extends PasskeyBase {
|
|
|
123
123
|
- Add a method for getting a paginated or filtered list of all a wallet's events
|
|
124
124
|
*/
|
|
125
125
|
|
|
126
|
-
public async send(
|
|
126
|
+
public async send(txn: Transaction, fee?: number) {
|
|
127
127
|
if (!this.launchtubeUrl || !this.launchtubeJwt)
|
|
128
128
|
throw new Error('Launchtube service not configured')
|
|
129
129
|
|
|
130
130
|
const data = new FormData();
|
|
131
131
|
|
|
132
|
-
data.set('xdr',
|
|
132
|
+
data.set('xdr', txn.toXDR());
|
|
133
133
|
|
|
134
134
|
if (fee)
|
|
135
135
|
data.set('fee', fee.toString());
|
package/types/kit.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Client as PasskeyClient } from 'passkey-kit-sdk';
|
|
2
2
|
import { Client as FactoryClient } from 'passkey-factory-sdk';
|
|
3
|
-
import { xdr,
|
|
3
|
+
import { xdr, SorobanRpc, Keypair, Transaction } from '@stellar/stellar-sdk';
|
|
4
4
|
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 { type Tx } from '@stellar/stellar-sdk/contract';
|
|
8
9
|
export declare class PasskeyKit extends PasskeyBase {
|
|
9
10
|
rpc: SorobanRpc.Server;
|
|
10
11
|
rpcUrl: string;
|
|
@@ -28,7 +29,7 @@ export declare class PasskeyKit extends PasskeyBase {
|
|
|
28
29
|
createWallet(app: string, user: string): Promise<{
|
|
29
30
|
keyId: Buffer;
|
|
30
31
|
contractId: string;
|
|
31
|
-
|
|
32
|
+
built: Tx;
|
|
32
33
|
}>;
|
|
33
34
|
createKey(app: string, user: string, settings?: {
|
|
34
35
|
rpId?: string;
|
|
@@ -50,21 +51,22 @@ export declare class PasskeyKit extends PasskeyBase {
|
|
|
50
51
|
keyId?: 'any' | string | Uint8Array;
|
|
51
52
|
keypair?: Keypair;
|
|
52
53
|
validUntilLedgerSeq?: number;
|
|
53
|
-
}): Promise<
|
|
54
|
+
}): Promise<void>;
|
|
54
55
|
signAuthEntries(entries: xdr.SorobanAuthorizationEntry[], options?: {
|
|
55
56
|
rpId?: string;
|
|
56
57
|
keyId?: 'any' | string | Uint8Array;
|
|
57
58
|
keypair?: Keypair;
|
|
58
59
|
validUntilLedgerSeq?: number;
|
|
59
|
-
}): Promise<
|
|
60
|
-
sign(txn: Transaction
|
|
60
|
+
}): Promise<void>;
|
|
61
|
+
sign(txn: Transaction, options?: {
|
|
61
62
|
rpId?: string;
|
|
62
63
|
keyId?: 'any' | string | Uint8Array;
|
|
63
64
|
keypair?: Keypair;
|
|
64
65
|
validUntilLedgerSeq?: number;
|
|
65
|
-
}): Promise<
|
|
66
|
-
attachPolicy(txn: Transaction
|
|
67
|
-
|
|
66
|
+
}): Promise<void>;
|
|
67
|
+
attachPolicy(txn: Transaction, index: number, policy: string): Promise<void>;
|
|
68
|
+
prepareTransaction(txn: Tx): Transaction<import("@stellar/stellar-sdk").Memo<import("@stellar/stellar-sdk").MemoType>, import("@stellar/stellar-sdk").Operation[]>;
|
|
69
|
+
private getAuthEntries;
|
|
68
70
|
private getPublicKey;
|
|
69
71
|
private compactSignature;
|
|
70
72
|
}
|
package/types/server.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Transaction } from "@stellar/stellar-sdk";
|
|
1
2
|
import { PasskeyBase } from "./base";
|
|
2
3
|
export declare class PasskeyServer extends PasskeyBase {
|
|
3
4
|
launchtubeUrl: string | undefined;
|
|
@@ -19,5 +20,5 @@ export declare class PasskeyServer extends PasskeyBase {
|
|
|
19
20
|
expired?: boolean;
|
|
20
21
|
}[]>;
|
|
21
22
|
getContractId(keyId: string): Promise<any>;
|
|
22
|
-
send(
|
|
23
|
+
send(txn: Transaction, fee?: number): Promise<any>;
|
|
23
24
|
}
|