passkey-kit 0.10.15 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "passkey-kit",
3
- "version": "0.10.15",
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
- "passkey-kit-sdk": "0.6.5",
16
- "sac-sdk": "0.3.5"
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
@@ -136,7 +136,7 @@ export class PasskeyKit extends PasskeyBase {
136
136
  rpId?: string,
137
137
  keyId?: string | Uint8Array,
138
138
  getContractId?: (keyId: string) => Promise<string | undefined>,
139
- walletPublicKey?: string // TEMP for backwards compatibility when we seeded wallets from a factory address
139
+ walletPublicKey?: string // TEMP for backwards compatibility for when we seeded wallets from a factory address
140
140
  }) {
141
141
  let { keyId, rpId, getContractId, walletPublicKey } = opts || {}
142
142
  let keyIdBuffer: Buffer
@@ -164,17 +164,7 @@ export class PasskeyKit extends PasskeyBase {
164
164
  this.keyId = keyId
165
165
 
166
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
167
- let contractId: string | undefined = StrKey.encodeContract(hash(xdr.HashIdPreimage.envelopeTypeContractId(
168
- new xdr.HashIdPreimageContractId({
169
- networkId: hash(Buffer.from(this.networkPassphrase)),
170
- contractIdPreimage: xdr.ContractIdPreimage.contractIdPreimageFromAddress(
171
- new xdr.ContractIdPreimageFromAddress({
172
- address: Address.fromString(walletPublicKey || this.walletPublicKey).toScAddress(),
173
- salt: hash(keyIdBuffer),
174
- })
175
- )
176
- })
177
- ).toXDR()));
167
+ let contractId: string | undefined = this.encodeContract(this.walletPublicKey, keyIdBuffer);
178
168
 
179
169
  // attempt passkey id derivation
180
170
  try {
@@ -186,6 +176,19 @@ export class PasskeyKit extends PasskeyBase {
186
176
  contractId = getContractId && await getContractId(keyId)
187
177
  }
188
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
+
189
192
  if (!contractId)
190
193
  throw new Error('Failed to connect wallet')
191
194
 
@@ -556,6 +559,22 @@ export class PasskeyKit extends PasskeyBase {
556
559
  return signer_key
557
560
  }
558
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
+
559
578
  private async getPublicKey(response: AuthenticatorAttestationResponseJSON) {
560
579
  let publicKey: Buffer | undefined
561
580
 
package/types/kit.d.ts CHANGED
@@ -76,6 +76,7 @@ export declare class PasskeyKit extends PasskeyBase {
76
76
  private policy;
77
77
  private getSignerLimits;
78
78
  private getSignerKey;
79
+ private encodeContract;
79
80
  private getPublicKey;
80
81
  private compactSignature;
81
82
  }