passkey-kit 0.0.24 → 0.0.26
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 +1 -1
- package/packages/passkey-factory-sdk/src/index.ts +4 -2
- package/packages/passkey-factory-sdk/types/index.d.ts +2 -1
- package/packages/passkey-kit-sdk/src/index.ts +4 -3
- package/packages/passkey-kit-sdk/types/index.d.ts +2 -1
- package/src/index.ts +29 -24
- package/types/index.d.ts +9 -5
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Buffer } from "buffer";
|
|
2
2
|
import {
|
|
3
|
-
AssembledTransaction,
|
|
4
3
|
Client as ContractClient,
|
|
4
|
+
Spec as ContractSpec,
|
|
5
|
+
} from '@stellar/stellar-sdk/contract';
|
|
6
|
+
import type {
|
|
7
|
+
AssembledTransaction,
|
|
5
8
|
ClientOptions as ContractClientOptions,
|
|
6
9
|
Result,
|
|
7
|
-
Spec as ContractSpec,
|
|
8
10
|
} from '@stellar/stellar-sdk/contract';
|
|
9
11
|
|
|
10
12
|
if (typeof window !== 'undefined') {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Buffer } from "buffer";
|
|
2
|
-
import {
|
|
2
|
+
import { Client as ContractClient } from '@stellar/stellar-sdk/contract';
|
|
3
|
+
import type { AssembledTransaction, ClientOptions as ContractClientOptions, Result } from '@stellar/stellar-sdk/contract';
|
|
3
4
|
export declare const networks: {
|
|
4
5
|
readonly testnet: {
|
|
5
6
|
readonly networkPassphrase: "Test SDF Network ; September 2015";
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Buffer } from "buffer";
|
|
2
2
|
import {
|
|
3
|
-
AssembledTransaction,
|
|
4
3
|
Client as ContractClient,
|
|
4
|
+
Spec as ContractSpec,
|
|
5
|
+
} from '@stellar/stellar-sdk/contract';
|
|
6
|
+
import type {
|
|
7
|
+
AssembledTransaction,
|
|
5
8
|
ClientOptions as ContractClientOptions,
|
|
6
9
|
Result,
|
|
7
|
-
Spec as ContractSpec,
|
|
8
10
|
} from '@stellar/stellar-sdk/contract';
|
|
9
11
|
|
|
10
12
|
if (typeof window !== 'undefined') {
|
|
@@ -12,7 +14,6 @@ if (typeof window !== 'undefined') {
|
|
|
12
14
|
window.Buffer = window.Buffer || Buffer;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
|
|
16
17
|
export const networks = {
|
|
17
18
|
testnet: {
|
|
18
19
|
networkPassphrase: "Test SDF Network ; September 2015",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Buffer } from "buffer";
|
|
2
|
-
import {
|
|
2
|
+
import { Client as ContractClient } from '@stellar/stellar-sdk/contract';
|
|
3
|
+
import type { AssembledTransaction, ClientOptions as ContractClientOptions, Result } from '@stellar/stellar-sdk/contract';
|
|
3
4
|
export declare const networks: {
|
|
4
5
|
readonly testnet: {
|
|
5
6
|
readonly networkPassphrase: "Test SDF Network ; September 2015";
|
package/src/index.ts
CHANGED
|
@@ -15,8 +15,8 @@ import { Buffer } from 'buffer'
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
export class PasskeyAccount {
|
|
18
|
-
public
|
|
19
|
-
public
|
|
18
|
+
public keyId: string | undefined
|
|
19
|
+
public sudoKeyId: string | undefined
|
|
20
20
|
public wallet: PasskeyClient | undefined
|
|
21
21
|
public factory: FactoryClient
|
|
22
22
|
public sequencePublicKey: string
|
|
@@ -86,6 +86,7 @@ export class PasskeyAccount {
|
|
|
86
86
|
})
|
|
87
87
|
|
|
88
88
|
return {
|
|
89
|
+
keyId,
|
|
89
90
|
contractId,
|
|
90
91
|
xdr: built!.toXDR() as string
|
|
91
92
|
}
|
|
@@ -112,11 +113,12 @@ export class PasskeyAccount {
|
|
|
112
113
|
attestation: "none",
|
|
113
114
|
});
|
|
114
115
|
|
|
115
|
-
if (!this.
|
|
116
|
-
this.
|
|
116
|
+
if (!this.keyId) {
|
|
117
|
+
this.keyId = startRegistrationResponse.id
|
|
117
118
|
|
|
118
|
-
|
|
119
|
-
|
|
119
|
+
// If there was no keyId we're likely about to deploy a new wallet so we should set the sudoKeyId
|
|
120
|
+
if (!this.sudoKeyId)
|
|
121
|
+
this.sudoKeyId = startRegistrationResponse.id
|
|
120
122
|
}
|
|
121
123
|
|
|
122
124
|
return this.getKey(startRegistrationResponse)
|
|
@@ -129,8 +131,8 @@ export class PasskeyAccount {
|
|
|
129
131
|
userVerification: "discouraged",
|
|
130
132
|
});
|
|
131
133
|
|
|
132
|
-
if (!this.
|
|
133
|
-
this.
|
|
134
|
+
if (!this.keyId)
|
|
135
|
+
this.keyId = startAuthenticationResponse.id
|
|
134
136
|
|
|
135
137
|
const { keyId } = await this.getKey(startAuthenticationResponse)
|
|
136
138
|
|
|
@@ -167,18 +169,21 @@ export class PasskeyAccount {
|
|
|
167
169
|
// get and set the sudo signer
|
|
168
170
|
await this.getData()
|
|
169
171
|
|
|
170
|
-
return
|
|
172
|
+
return {
|
|
173
|
+
keyId,
|
|
174
|
+
contractId
|
|
175
|
+
}
|
|
171
176
|
}
|
|
172
177
|
|
|
173
178
|
public async sign(
|
|
174
179
|
txn: Transaction | string,
|
|
175
180
|
options?: {
|
|
176
|
-
|
|
177
|
-
|
|
181
|
+
keyId?: 'any' | 'sudo' | string | Uint8Array
|
|
182
|
+
ledgersToLive?: number
|
|
178
183
|
}
|
|
179
184
|
) {
|
|
180
185
|
// Default mirrors DEFAULT_TIMEOUT (currently 5 minutes) https://github.com/stellar/js-stellar-sdk/blob/master/src/contract/utils.ts#L7
|
|
181
|
-
let {
|
|
186
|
+
let { keyId, ledgersToLive = 60 } = options || {}
|
|
182
187
|
|
|
183
188
|
// hack to ensure we don't stack fees when simulating and assembling multiple times
|
|
184
189
|
txn = TransactionBuilder.cloneFrom(new Transaction(
|
|
@@ -197,14 +202,14 @@ export class PasskeyAccount {
|
|
|
197
202
|
new xdr.HashIdPreimageSorobanAuthorization({
|
|
198
203
|
networkId: hash(Buffer.from(this.networkPassphrase, 'utf-8')),
|
|
199
204
|
nonce: auth.credentials().address().nonce(),
|
|
200
|
-
signatureExpirationLedger: lastLedger +
|
|
205
|
+
signatureExpirationLedger: lastLedger + ledgersToLive,
|
|
201
206
|
invocation: auth.rootInvocation()
|
|
202
207
|
})
|
|
203
208
|
).toXDR()
|
|
204
209
|
)
|
|
205
210
|
|
|
206
211
|
const authenticationResponse = await startAuthentication(
|
|
207
|
-
|
|
212
|
+
keyId === 'any' || (keyId === 'sudo' && !this.sudoKeyId)
|
|
208
213
|
? {
|
|
209
214
|
challenge: base64url(authHash),
|
|
210
215
|
// rpId: undefined,
|
|
@@ -215,11 +220,11 @@ export class PasskeyAccount {
|
|
|
215
220
|
// rpId: undefined,
|
|
216
221
|
allowCredentials: [
|
|
217
222
|
{
|
|
218
|
-
id:
|
|
219
|
-
? this.
|
|
220
|
-
:
|
|
221
|
-
? base64url(
|
|
222
|
-
:
|
|
223
|
+
id: keyId === 'sudo'
|
|
224
|
+
? this.sudoKeyId!
|
|
225
|
+
: keyId instanceof Uint8Array
|
|
226
|
+
? base64url(keyId)
|
|
227
|
+
: keyId || this.keyId!,
|
|
223
228
|
type: "public-key",
|
|
224
229
|
},
|
|
225
230
|
],
|
|
@@ -228,17 +233,17 @@ export class PasskeyAccount {
|
|
|
228
233
|
);
|
|
229
234
|
|
|
230
235
|
// set sudo if this is a sudo request
|
|
231
|
-
if (
|
|
232
|
-
this.
|
|
236
|
+
if (keyId === 'sudo')
|
|
237
|
+
this.sudoKeyId = authenticationResponse.id
|
|
233
238
|
|
|
234
239
|
// reset this.id to be the most recently used passkey
|
|
235
|
-
this.
|
|
240
|
+
this.keyId = authenticationResponse.id
|
|
236
241
|
|
|
237
242
|
const signatureRaw = base64url.toBuffer(authenticationResponse.response.signature);
|
|
238
243
|
const signature = this.convertEcdsaSignatureAsnToCompact(signatureRaw);
|
|
239
244
|
const creds = auth.credentials().address();
|
|
240
245
|
|
|
241
|
-
creds.signatureExpirationLedger(lastLedger +
|
|
246
|
+
creds.signatureExpirationLedger(lastLedger + ledgersToLive)
|
|
242
247
|
creds.signature(xdr.ScVal.scvMap([
|
|
243
248
|
new xdr.ScMapEntry({
|
|
244
249
|
key: xdr.ScVal.scvSymbol('authenticator_data'),
|
|
@@ -308,7 +313,7 @@ export class PasskeyAccount {
|
|
|
308
313
|
);
|
|
309
314
|
});
|
|
310
315
|
|
|
311
|
-
this.
|
|
316
|
+
this.sudoKeyId = base64url(data.get('sudo_sig'))
|
|
312
317
|
|
|
313
318
|
return data
|
|
314
319
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { Client as FactoryClient } from 'passkey-factory-sdk';
|
|
|
3
3
|
import { Networks, Transaction, Horizon, SorobanRpc } from '@stellar/stellar-sdk';
|
|
4
4
|
import { Buffer } from 'buffer';
|
|
5
5
|
export declare class PasskeyAccount {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
keyId: string | undefined;
|
|
7
|
+
sudoKeyId: string | undefined;
|
|
8
8
|
wallet: PasskeyClient | undefined;
|
|
9
9
|
factory: FactoryClient;
|
|
10
10
|
sequencePublicKey: string;
|
|
@@ -26,6 +26,7 @@ export declare class PasskeyAccount {
|
|
|
26
26
|
factoryContractId?: string;
|
|
27
27
|
});
|
|
28
28
|
createWallet(name: string, user: string): Promise<{
|
|
29
|
+
keyId: Buffer;
|
|
29
30
|
contractId: string;
|
|
30
31
|
xdr: string;
|
|
31
32
|
}>;
|
|
@@ -33,10 +34,13 @@ export declare class PasskeyAccount {
|
|
|
33
34
|
keyId: Buffer;
|
|
34
35
|
publicKey: Buffer | undefined;
|
|
35
36
|
}>;
|
|
36
|
-
connectWallet(): Promise<
|
|
37
|
+
connectWallet(): Promise<{
|
|
38
|
+
keyId: Buffer;
|
|
39
|
+
contractId: string;
|
|
40
|
+
}>;
|
|
37
41
|
sign(txn: Transaction | string, options?: {
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
keyId?: 'any' | 'sudo' | string | Uint8Array;
|
|
43
|
+
ledgersToLive?: number;
|
|
40
44
|
}): Promise<string>;
|
|
41
45
|
send(txn: Transaction, fee?: number): Promise<Horizon.HorizonApi.SubmitTransactionResponse>;
|
|
42
46
|
getData(): Promise<Map<string, any>>;
|