passkey-kit 0.7.13 → 0.7.15
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/src/index.ts +2 -2
- package/src/kit.ts +17 -8
- package/src/server.ts +26 -9
- package/types/index.d.ts +2 -2
- package/types/kit.d.ts +6 -4
- package/types/server.d.ts +5 -1
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PasskeyServer } from "./server"
|
|
2
|
-
import { PasskeyKit, SignerStore, SignerKey, type SignerLimits } from "./kit"
|
|
2
|
+
import { PasskeyKit, PasskeyClient, FactoryClient, SignerStore, SignerKey, type SignerLimits } from "./kit"
|
|
3
3
|
import { SACClient } from "./sac"
|
|
4
4
|
|
|
5
|
-
export {
|
|
5
|
+
export { PasskeyKit, PasskeyClient, FactoryClient, PasskeyServer, SACClient, SignerStore, SignerKey, type SignerLimits }
|
package/src/kit.ts
CHANGED
|
@@ -6,7 +6,10 @@ 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 } from '@stellar/stellar-sdk/contract'
|
|
9
|
+
import { AssembledTransaction, DEFAULT_TIMEOUT, type Tx } from '@stellar/stellar-sdk/contract'
|
|
10
|
+
|
|
11
|
+
export { Client as PasskeyClient } from 'passkey-kit-sdk'
|
|
12
|
+
export { Client as FactoryClient } from 'passkey-factory-sdk'
|
|
10
13
|
|
|
11
14
|
export class SignerKey {
|
|
12
15
|
private constructor(public key: "Policy" | "Ed25519" | "Secp256r1", public value: string) { }
|
|
@@ -184,7 +187,7 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
184
187
|
}
|
|
185
188
|
// if that fails look up from the `getContractId` function
|
|
186
189
|
catch {
|
|
187
|
-
contractId = getContractId
|
|
190
|
+
contractId = getContractId && await getContractId(keyId)
|
|
188
191
|
}
|
|
189
192
|
|
|
190
193
|
if (!contractId)
|
|
@@ -192,8 +195,8 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
192
195
|
|
|
193
196
|
this.wallet = new PasskeyClient({
|
|
194
197
|
contractId,
|
|
198
|
+
rpcUrl: this.rpcUrl,
|
|
195
199
|
networkPassphrase: this.networkPassphrase,
|
|
196
|
-
rpcUrl: this.rpcUrl
|
|
197
200
|
})
|
|
198
201
|
|
|
199
202
|
return {
|
|
@@ -390,8 +393,8 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
390
393
|
return entry
|
|
391
394
|
}
|
|
392
395
|
|
|
393
|
-
public sign<T>(
|
|
394
|
-
txn: AssembledTransaction<T
|
|
396
|
+
public async sign<T>(
|
|
397
|
+
txn: AssembledTransaction<T> | Tx | string,
|
|
395
398
|
options?: {
|
|
396
399
|
rpId?: string,
|
|
397
400
|
keyId?: 'any' | string | Uint8Array
|
|
@@ -400,15 +403,21 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
400
403
|
expiration?: number
|
|
401
404
|
}
|
|
402
405
|
) {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
+
if (typeof txn === 'string') {
|
|
407
|
+
txn = AssembledTransaction.fromXDR(this.wallet!.options, txn, this.wallet!.spec)
|
|
408
|
+
} else if (!(txn instanceof AssembledTransaction)) {
|
|
409
|
+
txn = AssembledTransaction.fromXDR(this.wallet!.options, txn.toXDR(), this.wallet!.spec)
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
await txn.signAuthEntries({
|
|
406
413
|
address: this.wallet!.options.contractId,
|
|
407
414
|
authorizeEntry: (entry) => {
|
|
408
415
|
const clone = xdr.SorobanAuthorizationEntry.fromXDR(entry.toXDR())
|
|
409
416
|
return this.signAuthEntry(clone, options)
|
|
410
417
|
},
|
|
411
418
|
})
|
|
419
|
+
|
|
420
|
+
return txn
|
|
412
421
|
}
|
|
413
422
|
|
|
414
423
|
public addSecp256r1(keyId: Uint8Array, publicKey: Uint8Array, limits: SignerLimits, store: SignerStore) {
|
package/src/server.ts
CHANGED
|
@@ -87,9 +87,29 @@ export class PasskeyServer extends PasskeyBase {
|
|
|
87
87
|
}[]
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
public async getContractId(
|
|
90
|
+
public async getContractId(options: {
|
|
91
|
+
keyId?: string,
|
|
92
|
+
publicKey?: string,
|
|
93
|
+
policy?: string,
|
|
94
|
+
}, index = 0) {
|
|
91
95
|
if (!this.mercuryUrl || !this.mercuryJwt)
|
|
92
|
-
|
|
96
|
+
throw new Error('Mercury service not configured')
|
|
97
|
+
|
|
98
|
+
let { keyId, publicKey, policy } = options || {}
|
|
99
|
+
|
|
100
|
+
if ([keyId, publicKey, policy].filter((arg) => !!arg).length > 1)
|
|
101
|
+
throw new Error('Exactly one of `options.keyId`, `options.publicKey`, or `options.policy` must be provided.');
|
|
102
|
+
|
|
103
|
+
let args: { key: string, kind: 'Secp256r1' | 'Ed25519' | 'Policy' }
|
|
104
|
+
|
|
105
|
+
if (keyId)
|
|
106
|
+
args = { key: keyId, kind: 'Secp256r1' }
|
|
107
|
+
else if (publicKey)
|
|
108
|
+
args = { key: publicKey, kind: 'Ed25519' }
|
|
109
|
+
else if (policy)
|
|
110
|
+
args = { key: policy, kind: 'Policy' }
|
|
111
|
+
else
|
|
112
|
+
throw new Error('Exactly one of `options.keyId`, `options.publicKey`, or `options.policy` must be provided.');
|
|
93
113
|
|
|
94
114
|
const res = await fetch(`${this.mercuryUrl}/zephyr/execute`, {
|
|
95
115
|
method: 'POST',
|
|
@@ -101,23 +121,20 @@ export class PasskeyServer extends PasskeyBase {
|
|
|
101
121
|
project_name: 'smart-wallets-data-multi-signer-multi-sig',
|
|
102
122
|
mode: {
|
|
103
123
|
Function: {
|
|
104
|
-
fname: "
|
|
105
|
-
arguments: JSON.stringify(
|
|
106
|
-
key: keyId,
|
|
107
|
-
kind: 'Secp256r1'
|
|
108
|
-
})
|
|
124
|
+
fname: "get_addresses_by_signer",
|
|
125
|
+
arguments: JSON.stringify(args)
|
|
109
126
|
}
|
|
110
127
|
}
|
|
111
128
|
})
|
|
112
129
|
})
|
|
113
130
|
.then(async (res) => {
|
|
114
131
|
if (res.ok)
|
|
115
|
-
return res.json()
|
|
132
|
+
return await res.json() as string[]
|
|
116
133
|
|
|
117
134
|
throw await res.json()
|
|
118
135
|
})
|
|
119
136
|
|
|
120
|
-
return res
|
|
137
|
+
return res[index]
|
|
121
138
|
}
|
|
122
139
|
|
|
123
140
|
/* LATER
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { PasskeyServer } from "./server";
|
|
2
|
-
import { PasskeyKit, SignerStore, SignerKey, type SignerLimits } from "./kit";
|
|
2
|
+
import { PasskeyKit, PasskeyClient, FactoryClient, SignerStore, SignerKey, type SignerLimits } from "./kit";
|
|
3
3
|
import { SACClient } from "./sac";
|
|
4
|
-
export {
|
|
4
|
+
export { PasskeyKit, PasskeyClient, FactoryClient, PasskeyServer, SACClient, SignerStore, SignerKey, type SignerLimits };
|
package/types/kit.d.ts
CHANGED
|
@@ -5,7 +5,9 @@ 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 } from '@stellar/stellar-sdk/contract';
|
|
8
|
+
import { AssembledTransaction, type Tx } from '@stellar/stellar-sdk/contract';
|
|
9
|
+
export { Client as PasskeyClient } from 'passkey-kit-sdk';
|
|
10
|
+
export { Client as FactoryClient } from 'passkey-factory-sdk';
|
|
9
11
|
export declare class SignerKey {
|
|
10
12
|
key: "Policy" | "Ed25519" | "Secp256r1";
|
|
11
13
|
value: string;
|
|
@@ -42,7 +44,7 @@ export declare class PasskeyKit extends PasskeyBase {
|
|
|
42
44
|
createWallet(app: string, user: string): Promise<{
|
|
43
45
|
keyId: Buffer;
|
|
44
46
|
contractId: string;
|
|
45
|
-
built:
|
|
47
|
+
built: Tx;
|
|
46
48
|
}>;
|
|
47
49
|
createKey(app: string, user: string, settings?: {
|
|
48
50
|
rpId?: string;
|
|
@@ -66,13 +68,13 @@ export declare class PasskeyKit extends PasskeyBase {
|
|
|
66
68
|
policy?: string;
|
|
67
69
|
expiration?: number;
|
|
68
70
|
}): Promise<xdr.SorobanAuthorizationEntry>;
|
|
69
|
-
sign<T>(txn: AssembledTransaction<T
|
|
71
|
+
sign<T>(txn: AssembledTransaction<T> | Tx | string, options?: {
|
|
70
72
|
rpId?: string;
|
|
71
73
|
keyId?: 'any' | string | Uint8Array;
|
|
72
74
|
keypair?: Keypair;
|
|
73
75
|
policy?: string;
|
|
74
76
|
expiration?: number;
|
|
75
|
-
}): Promise<
|
|
77
|
+
}): Promise<AssembledTransaction<T>>;
|
|
76
78
|
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
79
|
addEd25519(publicKey: string, limits: SignerLimits, store: SignerStore): Promise<AssembledTransaction<import("@stellar/stellar-sdk/contract").Result<void, import("@stellar/stellar-sdk/contract").ErrorMessage>>>;
|
|
78
80
|
addPolicy(policy: string, limits: SignerLimits, store: SignerStore): Promise<AssembledTransaction<import("@stellar/stellar-sdk/contract").Result<void, import("@stellar/stellar-sdk/contract").ErrorMessage>>>;
|
package/types/server.d.ts
CHANGED
|
@@ -19,6 +19,10 @@ export declare class PasskeyServer extends PasskeyBase {
|
|
|
19
19
|
limits: string;
|
|
20
20
|
expired?: boolean;
|
|
21
21
|
}[]>;
|
|
22
|
-
getContractId(
|
|
22
|
+
getContractId(options: {
|
|
23
|
+
keyId?: string;
|
|
24
|
+
publicKey?: string;
|
|
25
|
+
policy?: string;
|
|
26
|
+
}, index?: number): Promise<string>;
|
|
23
27
|
send(txn: Tx, fee?: number): Promise<any>;
|
|
24
28
|
}
|