passkey-kit 0.7.14 → 0.7.16
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 +1 -5
- package/package.json +1 -1
- package/src/index.ts +6 -5
- package/src/kit.ts +19 -38
- package/src/server.ts +34 -13
- package/src/types.ts +22 -0
- package/types/index.d.ts +6 -4
- package/types/kit.d.ts +8 -22
- package/types/server.d.ts +7 -1
- package/types/types.d.ts +13 -0
package/cheatsheet
CHANGED
|
@@ -15,8 +15,4 @@ export JWT=???
|
|
|
15
15
|
mercury-cli --jwt $JWT --local false --mainnet false deploy
|
|
16
16
|
mercury-cli --jwt $JWT --local false --mainnet false catchup --project-name "smart-wallets-data-multi-signer-multi-sig" --contracts CC3TMW7O43G3WJBZ2RVWMBBKL3B5KIO275D2LHQ43KJQF4TUOHFEYVOR
|
|
17
17
|
curl -X GET https://api.mercurydata.app/catchups/4
|
|
18
|
-
curl -X POST https://api.mercurydata.app/
|
|
19
|
-
curl -X POST https://api.mercurydata.app/zephyr/execute -H "Authorization: Bearer $MERCURY_JWT" -H 'Content-Type: application/json' -d '{"mode":{"Function": {"fname": "get_address_by_signer", "arguments": "{\"id\": [78,127,30,69,248,174,95,168,47,59,161,168,51,120,117,135,112,133,232,92]}"}}}'
|
|
20
|
-
curl -X POST https://api.mercurydata.app/zephyr/execute -H "Authorization: Bearer $MERCURY_JWT" -H 'Content-Type: application/json' -d '{"mode":{"Function": {"fname": "get_events_by_address", "arguments": "{\"address\": \"CA4G3X75IGGNXNLXFIVFNYIGC6YAVLA7KSIFFDBSR7RQ7KEZMZWLXQBH\"}"}}}'
|
|
21
|
-
|
|
22
|
-
cp -R ext/js-stellar-sdk/lib/. ext/@stellar/stellar-sdk/
|
|
18
|
+
curl -X POST https://api.mercurydata.app/v2/key -H "Authorization: Bearer $JWT"
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export {
|
|
1
|
+
export { SignerStore, SignerKey, type SignerLimits } from './types'
|
|
2
|
+
export { PasskeyKit } from "./kit"
|
|
3
|
+
export { PasskeyServer } from "./server"
|
|
4
|
+
export { SACClient } from "./sac"
|
|
5
|
+
export { Client as PasskeyClient } from 'passkey-kit-sdk'
|
|
6
|
+
export { Client as FactoryClient } from 'passkey-factory-sdk'
|
package/src/kit.ts
CHANGED
|
@@ -1,38 +1,13 @@
|
|
|
1
|
-
import { Client as PasskeyClient, type Signature, type SignerKey as SDKSignerKey, type SignerLimits as SDKSignerLimits } from 'passkey-kit-sdk'
|
|
2
1
|
import { Client as FactoryClient } from 'passkey-factory-sdk'
|
|
2
|
+
import { Client as PasskeyClient, type Signature, type SignerKey as SDKSignerKey, type SignerLimits as SDKSignerLimits } from 'passkey-kit-sdk'
|
|
3
3
|
import { StrKey, hash, xdr, SorobanRpc, Keypair, Address } from '@stellar/stellar-sdk'
|
|
4
|
-
import
|
|
5
|
-
import { startRegistration, startAuthentication } from "@simplewebauthn/browser"
|
|
4
|
+
import { AssembledTransaction, DEFAULT_TIMEOUT, type Tx } from '@stellar/stellar-sdk/contract'
|
|
6
5
|
import type { AuthenticatorAttestationResponseJSON, AuthenticatorSelectionCriteria } from "@simplewebauthn/types"
|
|
6
|
+
import { startRegistration, startAuthentication } from "@simplewebauthn/browser"
|
|
7
7
|
import { Buffer } from 'buffer'
|
|
8
|
+
import base64url from 'base64url'
|
|
9
|
+
import type { SignerKey, SignerLimits, SignerStore } from './types'
|
|
8
10
|
import { PasskeyBase } from './base'
|
|
9
|
-
import { AssembledTransaction, DEFAULT_TIMEOUT } from '@stellar/stellar-sdk/contract'
|
|
10
|
-
|
|
11
|
-
export { Client as PasskeyClient } from 'passkey-kit-sdk'
|
|
12
|
-
export { Client as FactoryClient } from 'passkey-factory-sdk'
|
|
13
|
-
|
|
14
|
-
export class SignerKey {
|
|
15
|
-
private constructor(public key: "Policy" | "Ed25519" | "Secp256r1", public value: string) { }
|
|
16
|
-
|
|
17
|
-
static Policy(policy: string): SignerKey {
|
|
18
|
-
return new SignerKey("Policy", policy);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
static Ed25519(publicKey: string): SignerKey {
|
|
22
|
-
return new SignerKey("Ed25519", publicKey);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
static Secp256r1(id: string): SignerKey {
|
|
26
|
-
return new SignerKey("Secp256r1", id);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export type SignerLimits = Map<string, SignerKey[] | undefined>
|
|
31
|
-
|
|
32
|
-
export enum SignerStore {
|
|
33
|
-
Persistent = 'Persistent',
|
|
34
|
-
Temporary = 'Temporary',
|
|
35
|
-
}
|
|
36
11
|
|
|
37
12
|
export class PasskeyKit extends PasskeyBase {
|
|
38
13
|
declare public rpc: SorobanRpc.Server
|
|
@@ -139,8 +114,8 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
139
114
|
}
|
|
140
115
|
|
|
141
116
|
public async connectWallet(opts?: {
|
|
142
|
-
keyId?: string | Uint8Array,
|
|
143
117
|
rpId?: string,
|
|
118
|
+
keyId?: string | Uint8Array,
|
|
144
119
|
getContractId?: (keyId: string) => Promise<string | undefined>
|
|
145
120
|
}) {
|
|
146
121
|
let { keyId, rpId, getContractId } = opts || {}
|
|
@@ -187,7 +162,7 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
187
162
|
}
|
|
188
163
|
// if that fails look up from the `getContractId` function
|
|
189
164
|
catch {
|
|
190
|
-
contractId = getContractId
|
|
165
|
+
contractId = getContractId && await getContractId(keyId)
|
|
191
166
|
}
|
|
192
167
|
|
|
193
168
|
if (!contractId)
|
|
@@ -195,8 +170,8 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
195
170
|
|
|
196
171
|
this.wallet = new PasskeyClient({
|
|
197
172
|
contractId,
|
|
173
|
+
rpcUrl: this.rpcUrl,
|
|
198
174
|
networkPassphrase: this.networkPassphrase,
|
|
199
|
-
rpcUrl: this.rpcUrl
|
|
200
175
|
})
|
|
201
176
|
|
|
202
177
|
return {
|
|
@@ -393,8 +368,8 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
393
368
|
return entry
|
|
394
369
|
}
|
|
395
370
|
|
|
396
|
-
public sign<T>(
|
|
397
|
-
txn: AssembledTransaction<T
|
|
371
|
+
public async sign<T>(
|
|
372
|
+
txn: AssembledTransaction<T> | Tx | string,
|
|
398
373
|
options?: {
|
|
399
374
|
rpId?: string,
|
|
400
375
|
keyId?: 'any' | string | Uint8Array
|
|
@@ -403,15 +378,21 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
403
378
|
expiration?: number
|
|
404
379
|
}
|
|
405
380
|
) {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
381
|
+
if (typeof txn === 'string') {
|
|
382
|
+
txn = AssembledTransaction.fromXDR(this.wallet!.options, txn, this.wallet!.spec)
|
|
383
|
+
} else if (!(txn instanceof AssembledTransaction)) {
|
|
384
|
+
txn = AssembledTransaction.fromXDR(this.wallet!.options, txn.toXDR(), this.wallet!.spec)
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
await txn.signAuthEntries({
|
|
409
388
|
address: this.wallet!.options.contractId,
|
|
410
389
|
authorizeEntry: (entry) => {
|
|
411
390
|
const clone = xdr.SorobanAuthorizationEntry.fromXDR(entry.toXDR())
|
|
412
391
|
return this.signAuthEntry(clone, options)
|
|
413
392
|
},
|
|
414
393
|
})
|
|
394
|
+
|
|
395
|
+
return txn
|
|
415
396
|
}
|
|
416
397
|
|
|
417
398
|
public addSecp256r1(keyId: Uint8Array, publicKey: Uint8Array, limits: SignerLimits, store: SignerStore) {
|
package/src/server.ts
CHANGED
|
@@ -8,6 +8,7 @@ export class PasskeyServer extends PasskeyBase {
|
|
|
8
8
|
public launchtubeJwt: string | undefined
|
|
9
9
|
public mercuryUrl: string | undefined
|
|
10
10
|
public mercuryJwt: string | undefined
|
|
11
|
+
public mercuryKey: string | undefined
|
|
11
12
|
|
|
12
13
|
constructor(options: {
|
|
13
14
|
rpcUrl?: string,
|
|
@@ -15,6 +16,7 @@ export class PasskeyServer extends PasskeyBase {
|
|
|
15
16
|
launchtubeJwt?: string,
|
|
16
17
|
mercuryUrl?: string,
|
|
17
18
|
mercuryJwt?: string,
|
|
19
|
+
mercuryKey?: string,
|
|
18
20
|
}) {
|
|
19
21
|
const {
|
|
20
22
|
rpcUrl,
|
|
@@ -22,6 +24,7 @@ export class PasskeyServer extends PasskeyBase {
|
|
|
22
24
|
launchtubeJwt,
|
|
23
25
|
mercuryUrl,
|
|
24
26
|
mercuryJwt,
|
|
27
|
+
mercuryKey,
|
|
25
28
|
} = options
|
|
26
29
|
|
|
27
30
|
super(rpcUrl)
|
|
@@ -37,17 +40,20 @@ export class PasskeyServer extends PasskeyBase {
|
|
|
37
40
|
|
|
38
41
|
if (mercuryJwt)
|
|
39
42
|
this.mercuryJwt = mercuryJwt
|
|
43
|
+
|
|
44
|
+
if (mercuryKey)
|
|
45
|
+
this.mercuryKey = mercuryKey
|
|
40
46
|
}
|
|
41
47
|
|
|
42
48
|
public async getSigners(contractId: string) {
|
|
43
|
-
if (!this.rpc || !this.mercuryUrl || !this.mercuryJwt)
|
|
49
|
+
if (!this.rpc || !this.mercuryUrl || (!this.mercuryJwt && !this.mercuryKey))
|
|
44
50
|
throw new Error('Mercury service not configured')
|
|
45
51
|
|
|
46
52
|
const signers = await fetch(`${this.mercuryUrl}/zephyr/execute`, {
|
|
47
53
|
method: 'POST',
|
|
48
54
|
headers: {
|
|
49
55
|
'Content-Type': 'application/json',
|
|
50
|
-
Authorization: `Bearer ${this.mercuryJwt}`
|
|
56
|
+
Authorization: this.mercuryJwt ? `Bearer ${this.mercuryJwt}` : this.mercuryKey!
|
|
51
57
|
},
|
|
52
58
|
body: JSON.stringify({
|
|
53
59
|
project_name: 'smart-wallets-data-multi-signer-multi-sig',
|
|
@@ -87,37 +93,52 @@ export class PasskeyServer extends PasskeyBase {
|
|
|
87
93
|
}[]
|
|
88
94
|
}
|
|
89
95
|
|
|
90
|
-
public async getContractId(
|
|
91
|
-
|
|
92
|
-
|
|
96
|
+
public async getContractId(options: {
|
|
97
|
+
keyId?: string,
|
|
98
|
+
publicKey?: string,
|
|
99
|
+
policy?: string,
|
|
100
|
+
}, index = 0) {
|
|
101
|
+
if (!this.mercuryUrl || (!this.mercuryJwt && !this.mercuryKey))
|
|
102
|
+
throw new Error('Mercury service not configured')
|
|
103
|
+
|
|
104
|
+
let { keyId, publicKey, policy } = options || {}
|
|
105
|
+
|
|
106
|
+
if ([keyId, publicKey, policy].filter((arg) => !!arg).length > 1)
|
|
107
|
+
throw new Error('Exactly one of `options.keyId`, `options.publicKey`, or `options.policy` must be provided.');
|
|
108
|
+
|
|
109
|
+
let args: { key: string, kind: 'Secp256r1' | 'Ed25519' | 'Policy' }
|
|
110
|
+
|
|
111
|
+
if (keyId)
|
|
112
|
+
args = { key: keyId, kind: 'Secp256r1' }
|
|
113
|
+
else if (publicKey)
|
|
114
|
+
args = { key: publicKey, kind: 'Ed25519' }
|
|
115
|
+
else if (policy)
|
|
116
|
+
args = { key: policy, kind: 'Policy' }
|
|
93
117
|
|
|
94
118
|
const res = await fetch(`${this.mercuryUrl}/zephyr/execute`, {
|
|
95
119
|
method: 'POST',
|
|
96
120
|
headers: {
|
|
97
121
|
'Content-Type': 'application/json',
|
|
98
|
-
Authorization: `Bearer ${this.mercuryJwt}`
|
|
122
|
+
Authorization: this.mercuryJwt ? `Bearer ${this.mercuryJwt}` : this.mercuryKey!
|
|
99
123
|
},
|
|
100
124
|
body: JSON.stringify({
|
|
101
125
|
project_name: 'smart-wallets-data-multi-signer-multi-sig',
|
|
102
126
|
mode: {
|
|
103
127
|
Function: {
|
|
104
|
-
fname: "
|
|
105
|
-
arguments: JSON.stringify(
|
|
106
|
-
key: keyId,
|
|
107
|
-
kind: 'Secp256r1'
|
|
108
|
-
})
|
|
128
|
+
fname: "get_addresses_by_signer",
|
|
129
|
+
arguments: JSON.stringify(args!)
|
|
109
130
|
}
|
|
110
131
|
}
|
|
111
132
|
})
|
|
112
133
|
})
|
|
113
134
|
.then(async (res) => {
|
|
114
135
|
if (res.ok)
|
|
115
|
-
return res.json()
|
|
136
|
+
return await res.json() as string[]
|
|
116
137
|
|
|
117
138
|
throw await res.json()
|
|
118
139
|
})
|
|
119
140
|
|
|
120
|
-
return res
|
|
141
|
+
return res[index]
|
|
121
142
|
}
|
|
122
143
|
|
|
123
144
|
/* LATER
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export class SignerKey {
|
|
2
|
+
private constructor(public key: "Policy" | "Ed25519" | "Secp256r1", public value: string) { }
|
|
3
|
+
|
|
4
|
+
static Policy(policy: string): SignerKey {
|
|
5
|
+
return new SignerKey("Policy", policy);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
static Ed25519(publicKey: string): SignerKey {
|
|
9
|
+
return new SignerKey("Ed25519", publicKey);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static Secp256r1(id: string): SignerKey {
|
|
13
|
+
return new SignerKey("Secp256r1", id);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type SignerLimits = Map<string, SignerKey[] | undefined>
|
|
18
|
+
|
|
19
|
+
export enum SignerStore {
|
|
20
|
+
Persistent = 'Persistent',
|
|
21
|
+
Temporary = 'Temporary',
|
|
22
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export {
|
|
1
|
+
export { SignerStore, SignerKey, type SignerLimits } from './types';
|
|
2
|
+
export { PasskeyKit } from "./kit";
|
|
3
|
+
export { PasskeyServer } from "./server";
|
|
4
|
+
export { SACClient } from "./sac";
|
|
5
|
+
export { Client as PasskeyClient } from 'passkey-kit-sdk';
|
|
6
|
+
export { Client as FactoryClient } from 'passkey-factory-sdk';
|
package/types/kit.d.ts
CHANGED
|
@@ -1,26 +1,12 @@
|
|
|
1
|
-
import { Client as PasskeyClient } from 'passkey-kit-sdk';
|
|
2
1
|
import { Client as FactoryClient } from 'passkey-factory-sdk';
|
|
2
|
+
import { Client as PasskeyClient } from 'passkey-kit-sdk';
|
|
3
3
|
import { xdr, SorobanRpc, Keypair } from '@stellar/stellar-sdk';
|
|
4
|
-
import {
|
|
4
|
+
import { AssembledTransaction, type Tx } from '@stellar/stellar-sdk/contract';
|
|
5
5
|
import type { AuthenticatorSelectionCriteria } from "@simplewebauthn/types";
|
|
6
|
+
import { startRegistration, startAuthentication } from "@simplewebauthn/browser";
|
|
6
7
|
import { Buffer } from 'buffer';
|
|
8
|
+
import type { SignerKey, SignerLimits, SignerStore } from './types';
|
|
7
9
|
import { PasskeyBase } from './base';
|
|
8
|
-
import { AssembledTransaction } from '@stellar/stellar-sdk/contract';
|
|
9
|
-
export { Client as PasskeyClient } from 'passkey-kit-sdk';
|
|
10
|
-
export { Client as FactoryClient } from 'passkey-factory-sdk';
|
|
11
|
-
export declare class SignerKey {
|
|
12
|
-
key: "Policy" | "Ed25519" | "Secp256r1";
|
|
13
|
-
value: string;
|
|
14
|
-
private constructor();
|
|
15
|
-
static Policy(policy: string): SignerKey;
|
|
16
|
-
static Ed25519(publicKey: string): SignerKey;
|
|
17
|
-
static Secp256r1(id: string): SignerKey;
|
|
18
|
-
}
|
|
19
|
-
export type SignerLimits = Map<string, SignerKey[] | undefined>;
|
|
20
|
-
export declare enum SignerStore {
|
|
21
|
-
Persistent = "Persistent",
|
|
22
|
-
Temporary = "Temporary"
|
|
23
|
-
}
|
|
24
10
|
export declare class PasskeyKit extends PasskeyBase {
|
|
25
11
|
rpc: SorobanRpc.Server;
|
|
26
12
|
rpcUrl: string;
|
|
@@ -44,7 +30,7 @@ export declare class PasskeyKit extends PasskeyBase {
|
|
|
44
30
|
createWallet(app: string, user: string): Promise<{
|
|
45
31
|
keyId: Buffer;
|
|
46
32
|
contractId: string;
|
|
47
|
-
built:
|
|
33
|
+
built: Tx;
|
|
48
34
|
}>;
|
|
49
35
|
createKey(app: string, user: string, settings?: {
|
|
50
36
|
rpId?: string;
|
|
@@ -54,8 +40,8 @@ export declare class PasskeyKit extends PasskeyBase {
|
|
|
54
40
|
publicKey: Buffer;
|
|
55
41
|
}>;
|
|
56
42
|
connectWallet(opts?: {
|
|
57
|
-
keyId?: string | Uint8Array;
|
|
58
43
|
rpId?: string;
|
|
44
|
+
keyId?: string | Uint8Array;
|
|
59
45
|
getContractId?: (keyId: string) => Promise<string | undefined>;
|
|
60
46
|
}): Promise<{
|
|
61
47
|
keyId: Buffer;
|
|
@@ -68,13 +54,13 @@ export declare class PasskeyKit extends PasskeyBase {
|
|
|
68
54
|
policy?: string;
|
|
69
55
|
expiration?: number;
|
|
70
56
|
}): Promise<xdr.SorobanAuthorizationEntry>;
|
|
71
|
-
sign<T>(txn: AssembledTransaction<T
|
|
57
|
+
sign<T>(txn: AssembledTransaction<T> | Tx | string, options?: {
|
|
72
58
|
rpId?: string;
|
|
73
59
|
keyId?: 'any' | string | Uint8Array;
|
|
74
60
|
keypair?: Keypair;
|
|
75
61
|
policy?: string;
|
|
76
62
|
expiration?: number;
|
|
77
|
-
}): Promise<
|
|
63
|
+
}): Promise<AssembledTransaction<T>>;
|
|
78
64
|
addSecp256r1(keyId: Uint8Array, publicKey: Uint8Array, limits: SignerLimits, store: SignerStore): Promise<AssembledTransaction<import("@stellar/stellar-sdk/contract").Result<void, import("@stellar/stellar-sdk/contract").ErrorMessage>>>;
|
|
79
65
|
addEd25519(publicKey: string, limits: SignerLimits, store: SignerStore): Promise<AssembledTransaction<import("@stellar/stellar-sdk/contract").Result<void, import("@stellar/stellar-sdk/contract").ErrorMessage>>>;
|
|
80
66
|
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
|
@@ -5,12 +5,14 @@ export declare class PasskeyServer extends PasskeyBase {
|
|
|
5
5
|
launchtubeJwt: string | undefined;
|
|
6
6
|
mercuryUrl: string | undefined;
|
|
7
7
|
mercuryJwt: string | undefined;
|
|
8
|
+
mercuryKey: string | undefined;
|
|
8
9
|
constructor(options: {
|
|
9
10
|
rpcUrl?: string;
|
|
10
11
|
launchtubeUrl?: string;
|
|
11
12
|
launchtubeJwt?: string;
|
|
12
13
|
mercuryUrl?: string;
|
|
13
14
|
mercuryJwt?: string;
|
|
15
|
+
mercuryKey?: string;
|
|
14
16
|
});
|
|
15
17
|
getSigners(contractId: string): Promise<{
|
|
16
18
|
kind: string;
|
|
@@ -19,6 +21,10 @@ export declare class PasskeyServer extends PasskeyBase {
|
|
|
19
21
|
limits: string;
|
|
20
22
|
expired?: boolean;
|
|
21
23
|
}[]>;
|
|
22
|
-
getContractId(
|
|
24
|
+
getContractId(options: {
|
|
25
|
+
keyId?: string;
|
|
26
|
+
publicKey?: string;
|
|
27
|
+
policy?: string;
|
|
28
|
+
}, index?: number): Promise<string>;
|
|
23
29
|
send(txn: Tx, fee?: number): Promise<any>;
|
|
24
30
|
}
|
package/types/types.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class SignerKey {
|
|
2
|
+
key: "Policy" | "Ed25519" | "Secp256r1";
|
|
3
|
+
value: string;
|
|
4
|
+
private constructor();
|
|
5
|
+
static Policy(policy: string): SignerKey;
|
|
6
|
+
static Ed25519(publicKey: string): SignerKey;
|
|
7
|
+
static Secp256r1(id: string): SignerKey;
|
|
8
|
+
}
|
|
9
|
+
export type SignerLimits = Map<string, SignerKey[] | undefined>;
|
|
10
|
+
export declare enum SignerStore {
|
|
11
|
+
Persistent = "Persistent",
|
|
12
|
+
Temporary = "Temporary"
|
|
13
|
+
}
|