@thru/programs 0.2.38 → 0.2.39

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.
@@ -7767,6 +7767,52 @@ function hexToBytes(hex) {
7767
7767
  }
7768
7768
 
7769
7769
  // src/passkey-manager/context.ts
7770
+ function buildDeferredAccountLists(params) {
7771
+ const programBytes = helpers.decodeAddress(params.programAddress ?? PASSKEY_MANAGER_PROGRAM_ADDRESS);
7772
+ const walletBytes = helpers.decodeAddress(params.walletAddress);
7773
+ const readWriteBytes = uniqueAccounts([walletBytes, ...params.readWriteAccounts]).filter((addr) => !bytesEqual(addr, programBytes)).sort(compareBytes);
7774
+ const readOnlyBytes = uniqueAccounts(params.readOnlyAccounts).filter(
7775
+ (addr) => !bytesEqual(addr, programBytes) && !readWriteBytes.some((candidate) => bytesEqual(candidate, addr))
7776
+ ).sort(compareBytes);
7777
+ return { programBytes, walletBytes, readWriteBytes, readOnlyBytes };
7778
+ }
7779
+ function buildWalletAccountContext(params) {
7780
+ const { programBytes, walletBytes, readWriteBytes, readOnlyBytes } = buildDeferredAccountLists(params);
7781
+ const readWriteAddresses = readWriteBytes.map(helpers.encodeAddress);
7782
+ const readOnlyAddresses = readOnlyBytes.map(helpers.encodeAddress);
7783
+ const findIndex = (target) => {
7784
+ if (bytesEqual(target, programBytes)) return 1;
7785
+ const rwIndex = readWriteBytes.findIndex((candidate) => bytesEqual(candidate, target));
7786
+ if (rwIndex >= 0) return rwIndex + 2;
7787
+ const roIndex = readOnlyBytes.findIndex((candidate) => bytesEqual(candidate, target));
7788
+ if (roIndex >= 0) return roIndex + 2 + readWriteBytes.length;
7789
+ return -1;
7790
+ };
7791
+ const walletAccountIdx = findIndex(walletBytes);
7792
+ if (walletAccountIdx < 2) {
7793
+ throw new Error("Wallet account must be a non-program account");
7794
+ }
7795
+ return {
7796
+ readWriteAddresses,
7797
+ readOnlyAddresses,
7798
+ walletAccountIdx,
7799
+ getAccountIndex: (pubkey) => {
7800
+ const idx = findIndex(pubkey);
7801
+ if (idx < 0) {
7802
+ throw new Error("Account not found in transaction accounts");
7803
+ }
7804
+ return idx;
7805
+ }
7806
+ };
7807
+ }
7808
+ function assertWalletFeePayerCompatible(params) {
7809
+ const feePayerBytes = helpers.decodeAddress(params.feePayerAddress);
7810
+ const { programBytes, walletBytes, readWriteBytes, readOnlyBytes } = buildDeferredAccountLists(params);
7811
+ const conflicts = [programBytes, walletBytes, ...readWriteBytes, ...readOnlyBytes];
7812
+ if (conflicts.some((account) => bytesEqual(account, feePayerBytes))) {
7813
+ throw new Error("Wallet fee payer must not overlap instruction accounts");
7814
+ }
7815
+ }
7770
7816
  function buildAccountContext(params) {
7771
7817
  const feePayerBytes = helpers.decodeAddress(params.feePayerAddress);
7772
7818
  const programBytes = helpers.decodeAddress(params.programAddress ?? PASSKEY_MANAGER_PROGRAM_ADDRESS);
@@ -8085,6 +8131,7 @@ exports.P256_N = P256_N;
8085
8131
  exports.PASSKEY_MANAGER_PROGRAM_ADDRESS = PASSKEY_MANAGER_PROGRAM_ADDRESS;
8086
8132
  exports.VALIDATE_CHALLENGE_DOMAIN = VALIDATE_CHALLENGE_DOMAIN;
8087
8133
  exports.arrayBufferToBase64Url = arrayBufferToBase64Url;
8134
+ exports.assertWalletFeePayerCompatible = assertWalletFeePayerCompatible;
8088
8135
  exports.base64UrlToArrayBuffer = base64UrlToArrayBuffer;
8089
8136
  exports.base64UrlToBytes = base64UrlToBytes;
8090
8137
  exports.bigIntToBytesBE = bigIntToBytesBE;
@@ -8092,6 +8139,7 @@ exports.buildAccountContext = buildAccountContext;
8092
8139
  exports.buildAuthority = buildAuthority;
8093
8140
  exports.buildAuthorityRecord = buildAuthorityRecord;
8094
8141
  exports.buildPasskeyReadWriteAccounts = buildPasskeyReadWriteAccounts;
8142
+ exports.buildWalletAccountContext = buildWalletAccountContext;
8095
8143
  exports.bytesEqual = bytesEqual;
8096
8144
  exports.bytesToBase64 = bytesToBase64;
8097
8145
  exports.bytesToBase64Url = bytesToBase64Url;