passkey-kit 0.2.0 → 0.2.1
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/cheatsheet +5 -0
- package/package.json +3 -3
- package/packages/passkey-factory-sdk/package.json +1 -1
- package/packages/passkey-factory-sdk/src/index.ts +3 -5
- package/packages/passkey-factory-sdk/types/index.d.ts +2 -3
- package/packages/passkey-kit-sdk/package.json +1 -1
- package/packages/passkey-kit-sdk/src/index.ts +25 -5
- package/packages/passkey-kit-sdk/types/index.d.ts +22 -3
- package/src/base.ts +18 -30
- package/src/kit.ts +30 -38
- package/types/base.d.ts +5 -11
- package/types/kit.d.ts +4 -7
package/cheatsheet
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "passkey-kit",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
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
|
"bigint-conversion": "^2.4.3",
|
|
15
15
|
"buffer": "^6.0.3",
|
|
16
16
|
"cbor-x": "^1.5.9",
|
|
17
|
-
"passkey-factory-sdk": "0.0.
|
|
18
|
-
"passkey-kit-sdk": "0.0.
|
|
17
|
+
"passkey-factory-sdk": "0.0.8",
|
|
18
|
+
"passkey-kit-sdk": "0.0.8"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"typescript": "^5.4.5"
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { Buffer } from "buffer";
|
|
2
2
|
import {
|
|
3
|
-
Client as ContractClient,
|
|
4
|
-
Spec as ContractSpec,
|
|
5
|
-
} from '@stellar/stellar-sdk/contract';
|
|
6
|
-
import type {
|
|
7
3
|
AssembledTransaction,
|
|
4
|
+
Client as ContractClient,
|
|
8
5
|
ClientOptions as ContractClientOptions,
|
|
9
6
|
Result,
|
|
7
|
+
Spec as ContractSpec,
|
|
10
8
|
} from '@stellar/stellar-sdk/contract';
|
|
11
9
|
|
|
12
10
|
if (typeof window !== 'undefined') {
|
|
@@ -17,7 +15,7 @@ if (typeof window !== 'undefined') {
|
|
|
17
15
|
export const networks = {
|
|
18
16
|
testnet: {
|
|
19
17
|
networkPassphrase: "Test SDF Network ; September 2015",
|
|
20
|
-
contractId: "
|
|
18
|
+
contractId: "CBXQAM53YVVPKAPS2NCSOCXTOK6HOXA3JLURVLD6VFQUHJPKFVBJIBHQ",
|
|
21
19
|
}
|
|
22
20
|
} as const
|
|
23
21
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Buffer } from "buffer";
|
|
2
|
-
import { Client as ContractClient } from '@stellar/stellar-sdk/contract';
|
|
3
|
-
import type { AssembledTransaction, ClientOptions as ContractClientOptions, Result } from '@stellar/stellar-sdk/contract';
|
|
2
|
+
import { AssembledTransaction, Client as ContractClient, ClientOptions as ContractClientOptions, Result } from '@stellar/stellar-sdk/contract';
|
|
4
3
|
export declare const networks: {
|
|
5
4
|
readonly testnet: {
|
|
6
5
|
readonly networkPassphrase: "Test SDF Network ; September 2015";
|
|
7
|
-
readonly contractId: "
|
|
6
|
+
readonly contractId: "CBXQAM53YVVPKAPS2NCSOCXTOK6HOXA3JLURVLD6VFQUHJPKFVBJIBHQ";
|
|
8
7
|
};
|
|
9
8
|
};
|
|
10
9
|
export declare const Errors: {
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { Buffer } from "buffer";
|
|
2
2
|
import {
|
|
3
|
-
Client as ContractClient,
|
|
4
|
-
Spec as ContractSpec,
|
|
5
|
-
} from '@stellar/stellar-sdk/contract';
|
|
6
|
-
import type {
|
|
7
3
|
AssembledTransaction,
|
|
4
|
+
Client as ContractClient,
|
|
8
5
|
ClientOptions as ContractClientOptions,
|
|
9
6
|
Result,
|
|
7
|
+
Spec as ContractSpec,
|
|
10
8
|
} from '@stellar/stellar-sdk/contract';
|
|
11
9
|
|
|
12
10
|
if (typeof window !== 'undefined') {
|
|
@@ -17,7 +15,7 @@ if (typeof window !== 'undefined') {
|
|
|
17
15
|
export const networks = {
|
|
18
16
|
testnet: {
|
|
19
17
|
networkPassphrase: "Test SDF Network ; September 2015",
|
|
20
|
-
contractId: "
|
|
18
|
+
contractId: "CBXQAM53YVVPKAPS2NCSOCXTOK6HOXA3JLURVLD6VFQUHJPKFVBJIBHQ",
|
|
21
19
|
}
|
|
22
20
|
} as const
|
|
23
21
|
|
|
@@ -82,6 +80,26 @@ export interface Client {
|
|
|
82
80
|
simulate?: boolean;
|
|
83
81
|
}) => Promise<AssembledTransaction<Result<void>>>
|
|
84
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Construct and simulate a upgrade transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object.
|
|
85
|
+
*/
|
|
86
|
+
upgrade: ({ hash }: { hash: Buffer }, options?: {
|
|
87
|
+
/**
|
|
88
|
+
* The fee to pay for the transaction. Default: BASE_FEE
|
|
89
|
+
*/
|
|
90
|
+
fee?: number;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The maximum amount of time to wait for the transaction to complete. Default: DEFAULT_TIMEOUT
|
|
94
|
+
*/
|
|
95
|
+
timeoutInSeconds?: number;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Whether to automatically simulate the transaction when constructing the AssembledTransaction. Default: true
|
|
99
|
+
*/
|
|
100
|
+
simulate?: boolean;
|
|
101
|
+
}) => Promise<AssembledTransaction<Result<void>>>
|
|
102
|
+
|
|
85
103
|
/**
|
|
86
104
|
* Construct and simulate a resudo transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object.
|
|
87
105
|
*/
|
|
@@ -148,6 +166,7 @@ export class Client extends ContractClient {
|
|
|
148
166
|
new ContractSpec(["AAAABAAAAAAAAAAAAAAABUVycm9yAAAAAAAACgAAAAAAAAAJTm90SW5pdGVkAAAAAAAAAQAAAAAAAAAITm90Rm91bmQAAAACAAAAAAAAAAxOb3RQZXJtaXR0ZWQAAAADAAAAAAAAAA1BbHJlYWR5SW5pdGVkAAAAAAAABAAAAAAAAAAOSnNvblBhcnNlRXJyb3IAAAAAAAUAAAAAAAAADkludmFsaWRDb250ZXh0AAAAAAAGAAAAAAAAACBDbGllbnREYXRhSnNvbkNoYWxsZW5nZUluY29ycmVjdAAAAAcAAAAAAAAAF1NlY3AyNTZyMVB1YmxpY0tleVBhcnNlAAAAAAgAAAAAAAAAF1NlY3AyNTZyMVNpZ25hdHVyZVBhcnNlAAAAAAkAAAAAAAAAFVNlY3AyNTZyMVZlcmlmeUZhaWxlZAAAAAAAAAo=",
|
|
149
167
|
"AAAAAAAAAAAAAAAKZXh0ZW5kX3R0bAAAAAAAAAAAAAA=",
|
|
150
168
|
"AAAAAAAAAAAAAAAEaW5pdAAAAAMAAAAAAAAAAmlkAAAAAAAOAAAAAAAAAAJwawAAAAAD7gAAAEEAAAAAAAAAB2ZhY3RvcnkAAAAAEwAAAAEAAAPpAAAD7QAAAAAAAAAD",
|
|
169
|
+
"AAAAAAAAAAAAAAAHdXBncmFkZQAAAAABAAAAAAAAAARoYXNoAAAD7gAAACAAAAABAAAD6QAAA+0AAAAAAAAAAw==",
|
|
151
170
|
"AAAAAAAAAAAAAAAGcmVzdWRvAAAAAAABAAAAAAAAAAJpZAAAAAAADgAAAAEAAAPpAAAD7QAAAAAAAAAD",
|
|
152
171
|
"AAAAAAAAAAAAAAAGcm1fc2lnAAAAAAABAAAAAAAAAAJpZAAAAAAADgAAAAEAAAPpAAAD7QAAAAAAAAAD",
|
|
153
172
|
"AAAAAAAAAAAAAAAHYWRkX3NpZwAAAAACAAAAAAAAAAJpZAAAAAAADgAAAAAAAAACcGsAAAAAA+4AAABBAAAAAQAAA+kAAAPtAAAAAAAAAAM=",
|
|
@@ -159,6 +178,7 @@ export class Client extends ContractClient {
|
|
|
159
178
|
public readonly fromJSON = {
|
|
160
179
|
extend_ttl: this.txFromJSON<null>,
|
|
161
180
|
init: this.txFromJSON<Result<void>>,
|
|
181
|
+
upgrade: this.txFromJSON<Result<void>>,
|
|
162
182
|
resudo: this.txFromJSON<Result<void>>,
|
|
163
183
|
rm_sig: this.txFromJSON<Result<void>>,
|
|
164
184
|
add_sig: this.txFromJSON<Result<void>>,
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Buffer } from "buffer";
|
|
2
|
-
import { Client as ContractClient } from '@stellar/stellar-sdk/contract';
|
|
3
|
-
import type { AssembledTransaction, ClientOptions as ContractClientOptions, Result } from '@stellar/stellar-sdk/contract';
|
|
2
|
+
import { AssembledTransaction, Client as ContractClient, ClientOptions as ContractClientOptions, Result } from '@stellar/stellar-sdk/contract';
|
|
4
3
|
export declare const networks: {
|
|
5
4
|
readonly testnet: {
|
|
6
5
|
readonly networkPassphrase: "Test SDF Network ; September 2015";
|
|
7
|
-
readonly contractId: "
|
|
6
|
+
readonly contractId: "CBXQAM53YVVPKAPS2NCSOCXTOK6HOXA3JLURVLD6VFQUHJPKFVBJIBHQ";
|
|
8
7
|
};
|
|
9
8
|
};
|
|
10
9
|
export declare const Errors: {
|
|
@@ -84,6 +83,25 @@ export interface Client {
|
|
|
84
83
|
*/
|
|
85
84
|
simulate?: boolean;
|
|
86
85
|
}) => Promise<AssembledTransaction<Result<void>>>;
|
|
86
|
+
/**
|
|
87
|
+
* Construct and simulate a upgrade transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object.
|
|
88
|
+
*/
|
|
89
|
+
upgrade: ({ hash }: {
|
|
90
|
+
hash: Buffer;
|
|
91
|
+
}, options?: {
|
|
92
|
+
/**
|
|
93
|
+
* The fee to pay for the transaction. Default: BASE_FEE
|
|
94
|
+
*/
|
|
95
|
+
fee?: number;
|
|
96
|
+
/**
|
|
97
|
+
* The maximum amount of time to wait for the transaction to complete. Default: DEFAULT_TIMEOUT
|
|
98
|
+
*/
|
|
99
|
+
timeoutInSeconds?: number;
|
|
100
|
+
/**
|
|
101
|
+
* Whether to automatically simulate the transaction when constructing the AssembledTransaction. Default: true
|
|
102
|
+
*/
|
|
103
|
+
simulate?: boolean;
|
|
104
|
+
}) => Promise<AssembledTransaction<Result<void>>>;
|
|
87
105
|
/**
|
|
88
106
|
* Construct and simulate a resudo transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object.
|
|
89
107
|
*/
|
|
@@ -149,6 +167,7 @@ export declare class Client extends ContractClient {
|
|
|
149
167
|
readonly fromJSON: {
|
|
150
168
|
extend_ttl: (json: string) => AssembledTransaction<null>;
|
|
151
169
|
init: (json: string) => AssembledTransaction<Result<void, import("@stellar/stellar-sdk/contract").ErrorMessage>>;
|
|
170
|
+
upgrade: (json: string) => AssembledTransaction<Result<void, import("@stellar/stellar-sdk/contract").ErrorMessage>>;
|
|
152
171
|
resudo: (json: string) => AssembledTransaction<Result<void, import("@stellar/stellar-sdk/contract").ErrorMessage>>;
|
|
153
172
|
rm_sig: (json: string) => AssembledTransaction<Result<void, import("@stellar/stellar-sdk/contract").ErrorMessage>>;
|
|
154
173
|
add_sig: (json: string) => AssembledTransaction<Result<void, import("@stellar/stellar-sdk/contract").ErrorMessage>>;
|
package/src/base.ts
CHANGED
|
@@ -1,54 +1,42 @@
|
|
|
1
|
-
import { Networks, Transaction, Horizon, FeeBumpTransaction } from '@stellar/stellar-sdk'
|
|
2
|
-
|
|
3
1
|
export class PasskeyBase {
|
|
4
|
-
public
|
|
5
|
-
public
|
|
6
|
-
public horizon: Horizon.Server
|
|
7
|
-
public feeBumpUrl: string | undefined
|
|
8
|
-
public feeBumpJwt: string | undefined
|
|
2
|
+
public launchtubeUrl: string | undefined
|
|
3
|
+
public launchtubeJwt: string | undefined
|
|
9
4
|
|
|
10
5
|
constructor(options: {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
feeBumpUrl?: string,
|
|
14
|
-
feeBumpJwt?: string,
|
|
6
|
+
launchtubeUrl?: string,
|
|
7
|
+
launchtubeJwt?: string,
|
|
15
8
|
}) {
|
|
16
9
|
const {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
feeBumpUrl,
|
|
20
|
-
feeBumpJwt,
|
|
10
|
+
launchtubeUrl,
|
|
11
|
+
launchtubeJwt,
|
|
21
12
|
} = options
|
|
22
13
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
this.horizon = new Horizon.Server(horizonUrl)
|
|
26
|
-
|
|
27
|
-
if (feeBumpUrl)
|
|
28
|
-
this.feeBumpUrl = feeBumpUrl
|
|
14
|
+
if (launchtubeUrl)
|
|
15
|
+
this.launchtubeUrl = launchtubeUrl
|
|
29
16
|
|
|
30
|
-
if (
|
|
31
|
-
this.
|
|
17
|
+
if (launchtubeJwt)
|
|
18
|
+
this.launchtubeJwt = launchtubeJwt
|
|
32
19
|
}
|
|
33
20
|
|
|
34
|
-
public async send(
|
|
21
|
+
public async send(xdr: string, fee: number = 10_000) {
|
|
22
|
+
if (!this.launchtubeUrl || !this.launchtubeJwt)
|
|
23
|
+
throw new Error('Launchtube service not configured')
|
|
24
|
+
|
|
35
25
|
const data = new FormData();
|
|
36
26
|
|
|
37
|
-
data.set('xdr',
|
|
27
|
+
data.set('xdr', xdr);
|
|
38
28
|
data.set('fee', fee.toString());
|
|
39
29
|
|
|
40
|
-
|
|
30
|
+
return fetch(this.launchtubeUrl, {
|
|
41
31
|
method: 'POST',
|
|
42
32
|
headers: {
|
|
43
|
-
authorization: `Bearer ${this.
|
|
33
|
+
authorization: `Bearer ${this.launchtubeJwt}`,
|
|
44
34
|
},
|
|
45
35
|
body: data
|
|
46
36
|
}).then(async (res) => {
|
|
47
37
|
if (res.ok)
|
|
48
|
-
return res.
|
|
38
|
+
return res.json()
|
|
49
39
|
else throw await res.json()
|
|
50
40
|
})
|
|
51
|
-
|
|
52
|
-
return this.horizon.submitTransaction(new FeeBumpTransaction(bumptxn, this.networkPassphrase))
|
|
53
41
|
}
|
|
54
42
|
}
|
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,
|
|
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"
|
|
@@ -14,10 +14,6 @@ import { PasskeyBase } from './base'
|
|
|
14
14
|
@Later
|
|
15
15
|
|
|
16
16
|
- Right now publicKey can mean a Stellar public key or a passkey public key, there should be a noted difference
|
|
17
|
-
|
|
18
|
-
- It's finally time to make a server and a client version of this package
|
|
19
|
-
Maybe. I want to support passing "bad" secret values on the client.
|
|
20
|
-
It's maybe only the server that could be smaller and cleaner by opting out out WebAuthN stuff
|
|
21
17
|
*/
|
|
22
18
|
|
|
23
19
|
export class PasskeyKit extends PasskeyBase {
|
|
@@ -25,57 +21,45 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
25
21
|
public sudoKeyId: string | undefined
|
|
26
22
|
public wallet: PasskeyClient | undefined
|
|
27
23
|
public factory: FactoryClient
|
|
28
|
-
public
|
|
29
|
-
// public networkPassphrase: Networks
|
|
30
|
-
// public horizonUrl: string
|
|
31
|
-
public horizon: Horizon.Server
|
|
24
|
+
public networkPassphrase: Networks
|
|
32
25
|
public rpcUrl: string
|
|
33
26
|
public rpc: SorobanRpc.Server
|
|
34
|
-
// public feeBumpUrl: string | undefined
|
|
35
|
-
// public feeBumpJwt: string | undefined
|
|
36
27
|
public factoryContractId: string = networks.testnet.contractId
|
|
37
28
|
|
|
38
29
|
/* TODO
|
|
39
30
|
- Consider adding the ability to pass in a keyId and maybe even a contractId in order to preconnect to a wallet
|
|
40
31
|
If just a keyId call `connectWallet` in order to get the contractId
|
|
41
32
|
If both keyId and contractId are passed in then we can skip the connectWallet call (though we won't get the sudoKeyId in that case)
|
|
42
|
-
We don't
|
|
33
|
+
We don't strictly _need_ this as a dev can just call `connectWallet` after class instantiation but it might be a nice convenience
|
|
43
34
|
@Later
|
|
44
35
|
*/
|
|
36
|
+
|
|
45
37
|
constructor(options: {
|
|
46
|
-
sequencePublicKey: string,
|
|
47
38
|
networkPassphrase: Networks,
|
|
48
|
-
horizonUrl: string,
|
|
49
39
|
rpcUrl: string,
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
launchtubeUrl?: string,
|
|
41
|
+
launchtubeJwt?: string,
|
|
52
42
|
/* TODO
|
|
53
43
|
- Maybe remove this? The factory should likely be baked in a bit more tightly
|
|
54
44
|
On the other hand once we have a standard interface the factory interface only uses the `deploy` method right now inside the interface
|
|
55
|
-
@
|
|
45
|
+
@No
|
|
56
46
|
*/
|
|
57
|
-
factoryContractId?: string,
|
|
47
|
+
factoryContractId?: string,
|
|
58
48
|
}) {
|
|
59
49
|
const {
|
|
60
|
-
sequencePublicKey,
|
|
61
50
|
networkPassphrase,
|
|
62
|
-
horizonUrl,
|
|
63
51
|
rpcUrl,
|
|
64
|
-
|
|
65
|
-
|
|
52
|
+
launchtubeUrl,
|
|
53
|
+
launchtubeJwt,
|
|
66
54
|
factoryContractId
|
|
67
55
|
} = options
|
|
68
56
|
|
|
69
57
|
super({
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
feeBumpUrl,
|
|
73
|
-
feeBumpJwt,
|
|
58
|
+
launchtubeUrl,
|
|
59
|
+
launchtubeJwt,
|
|
74
60
|
})
|
|
75
61
|
|
|
76
|
-
this.
|
|
77
|
-
|
|
78
|
-
this.horizon = new Horizon.Server(horizonUrl)
|
|
62
|
+
this.networkPassphrase = networkPassphrase
|
|
79
63
|
this.rpcUrl = rpcUrl
|
|
80
64
|
this.rpc = new SorobanRpc.Server(rpcUrl)
|
|
81
65
|
|
|
@@ -83,7 +67,6 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
83
67
|
this.factoryContractId = factoryContractId
|
|
84
68
|
|
|
85
69
|
this.factory = new FactoryClient({
|
|
86
|
-
publicKey: sequencePublicKey,
|
|
87
70
|
contractId: this.factoryContractId,
|
|
88
71
|
networkPassphrase,
|
|
89
72
|
rpcUrl
|
|
@@ -101,7 +84,6 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
101
84
|
const contractId = result.unwrap() as string
|
|
102
85
|
|
|
103
86
|
this.wallet = new PasskeyClient({
|
|
104
|
-
publicKey: this.sequencePublicKey,
|
|
105
87
|
contractId,
|
|
106
88
|
networkPassphrase: this.networkPassphrase,
|
|
107
89
|
rpcUrl: this.rpcUrl
|
|
@@ -164,7 +146,7 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
164
146
|
Also not sure what the use case would be for this where keyId wouldn't also be possible and better
|
|
165
147
|
@No
|
|
166
148
|
*/
|
|
167
|
-
|
|
149
|
+
|
|
168
150
|
// @ts-ignore
|
|
169
151
|
// https://github.com/stellar/js-stellar-base/issues/750
|
|
170
152
|
// if (id && StrKey.isValidContract(id)) {
|
|
@@ -210,7 +192,6 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
210
192
|
}
|
|
211
193
|
|
|
212
194
|
this.wallet = new PasskeyClient({
|
|
213
|
-
publicKey: this.sequencePublicKey,
|
|
214
195
|
contractId,
|
|
215
196
|
networkPassphrase: this.networkPassphrase,
|
|
216
197
|
rpcUrl: this.rpcUrl
|
|
@@ -225,7 +206,11 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
225
206
|
}
|
|
226
207
|
}
|
|
227
208
|
|
|
228
|
-
|
|
209
|
+
/* TODO
|
|
210
|
+
- Is there anything to be done with using the TS bindings `signAuthEntries` logic? Likely not but worth exploring
|
|
211
|
+
Perhaps not but maybe the js-sdk's `authorizeEntry` or `authorizeInvocation`
|
|
212
|
+
https://stellar.github.io/js-stellar-sdk/global.html#authorizeInvocation
|
|
213
|
+
*/
|
|
229
214
|
public async sign(
|
|
230
215
|
txn: Transaction | string,
|
|
231
216
|
options?: {
|
|
@@ -236,7 +221,7 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
236
221
|
// Default mirrors DEFAULT_TIMEOUT (currently 5 minutes) https://github.com/stellar/js-stellar-sdk/blob/master/src/contract/utils.ts#L7
|
|
237
222
|
let { keyId, ledgersToLive = 60 } = options || {}
|
|
238
223
|
|
|
239
|
-
//
|
|
224
|
+
// Hack to ensure we don't stack fees when simulating and assembling multiple times
|
|
240
225
|
txn = TransactionBuilder.cloneFrom(new Transaction(
|
|
241
226
|
typeof txn === 'string'
|
|
242
227
|
? txn
|
|
@@ -245,7 +230,12 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
245
230
|
), { fee: '0' }).build()
|
|
246
231
|
|
|
247
232
|
// NOTE hard coded to sign only Soroban transactions and only and always the first auth
|
|
248
|
-
|
|
233
|
+
/* TODO !!!
|
|
234
|
+
- Switch to support signing multiple and specific auth entries
|
|
235
|
+
Possibly pass in auth entry vs the entire txn
|
|
236
|
+
Probably a bad idea as it would add complexity to the user side to reassemble the signed entries
|
|
237
|
+
I think we can probably look at the list of auth entries and assume which ones we want to sign
|
|
238
|
+
*/
|
|
249
239
|
const op = txn.operations[0] as Operation.InvokeHostFunction
|
|
250
240
|
const auth = op.auth![0]
|
|
251
241
|
const lastLedger = await this.rpc.getLatestLedger().then(({ sequence }) => sequence)
|
|
@@ -261,7 +251,9 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
261
251
|
)
|
|
262
252
|
|
|
263
253
|
const authenticationResponse = await startAuthentication(
|
|
264
|
-
keyId === 'any'
|
|
254
|
+
keyId === 'any'
|
|
255
|
+
|| (keyId === 'sudo' && !this.sudoKeyId)
|
|
256
|
+
|| (!keyId && !this.keyId)
|
|
265
257
|
? {
|
|
266
258
|
challenge: base64url(authHash),
|
|
267
259
|
// rpId: undefined,
|
|
@@ -319,7 +311,7 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
319
311
|
|
|
320
312
|
if (
|
|
321
313
|
SorobanRpc.Api.isSimulationError(sim)
|
|
322
|
-
|| SorobanRpc.Api.isSimulationRestore(sim) // TODO handle
|
|
314
|
+
|| SorobanRpc.Api.isSimulationRestore(sim) // TODO handle state archival
|
|
323
315
|
) throw sim
|
|
324
316
|
|
|
325
317
|
return SorobanRpc.assembleTransaction(txn, sim).build().toXDR()
|
package/types/base.d.ts
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import { Networks, Transaction, Horizon } from '@stellar/stellar-sdk';
|
|
2
1
|
export declare class PasskeyBase {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
horizon: Horizon.Server;
|
|
6
|
-
feeBumpUrl: string | undefined;
|
|
7
|
-
feeBumpJwt: string | undefined;
|
|
2
|
+
launchtubeUrl: string | undefined;
|
|
3
|
+
launchtubeJwt: string | undefined;
|
|
8
4
|
constructor(options: {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
feeBumpUrl?: string;
|
|
12
|
-
feeBumpJwt?: string;
|
|
5
|
+
launchtubeUrl?: string;
|
|
6
|
+
launchtubeJwt?: string;
|
|
13
7
|
});
|
|
14
|
-
send(
|
|
8
|
+
send(xdr: string, fee?: number): Promise<any>;
|
|
15
9
|
}
|
package/types/kit.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Client as PasskeyClient } from 'passkey-kit-sdk';
|
|
2
2
|
import { Client as FactoryClient } from 'passkey-factory-sdk';
|
|
3
|
-
import { Networks, Transaction,
|
|
3
|
+
import { Networks, Transaction, SorobanRpc } from '@stellar/stellar-sdk';
|
|
4
4
|
import { Buffer } from 'buffer';
|
|
5
5
|
import { PasskeyBase } from './base';
|
|
6
6
|
export declare class PasskeyKit extends PasskeyBase {
|
|
@@ -8,18 +8,15 @@ export declare class PasskeyKit extends PasskeyBase {
|
|
|
8
8
|
sudoKeyId: string | undefined;
|
|
9
9
|
wallet: PasskeyClient | undefined;
|
|
10
10
|
factory: FactoryClient;
|
|
11
|
-
|
|
12
|
-
horizon: Horizon.Server;
|
|
11
|
+
networkPassphrase: Networks;
|
|
13
12
|
rpcUrl: string;
|
|
14
13
|
rpc: SorobanRpc.Server;
|
|
15
14
|
factoryContractId: string;
|
|
16
15
|
constructor(options: {
|
|
17
|
-
sequencePublicKey: string;
|
|
18
16
|
networkPassphrase: Networks;
|
|
19
|
-
horizonUrl: string;
|
|
20
17
|
rpcUrl: string;
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
launchtubeUrl?: string;
|
|
19
|
+
launchtubeJwt?: string;
|
|
23
20
|
factoryContractId?: string;
|
|
24
21
|
});
|
|
25
22
|
createWallet(name: string, user: string): Promise<{
|