passkey-kit 0.10.14 → 0.10.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/package.json +3 -3
- package/src/kit.ts +33 -13
- package/types/kit.d.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "passkey-kit",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.16",
|
|
4
4
|
"description": "A helper library for creating and using smart wallet accounts on the Stellar blockchain.",
|
|
5
5
|
"author": "Tyler van der Hoeven",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"@stellar/stellar-sdk": "^13.1.0",
|
|
13
13
|
"base64url": "^3.0.1",
|
|
14
14
|
"buffer": "^6.0.3",
|
|
15
|
-
"
|
|
16
|
-
"
|
|
15
|
+
"sac-sdk": "0.3.5",
|
|
16
|
+
"passkey-kit-sdk": "0.6.5"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@simplewebauthn/types": "^12.0.0",
|
package/src/kit.ts
CHANGED
|
@@ -135,9 +135,10 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
135
135
|
public async connectWallet(opts?: {
|
|
136
136
|
rpId?: string,
|
|
137
137
|
keyId?: string | Uint8Array,
|
|
138
|
-
getContractId?: (keyId: string) => Promise<string | undefined
|
|
138
|
+
getContractId?: (keyId: string) => Promise<string | undefined>,
|
|
139
|
+
walletPublicKey?: string // TEMP for backwards compatibility for when we seeded wallets from a factory address
|
|
139
140
|
}) {
|
|
140
|
-
let { keyId, rpId, getContractId } = opts || {}
|
|
141
|
+
let { keyId, rpId, getContractId, walletPublicKey } = opts || {}
|
|
141
142
|
let keyIdBuffer: Buffer
|
|
142
143
|
|
|
143
144
|
if (!keyId) {
|
|
@@ -163,17 +164,7 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
163
164
|
this.keyId = keyId
|
|
164
165
|
|
|
165
166
|
// Check for the contractId on-chain as a derivation from the keyId. This is the easiest and "cheapest" check however it will only work for the initially deployed passkey if it was used as derivation
|
|
166
|
-
let contractId: string | undefined =
|
|
167
|
-
new xdr.HashIdPreimageContractId({
|
|
168
|
-
networkId: hash(Buffer.from(this.networkPassphrase)),
|
|
169
|
-
contractIdPreimage: xdr.ContractIdPreimage.contractIdPreimageFromAddress(
|
|
170
|
-
new xdr.ContractIdPreimageFromAddress({
|
|
171
|
-
address: Address.fromString(this.walletPublicKey).toScAddress(),
|
|
172
|
-
salt: hash(keyIdBuffer),
|
|
173
|
-
})
|
|
174
|
-
)
|
|
175
|
-
})
|
|
176
|
-
).toXDR()));
|
|
167
|
+
let contractId: string | undefined = this.encodeContract(this.walletPublicKey, keyIdBuffer);
|
|
177
168
|
|
|
178
169
|
// attempt passkey id derivation
|
|
179
170
|
try {
|
|
@@ -185,6 +176,19 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
185
176
|
contractId = getContractId && await getContractId(keyId)
|
|
186
177
|
}
|
|
187
178
|
|
|
179
|
+
////
|
|
180
|
+
// TEMP for backwards compatibility for when we seeded wallets from a factory address
|
|
181
|
+
if (!contractId && walletPublicKey) {
|
|
182
|
+
contractId = this.encodeContract(walletPublicKey, keyIdBuffer);
|
|
183
|
+
|
|
184
|
+
try {
|
|
185
|
+
await this.rpc.getContractData(contractId, xdr.ScVal.scvLedgerKeyContractInstance())
|
|
186
|
+
} catch {
|
|
187
|
+
contractId = undefined
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
////
|
|
191
|
+
|
|
188
192
|
if (!contractId)
|
|
189
193
|
throw new Error('Failed to connect wallet')
|
|
190
194
|
|
|
@@ -555,6 +559,22 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
555
559
|
return signer_key
|
|
556
560
|
}
|
|
557
561
|
|
|
562
|
+
private encodeContract(walletPublicKey: string, keyIdBuffer: Buffer) {
|
|
563
|
+
let contractId: string | undefined = StrKey.encodeContract(hash(xdr.HashIdPreimage.envelopeTypeContractId(
|
|
564
|
+
new xdr.HashIdPreimageContractId({
|
|
565
|
+
networkId: hash(Buffer.from(this.networkPassphrase)),
|
|
566
|
+
contractIdPreimage: xdr.ContractIdPreimage.contractIdPreimageFromAddress(
|
|
567
|
+
new xdr.ContractIdPreimageFromAddress({
|
|
568
|
+
address: Address.fromString(walletPublicKey).toScAddress(),
|
|
569
|
+
salt: hash(keyIdBuffer),
|
|
570
|
+
})
|
|
571
|
+
)
|
|
572
|
+
})
|
|
573
|
+
).toXDR()));
|
|
574
|
+
|
|
575
|
+
return contractId
|
|
576
|
+
}
|
|
577
|
+
|
|
558
578
|
private async getPublicKey(response: AuthenticatorAttestationResponseJSON) {
|
|
559
579
|
let publicKey: Buffer | undefined
|
|
560
580
|
|
package/types/kit.d.ts
CHANGED
|
@@ -44,6 +44,7 @@ export declare class PasskeyKit extends PasskeyBase {
|
|
|
44
44
|
rpId?: string;
|
|
45
45
|
keyId?: string | Uint8Array;
|
|
46
46
|
getContractId?: (keyId: string) => Promise<string | undefined>;
|
|
47
|
+
walletPublicKey?: string;
|
|
47
48
|
}): Promise<{
|
|
48
49
|
keyId: Buffer<ArrayBufferLike>;
|
|
49
50
|
keyIdBase64: string;
|
|
@@ -75,6 +76,7 @@ export declare class PasskeyKit extends PasskeyBase {
|
|
|
75
76
|
private policy;
|
|
76
77
|
private getSignerLimits;
|
|
77
78
|
private getSignerKey;
|
|
79
|
+
private encodeContract;
|
|
78
80
|
private getPublicKey;
|
|
79
81
|
private compactSignature;
|
|
80
82
|
}
|