@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.
@@ -115,6 +115,15 @@ interface AccountContext {
115
115
  walletAccountIdx: number;
116
116
  getAccountIndex: (pubkey: Uint8Array) => number;
117
117
  }
118
+ /** Account indices for a wallet-wrapped target instruction whose fee payer is
119
+ * selected later by the wallet. Index 0 is reserved for that fee payer and
120
+ * index 1 for the wrapper program. */
121
+ interface WalletAccountContext {
122
+ readWriteAddresses: string[];
123
+ readOnlyAddresses: string[];
124
+ walletAccountIdx: number;
125
+ getAccountIndex: (pubkey: Uint8Array) => number;
126
+ }
118
127
  interface RegisterCredentialInstructionParams {
119
128
  walletAccountIdx: number;
120
129
  lookupAccountIdx: number;
@@ -200,6 +209,23 @@ declare function createCredentialLookupSeed(credentialId: Uint8Array): Promise<U
200
209
  */
201
210
  declare function deriveCredentialLookupAddress(credentialId: Uint8Array, programAddress: string): Promise<Uint8Array>;
202
211
 
212
+ interface WalletAccountContextParams {
213
+ walletAddress: string;
214
+ readWriteAccounts: Uint8Array[];
215
+ readOnlyAccounts: Uint8Array[];
216
+ programAddress?: string;
217
+ }
218
+ /**
219
+ * Build account indices for an instruction that a wallet will wrap and pay for.
220
+ * The concrete fee payer is intentionally unknown here; index 0 is reserved for
221
+ * it and index 1 for the wrapper program.
222
+ */
223
+ declare function buildWalletAccountContext(params: WalletAccountContextParams): WalletAccountContext;
224
+ /** Ensure the wallet-selected fee payer does not invalidate indices that were
225
+ * encoded before that payer was known. */
226
+ declare function assertWalletFeePayerCompatible(params: WalletAccountContextParams & {
227
+ feePayerAddress: string;
228
+ }): void;
203
229
  /**
204
230
  * Build account context for passkey manager transactions.
205
231
  * Handles account deduplication, sorting, and index lookup.
@@ -353,4 +379,4 @@ declare function base64UrlToBytes(base64Url: string): Uint8Array;
353
379
  declare function bytesToHex(bytes: Uint8Array): string;
354
380
  declare function hexToBytes(hex: string): Uint8Array;
355
381
 
356
- export { AUTHORITY_BYTES, AUTHORITY_RECORD_BYTES, AUTHORITY_TAG_PASSKEY, AUTHORITY_TAG_PUBKEY, type AccountContext, type AddAuthorityInstructionParams, type Authority, type AuthorityRecord, type CheckablePasskeyAuthorityIdentity, type CreateInstructionParams, INSTRUCTION_ADD_AUTHORITY, INSTRUCTION_CREATE, INSTRUCTION_REGISTER_CREDENTIAL, INSTRUCTION_REMOVE_AUTHORITY, INSTRUCTION_TRANSFER, INSTRUCTION_VALIDATE, LONG_LIVED_AUTHORITY_EXPIRY_SECONDS, P256_HALF_N, P256_N, PASSKEY_MANAGER_PROGRAM_ADDRESS, type ParsedAuthority, type PasskeyAuthorityIdentity, type PasskeyAuthorityTarget, type PasskeyDiscoverableSigningResult, type PasskeyMetadata, type PasskeyRegistrationResult, type PasskeySigningResult, type PreparePasskeyAuthorityTargetsOptions, type RegisterCredentialInstructionParams, type RemoveAuthorityInstructionParams, type TargetInstructionParams, type TransactionExecutionSummary, type TransferInstructionParams, VALIDATE_CHALLENGE_DOMAIN, type ValidateInstructionParams, type WalletAuthorities, type WalletSigner, arrayBufferToBase64Url, base64UrlToArrayBuffer, base64UrlToBytes, bigIntToBytesBE, buildAccountContext, buildAuthority, buildAuthorityRecord, buildPasskeyReadWriteAccounts, bytesEqual, bytesToBase64, bytesToBase64Url, bytesToBigIntBE, bytesToHex, compareBytes, concatenateInstructions, createAuthorityRecord, createCredentialLookupSeed, createSessionAuthorityRecord, createValidateChallenge, createWalletSeed, deriveCredentialLookupAddress, deriveWalletAddress, encodeAddAuthorityInstruction, encodeCreateInstruction, encodeInvokeInstruction, encodeLegacyAddAuthorityInstruction, encodeLegacyCreateInstruction, encodeRegisterCredentialInstruction, encodeRemoveAuthorityInstruction, encodeTransferInstruction, encodeValidateInstruction, fetchWalletNonce, findPasskeyAuthorityIndexForIdentity, findPasskeyAuthorityIndexInWalletData, formatAuthorityPubkey, hexToBytes, isPasskeyAuthorityCheckable, normalizeLowS, normalizeSignatureComponent, parseCredentialLookupWallet, parseDerSignature, parseWalletAuthorities, parseWalletNonce, preparePasskeyAuthorityTargets, resolvePasskeyAuthorityIndex, uniqueAccounts };
382
+ export { AUTHORITY_BYTES, AUTHORITY_RECORD_BYTES, AUTHORITY_TAG_PASSKEY, AUTHORITY_TAG_PUBKEY, type AccountContext, type AddAuthorityInstructionParams, type Authority, type AuthorityRecord, type CheckablePasskeyAuthorityIdentity, type CreateInstructionParams, INSTRUCTION_ADD_AUTHORITY, INSTRUCTION_CREATE, INSTRUCTION_REGISTER_CREDENTIAL, INSTRUCTION_REMOVE_AUTHORITY, INSTRUCTION_TRANSFER, INSTRUCTION_VALIDATE, LONG_LIVED_AUTHORITY_EXPIRY_SECONDS, P256_HALF_N, P256_N, PASSKEY_MANAGER_PROGRAM_ADDRESS, type ParsedAuthority, type PasskeyAuthorityIdentity, type PasskeyAuthorityTarget, type PasskeyDiscoverableSigningResult, type PasskeyMetadata, type PasskeyRegistrationResult, type PasskeySigningResult, type PreparePasskeyAuthorityTargetsOptions, type RegisterCredentialInstructionParams, type RemoveAuthorityInstructionParams, type TargetInstructionParams, type TransactionExecutionSummary, type TransferInstructionParams, VALIDATE_CHALLENGE_DOMAIN, type ValidateInstructionParams, type WalletAccountContext, type WalletAuthorities, type WalletSigner, arrayBufferToBase64Url, assertWalletFeePayerCompatible, base64UrlToArrayBuffer, base64UrlToBytes, bigIntToBytesBE, buildAccountContext, buildAuthority, buildAuthorityRecord, buildPasskeyReadWriteAccounts, buildWalletAccountContext, bytesEqual, bytesToBase64, bytesToBase64Url, bytesToBigIntBE, bytesToHex, compareBytes, concatenateInstructions, createAuthorityRecord, createCredentialLookupSeed, createSessionAuthorityRecord, createValidateChallenge, createWalletSeed, deriveCredentialLookupAddress, deriveWalletAddress, encodeAddAuthorityInstruction, encodeCreateInstruction, encodeInvokeInstruction, encodeLegacyAddAuthorityInstruction, encodeLegacyCreateInstruction, encodeRegisterCredentialInstruction, encodeRemoveAuthorityInstruction, encodeTransferInstruction, encodeValidateInstruction, fetchWalletNonce, findPasskeyAuthorityIndexForIdentity, findPasskeyAuthorityIndexInWalletData, formatAuthorityPubkey, hexToBytes, isPasskeyAuthorityCheckable, normalizeLowS, normalizeSignatureComponent, parseCredentialLookupWallet, parseDerSignature, parseWalletAuthorities, parseWalletNonce, preparePasskeyAuthorityTargets, resolvePasskeyAuthorityIndex, uniqueAccounts };
@@ -115,6 +115,15 @@ interface AccountContext {
115
115
  walletAccountIdx: number;
116
116
  getAccountIndex: (pubkey: Uint8Array) => number;
117
117
  }
118
+ /** Account indices for a wallet-wrapped target instruction whose fee payer is
119
+ * selected later by the wallet. Index 0 is reserved for that fee payer and
120
+ * index 1 for the wrapper program. */
121
+ interface WalletAccountContext {
122
+ readWriteAddresses: string[];
123
+ readOnlyAddresses: string[];
124
+ walletAccountIdx: number;
125
+ getAccountIndex: (pubkey: Uint8Array) => number;
126
+ }
118
127
  interface RegisterCredentialInstructionParams {
119
128
  walletAccountIdx: number;
120
129
  lookupAccountIdx: number;
@@ -200,6 +209,23 @@ declare function createCredentialLookupSeed(credentialId: Uint8Array): Promise<U
200
209
  */
201
210
  declare function deriveCredentialLookupAddress(credentialId: Uint8Array, programAddress: string): Promise<Uint8Array>;
202
211
 
212
+ interface WalletAccountContextParams {
213
+ walletAddress: string;
214
+ readWriteAccounts: Uint8Array[];
215
+ readOnlyAccounts: Uint8Array[];
216
+ programAddress?: string;
217
+ }
218
+ /**
219
+ * Build account indices for an instruction that a wallet will wrap and pay for.
220
+ * The concrete fee payer is intentionally unknown here; index 0 is reserved for
221
+ * it and index 1 for the wrapper program.
222
+ */
223
+ declare function buildWalletAccountContext(params: WalletAccountContextParams): WalletAccountContext;
224
+ /** Ensure the wallet-selected fee payer does not invalidate indices that were
225
+ * encoded before that payer was known. */
226
+ declare function assertWalletFeePayerCompatible(params: WalletAccountContextParams & {
227
+ feePayerAddress: string;
228
+ }): void;
203
229
  /**
204
230
  * Build account context for passkey manager transactions.
205
231
  * Handles account deduplication, sorting, and index lookup.
@@ -353,4 +379,4 @@ declare function base64UrlToBytes(base64Url: string): Uint8Array;
353
379
  declare function bytesToHex(bytes: Uint8Array): string;
354
380
  declare function hexToBytes(hex: string): Uint8Array;
355
381
 
356
- export { AUTHORITY_BYTES, AUTHORITY_RECORD_BYTES, AUTHORITY_TAG_PASSKEY, AUTHORITY_TAG_PUBKEY, type AccountContext, type AddAuthorityInstructionParams, type Authority, type AuthorityRecord, type CheckablePasskeyAuthorityIdentity, type CreateInstructionParams, INSTRUCTION_ADD_AUTHORITY, INSTRUCTION_CREATE, INSTRUCTION_REGISTER_CREDENTIAL, INSTRUCTION_REMOVE_AUTHORITY, INSTRUCTION_TRANSFER, INSTRUCTION_VALIDATE, LONG_LIVED_AUTHORITY_EXPIRY_SECONDS, P256_HALF_N, P256_N, PASSKEY_MANAGER_PROGRAM_ADDRESS, type ParsedAuthority, type PasskeyAuthorityIdentity, type PasskeyAuthorityTarget, type PasskeyDiscoverableSigningResult, type PasskeyMetadata, type PasskeyRegistrationResult, type PasskeySigningResult, type PreparePasskeyAuthorityTargetsOptions, type RegisterCredentialInstructionParams, type RemoveAuthorityInstructionParams, type TargetInstructionParams, type TransactionExecutionSummary, type TransferInstructionParams, VALIDATE_CHALLENGE_DOMAIN, type ValidateInstructionParams, type WalletAuthorities, type WalletSigner, arrayBufferToBase64Url, base64UrlToArrayBuffer, base64UrlToBytes, bigIntToBytesBE, buildAccountContext, buildAuthority, buildAuthorityRecord, buildPasskeyReadWriteAccounts, bytesEqual, bytesToBase64, bytesToBase64Url, bytesToBigIntBE, bytesToHex, compareBytes, concatenateInstructions, createAuthorityRecord, createCredentialLookupSeed, createSessionAuthorityRecord, createValidateChallenge, createWalletSeed, deriveCredentialLookupAddress, deriveWalletAddress, encodeAddAuthorityInstruction, encodeCreateInstruction, encodeInvokeInstruction, encodeLegacyAddAuthorityInstruction, encodeLegacyCreateInstruction, encodeRegisterCredentialInstruction, encodeRemoveAuthorityInstruction, encodeTransferInstruction, encodeValidateInstruction, fetchWalletNonce, findPasskeyAuthorityIndexForIdentity, findPasskeyAuthorityIndexInWalletData, formatAuthorityPubkey, hexToBytes, isPasskeyAuthorityCheckable, normalizeLowS, normalizeSignatureComponent, parseCredentialLookupWallet, parseDerSignature, parseWalletAuthorities, parseWalletNonce, preparePasskeyAuthorityTargets, resolvePasskeyAuthorityIndex, uniqueAccounts };
382
+ export { AUTHORITY_BYTES, AUTHORITY_RECORD_BYTES, AUTHORITY_TAG_PASSKEY, AUTHORITY_TAG_PUBKEY, type AccountContext, type AddAuthorityInstructionParams, type Authority, type AuthorityRecord, type CheckablePasskeyAuthorityIdentity, type CreateInstructionParams, INSTRUCTION_ADD_AUTHORITY, INSTRUCTION_CREATE, INSTRUCTION_REGISTER_CREDENTIAL, INSTRUCTION_REMOVE_AUTHORITY, INSTRUCTION_TRANSFER, INSTRUCTION_VALIDATE, LONG_LIVED_AUTHORITY_EXPIRY_SECONDS, P256_HALF_N, P256_N, PASSKEY_MANAGER_PROGRAM_ADDRESS, type ParsedAuthority, type PasskeyAuthorityIdentity, type PasskeyAuthorityTarget, type PasskeyDiscoverableSigningResult, type PasskeyMetadata, type PasskeyRegistrationResult, type PasskeySigningResult, type PreparePasskeyAuthorityTargetsOptions, type RegisterCredentialInstructionParams, type RemoveAuthorityInstructionParams, type TargetInstructionParams, type TransactionExecutionSummary, type TransferInstructionParams, VALIDATE_CHALLENGE_DOMAIN, type ValidateInstructionParams, type WalletAccountContext, type WalletAuthorities, type WalletSigner, arrayBufferToBase64Url, assertWalletFeePayerCompatible, base64UrlToArrayBuffer, base64UrlToBytes, bigIntToBytesBE, buildAccountContext, buildAuthority, buildAuthorityRecord, buildPasskeyReadWriteAccounts, buildWalletAccountContext, bytesEqual, bytesToBase64, bytesToBase64Url, bytesToBigIntBE, bytesToHex, compareBytes, concatenateInstructions, createAuthorityRecord, createCredentialLookupSeed, createSessionAuthorityRecord, createValidateChallenge, createWalletSeed, deriveCredentialLookupAddress, deriveWalletAddress, encodeAddAuthorityInstruction, encodeCreateInstruction, encodeInvokeInstruction, encodeLegacyAddAuthorityInstruction, encodeLegacyCreateInstruction, encodeRegisterCredentialInstruction, encodeRemoveAuthorityInstruction, encodeTransferInstruction, encodeValidateInstruction, fetchWalletNonce, findPasskeyAuthorityIndexForIdentity, findPasskeyAuthorityIndexInWalletData, formatAuthorityPubkey, hexToBytes, isPasskeyAuthorityCheckable, normalizeLowS, normalizeSignatureComponent, parseCredentialLookupWallet, parseDerSignature, parseWalletAuthorities, parseWalletNonce, preparePasskeyAuthorityTargets, resolvePasskeyAuthorityIndex, uniqueAccounts };
@@ -1,4 +1,4 @@
1
- import { uniqueAccounts, bytesEqual, compareBytes } from '../chunk-P5OABVJI.js';
1
+ import { bytesEqual, uniqueAccounts, compareBytes } from '../chunk-P5OABVJI.js';
2
2
  export { bytesEqual, compareBytes, uniqueAccounts } from '../chunk-P5OABVJI.js';
3
3
  import { decodeAddress, hexToBytes as hexToBytes$1, encodeAddress } from '@thru/sdk/helpers';
4
4
  export { decodeAddress, encodeAddress } from '@thru/sdk/helpers';
@@ -7741,6 +7741,52 @@ function hexToBytes(hex) {
7741
7741
  }
7742
7742
 
7743
7743
  // src/passkey-manager/context.ts
7744
+ function buildDeferredAccountLists(params) {
7745
+ const programBytes = decodeAddress(params.programAddress ?? PASSKEY_MANAGER_PROGRAM_ADDRESS);
7746
+ const walletBytes = decodeAddress(params.walletAddress);
7747
+ const readWriteBytes = uniqueAccounts([walletBytes, ...params.readWriteAccounts]).filter((addr) => !bytesEqual(addr, programBytes)).sort(compareBytes);
7748
+ const readOnlyBytes = uniqueAccounts(params.readOnlyAccounts).filter(
7749
+ (addr) => !bytesEqual(addr, programBytes) && !readWriteBytes.some((candidate) => bytesEqual(candidate, addr))
7750
+ ).sort(compareBytes);
7751
+ return { programBytes, walletBytes, readWriteBytes, readOnlyBytes };
7752
+ }
7753
+ function buildWalletAccountContext(params) {
7754
+ const { programBytes, walletBytes, readWriteBytes, readOnlyBytes } = buildDeferredAccountLists(params);
7755
+ const readWriteAddresses = readWriteBytes.map(encodeAddress);
7756
+ const readOnlyAddresses = readOnlyBytes.map(encodeAddress);
7757
+ const findIndex = (target) => {
7758
+ if (bytesEqual(target, programBytes)) return 1;
7759
+ const rwIndex = readWriteBytes.findIndex((candidate) => bytesEqual(candidate, target));
7760
+ if (rwIndex >= 0) return rwIndex + 2;
7761
+ const roIndex = readOnlyBytes.findIndex((candidate) => bytesEqual(candidate, target));
7762
+ if (roIndex >= 0) return roIndex + 2 + readWriteBytes.length;
7763
+ return -1;
7764
+ };
7765
+ const walletAccountIdx = findIndex(walletBytes);
7766
+ if (walletAccountIdx < 2) {
7767
+ throw new Error("Wallet account must be a non-program account");
7768
+ }
7769
+ return {
7770
+ readWriteAddresses,
7771
+ readOnlyAddresses,
7772
+ walletAccountIdx,
7773
+ getAccountIndex: (pubkey) => {
7774
+ const idx = findIndex(pubkey);
7775
+ if (idx < 0) {
7776
+ throw new Error("Account not found in transaction accounts");
7777
+ }
7778
+ return idx;
7779
+ }
7780
+ };
7781
+ }
7782
+ function assertWalletFeePayerCompatible(params) {
7783
+ const feePayerBytes = decodeAddress(params.feePayerAddress);
7784
+ const { programBytes, walletBytes, readWriteBytes, readOnlyBytes } = buildDeferredAccountLists(params);
7785
+ const conflicts = [programBytes, walletBytes, ...readWriteBytes, ...readOnlyBytes];
7786
+ if (conflicts.some((account) => bytesEqual(account, feePayerBytes))) {
7787
+ throw new Error("Wallet fee payer must not overlap instruction accounts");
7788
+ }
7789
+ }
7744
7790
  function buildAccountContext(params) {
7745
7791
  const feePayerBytes = decodeAddress(params.feePayerAddress);
7746
7792
  const programBytes = decodeAddress(params.programAddress ?? PASSKEY_MANAGER_PROGRAM_ADDRESS);
@@ -8035,6 +8081,6 @@ function bigIntToBytesBE(value, length) {
8035
8081
  return out;
8036
8082
  }
8037
8083
 
8038
- export { AUTHORITY_BYTES, AUTHORITY_RECORD_BYTES, AUTHORITY_TAG_PASSKEY, AUTHORITY_TAG_PUBKEY, INSTRUCTION_ADD_AUTHORITY, INSTRUCTION_CREATE, INSTRUCTION_REGISTER_CREDENTIAL, INSTRUCTION_REMOVE_AUTHORITY, INSTRUCTION_TRANSFER, INSTRUCTION_VALIDATE, LONG_LIVED_AUTHORITY_EXPIRY_SECONDS, P256_HALF_N, P256_N, PASSKEY_MANAGER_PROGRAM_ADDRESS, VALIDATE_CHALLENGE_DOMAIN, arrayBufferToBase64Url, base64UrlToArrayBuffer, base64UrlToBytes, bigIntToBytesBE, buildAccountContext, buildAuthority, buildAuthorityRecord, buildPasskeyReadWriteAccounts, bytesToBase64, bytesToBase64Url, bytesToBigIntBE, bytesToHex, concatenateInstructions, createAuthorityRecord, createCredentialLookupSeed, createSessionAuthorityRecord, createValidateChallenge, createWalletSeed, deriveCredentialLookupAddress, deriveWalletAddress, encodeAddAuthorityInstruction, encodeCreateInstruction, encodeInvokeInstruction, encodeLegacyAddAuthorityInstruction, encodeLegacyCreateInstruction, encodeRegisterCredentialInstruction, encodeRemoveAuthorityInstruction, encodeTransferInstruction, encodeValidateInstruction, fetchWalletNonce, findPasskeyAuthorityIndexForIdentity, findPasskeyAuthorityIndexInWalletData, formatAuthorityPubkey, hexToBytes, isPasskeyAuthorityCheckable, normalizeLowS, normalizeSignatureComponent, parseCredentialLookupWallet, parseDerSignature, parseWalletAuthorities, parseWalletNonce, preparePasskeyAuthorityTargets, resolvePasskeyAuthorityIndex };
8084
+ export { AUTHORITY_BYTES, AUTHORITY_RECORD_BYTES, AUTHORITY_TAG_PASSKEY, AUTHORITY_TAG_PUBKEY, INSTRUCTION_ADD_AUTHORITY, INSTRUCTION_CREATE, INSTRUCTION_REGISTER_CREDENTIAL, INSTRUCTION_REMOVE_AUTHORITY, INSTRUCTION_TRANSFER, INSTRUCTION_VALIDATE, LONG_LIVED_AUTHORITY_EXPIRY_SECONDS, P256_HALF_N, P256_N, PASSKEY_MANAGER_PROGRAM_ADDRESS, VALIDATE_CHALLENGE_DOMAIN, arrayBufferToBase64Url, assertWalletFeePayerCompatible, base64UrlToArrayBuffer, base64UrlToBytes, bigIntToBytesBE, buildAccountContext, buildAuthority, buildAuthorityRecord, buildPasskeyReadWriteAccounts, buildWalletAccountContext, bytesToBase64, bytesToBase64Url, bytesToBigIntBE, bytesToHex, concatenateInstructions, createAuthorityRecord, createCredentialLookupSeed, createSessionAuthorityRecord, createValidateChallenge, createWalletSeed, deriveCredentialLookupAddress, deriveWalletAddress, encodeAddAuthorityInstruction, encodeCreateInstruction, encodeInvokeInstruction, encodeLegacyAddAuthorityInstruction, encodeLegacyCreateInstruction, encodeRegisterCredentialInstruction, encodeRemoveAuthorityInstruction, encodeTransferInstruction, encodeValidateInstruction, fetchWalletNonce, findPasskeyAuthorityIndexForIdentity, findPasskeyAuthorityIndexInWalletData, formatAuthorityPubkey, hexToBytes, isPasskeyAuthorityCheckable, normalizeLowS, normalizeSignatureComponent, parseCredentialLookupWallet, parseDerSignature, parseWalletAuthorities, parseWalletNonce, preparePasskeyAuthorityTargets, resolvePasskeyAuthorityIndex };
8039
8085
  //# sourceMappingURL=index.js.map
8040
8086
  //# sourceMappingURL=index.js.map