@usearete/sdk 0.5.0 → 0.7.0
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/dist/index.cjs +89 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +29 -5
- package/dist/index.esm.js +89 -20
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -241,6 +241,8 @@ interface AccountMeta {
|
|
|
241
241
|
isWritable: boolean;
|
|
242
242
|
/** Category of this account */
|
|
243
243
|
category: AccountCategory;
|
|
244
|
+
/** How a signer account is satisfied. Unspecified signers are caller-provided. */
|
|
245
|
+
signerKind?: 'wallet' | 'provided' | 'generated';
|
|
244
246
|
/** Fixed address for "known" accounts (e.g., "11111111111111111111111111111111") */
|
|
245
247
|
knownAddress?: string;
|
|
246
248
|
/** PDA configuration for "pda" accounts */
|
|
@@ -254,9 +256,18 @@ interface AccountMeta {
|
|
|
254
256
|
interface PdaConfig {
|
|
255
257
|
/** Program ID that owns this PDA (defaults to instruction's programId) */
|
|
256
258
|
programId?: string;
|
|
259
|
+
/** Dynamic program selector for cross-program PDA derivation. */
|
|
260
|
+
program?: PdaProgram;
|
|
257
261
|
/** Seed definitions for PDA derivation */
|
|
258
262
|
seeds: PdaSeed[];
|
|
259
263
|
}
|
|
264
|
+
type PdaProgram = {
|
|
265
|
+
type: 'accountRef';
|
|
266
|
+
accountName: string;
|
|
267
|
+
} | {
|
|
268
|
+
type: 'argRef';
|
|
269
|
+
argName: string;
|
|
270
|
+
};
|
|
260
271
|
/**
|
|
261
272
|
* Single seed in a PDA derivation.
|
|
262
273
|
*/
|
|
@@ -304,7 +315,7 @@ interface AccountResolutionOptions {
|
|
|
304
315
|
accounts?: Record<string, string>;
|
|
305
316
|
/** Helper-only PDA seed inputs */
|
|
306
317
|
resolve?: Record<string, unknown>;
|
|
307
|
-
/** Wallet adapter for
|
|
318
|
+
/** Wallet adapter for accounts explicitly marked with signerKind: 'wallet' */
|
|
308
319
|
wallet?: WalletAdapter;
|
|
309
320
|
/** Program ID for PDA derivation (required if any PDAs exist) */
|
|
310
321
|
programId?: string;
|
|
@@ -610,7 +621,7 @@ declare function createInstructionHandler<TParams = Record<string, unknown>, TEr
|
|
|
610
621
|
* Options for building an instruction (no network access).
|
|
611
622
|
*/
|
|
612
623
|
interface BuildOptions {
|
|
613
|
-
/** Wallet, used only for
|
|
624
|
+
/** Wallet, used only for accounts explicitly marked with signerKind: 'wallet'. */
|
|
614
625
|
wallet?: WalletAdapter;
|
|
615
626
|
/** Explicit account-address overrides, including signer slots when needed. */
|
|
616
627
|
accounts?: Record<string, string>;
|
|
@@ -685,9 +696,17 @@ interface PdaDeriveContext {
|
|
|
685
696
|
resolve?: Record<string, unknown>;
|
|
686
697
|
programId?: string;
|
|
687
698
|
}
|
|
699
|
+
type PdaProgramSelector = string | {
|
|
700
|
+
type: 'accountRef';
|
|
701
|
+
accountName: string;
|
|
702
|
+
} | {
|
|
703
|
+
type: 'argRef';
|
|
704
|
+
argName: string;
|
|
705
|
+
};
|
|
688
706
|
interface PdaFactory {
|
|
689
707
|
readonly seeds: readonly SeedDef[];
|
|
690
|
-
readonly programId
|
|
708
|
+
readonly programId?: string;
|
|
709
|
+
readonly programSelector: PdaProgramSelector;
|
|
691
710
|
program(programId: string): PdaFactory;
|
|
692
711
|
derive(context: PdaDeriveContext): Promise<string>;
|
|
693
712
|
deriveSync(context: PdaDeriveContext): string;
|
|
@@ -696,7 +715,7 @@ declare function literal(value: string): SeedDef;
|
|
|
696
715
|
declare function account(name: string): SeedDef;
|
|
697
716
|
declare function arg(name: string, type?: string): SeedDef;
|
|
698
717
|
declare function bytes(value: Uint8Array): SeedDef;
|
|
699
|
-
declare function pda(
|
|
718
|
+
declare function pda(programSelector: PdaProgramSelector, ...seeds: SeedDef[]): PdaFactory;
|
|
700
719
|
type ProgramPdas<T extends Record<string, PdaFactory>> = T;
|
|
701
720
|
declare function createProgramPdas<T extends Record<string, PdaFactory>>(pdas: T): ProgramPdas<T>;
|
|
702
721
|
|
|
@@ -1563,6 +1582,8 @@ interface PreparedTransactionBody {
|
|
|
1563
1582
|
readonly name: string;
|
|
1564
1583
|
readonly instructions: NonEmptyReadonlyArray<BuiltInstruction>;
|
|
1565
1584
|
readonly requiredSignerAddresses: readonly string[];
|
|
1585
|
+
/** Signer material created while preparing this transaction. */
|
|
1586
|
+
readonly signers?: readonly unknown[];
|
|
1566
1587
|
readonly errors: readonly ErrorMetadata[];
|
|
1567
1588
|
}
|
|
1568
1589
|
interface OperationPlan<TArtifacts = void> {
|
|
@@ -1591,6 +1612,7 @@ interface CreatePreparedInstructionInput<TArtifacts> {
|
|
|
1591
1612
|
instruction: BuiltInstruction;
|
|
1592
1613
|
artifacts: TArtifacts;
|
|
1593
1614
|
requiredSignerAddresses?: readonly string[];
|
|
1615
|
+
signers?: readonly unknown[];
|
|
1594
1616
|
errors?: readonly ErrorMetadata[];
|
|
1595
1617
|
}
|
|
1596
1618
|
type PreparedTransactionInstruction = BuiltInstruction | PreparedInstruction<unknown>;
|
|
@@ -1599,6 +1621,7 @@ interface CreatePreparedTransactionBaseInput<TArtifacts> {
|
|
|
1599
1621
|
name: string;
|
|
1600
1622
|
artifacts: TArtifacts;
|
|
1601
1623
|
requiredSignerAddresses?: readonly string[];
|
|
1624
|
+
signers?: readonly unknown[];
|
|
1602
1625
|
errors?: readonly ErrorMetadata[];
|
|
1603
1626
|
}
|
|
1604
1627
|
type CreatePreparedTransactionInput<TArtifacts> = CreatePreparedTransactionBaseInput<TArtifacts> & ({
|
|
@@ -1617,6 +1640,7 @@ declare function createPreparedTransactionBody(input: {
|
|
|
1617
1640
|
name: string;
|
|
1618
1641
|
instructions: readonly BuiltInstruction[];
|
|
1619
1642
|
requiredSignerAddresses?: readonly string[];
|
|
1643
|
+
signers?: readonly unknown[];
|
|
1620
1644
|
errors?: readonly ErrorMetadata[];
|
|
1621
1645
|
}): PreparedTransactionBody;
|
|
1622
1646
|
declare function createPreparedInstruction<TArtifacts>(input: CreatePreparedInstructionInput<TArtifacts>): PreparedInstruction<TArtifacts>;
|
|
@@ -2365,4 +2389,4 @@ declare const Arete: typeof Arete$1 & {
|
|
|
2365
2389
|
};
|
|
2366
2390
|
|
|
2367
2391
|
export { ASSOCIATED_TOKEN_PROGRAM_ADDRESS, Arete, AreteError, ConnectionManager, DEFAULT_CONFIG, DEFAULT_MAX_ENTRIES_PER_VIEW, FrameProcessor, InstructionError, MemoryAdapter, OperationCallbackError, OperationExecutionError, PROGRAM_OPERATION_EXTENSIONS, ProcessedSlotTimeoutError, QueryStore, ReadRequestError, SPL_TOKEN_PROGRAM_ADDRESS, STACK_RUNTIME_EXTENSIONS, SYSTEM_PROGRAM_ADDRESS, SubscriptionRegistry, TOKEN_2022_PROGRAM_ADDRESS, TransactionExecutionError, TransactionTransportError, account, appendFlowTransactions, appendTransactionInstructions, applyConnectedStackExtensions, arg, buildInstruction, bytes, canonicalQueryKey, chainAccountLoader, createChainClient, createEntityStream, createHostedSolanaGatewayTransports, createInstructionExecutor, createInstructionHandler, createPreparedFlow, createPreparedInstruction, createPreparedTransaction, createPreparedTransactionBody, createProgramPdas, createPublicKeySeed, createRichUpdateStream, createSeed, createSession, createSignerRegistry, createSubscriptionId, createTransactionTransport, createTypedListView, createTypedStateView, createTypedViews, createUpdateStream, decodeBase58, defineProgramExtensions, defineStackExtensions, deriveAssociatedTokenAccount, deriveHttpEndpoint, findProgramAddress as derivePda, describePreparedOperation, encodeBase58, executeInstruction, executePreparedOperation, extendProgram, extendPrograms, extendStack, findProgramAddress, findProgramAddressSync, flowOperation, formatPreparedOperation, formatProgramError, formatRawToUi, getMintDecimals, getProgramRuntimeExtensions, getStackRuntimeExtensions, getTransactionFailureOutcome, inspectPreparedOperation, instructionOperation, isEntityFrame, isErrorFrame, isHostedAreteEndpoint, isSnapshotFrame, isSubscribedFrame, isUnsubscribedFrame, isValidFrame, literal, normalizeSubscription, normalizeSubscriptionQuery, normalizeSubscriptionRequest, normalizeTransactionError, parseFrame, parseFrameFromBlob, parseInstructionError, parseUiAmountToRaw, pda, prependFlowTransactionInstructions, prependTransactionInstructions, programAccountRead, programQuery, resolveAccounts, resolveAmount, resolveAmountToRaw, resolveAmountsToRaw, resolveTokenProgramAddress, safeToRawAmount, serializeInstructionData, serializeViewKey, stackQuery, stringifyBigints, toJsonValue, toRawAmount, transactionOperation, unwrapOperationExecutionError, validateAccountResolution, validateProgramReadDescriptor, validateSubscriptionId, withPrograms };
|
|
2368
|
-
export type { AccountCategory, AccountLoader, AccountMeta, AccountResolutionOptions, AccountResolutionResult, AmountInput, AnyOperation, AreteConfig, AreteOptions, AreteOptionsWithStorage, ArgSchema, ArgType, AuthConfig, AuthTokenRequest, AuthTokenResult, AuthTokenTarget, BuildOptions, BuiltAccountMeta, BuiltInstruction, ChainClient, ChainClock, ChainFailedTransactionOutcome, CompositionSessionOptions, ConfirmationLevel, ConfirmedTransactionOutcome, ConnectOptions, ConnectedArete, ConnectedStackClient, ConnectionState, ConnectionStateCallback, ContextSlotOptions, CreatePreparedFlowInput, CreatePreparedInstructionInput, CreatePreparedTransactionInput, DefaultViewKey, EntityFrame, ErrorFrame, ErrorMetadata, ExecuteOptions, ExecutionResult, ExtendedProgramDefinition, ExtendedStackDefinition, FlowOperation, FlowOperationNamespace, FlowOperationReceipt, Frame, FrameMode, FrameOp, FrameProcessorConfig, FrameValidationDiagnostic, HostedSolanaGatewayBindings, HostedSolanaGatewayCapabilityBinding, HostedSolanaGatewayTransportOptions, HostedSolanaGatewayTransports, HttpAuthMetadata, InstructionExecutor, InstructionHandler, InstructionHandlerConfig, InstructionOperation, InstructionOperationNamespace, JsonObject, JsonPrimitive, JsonValue, LatestBlockhashResult, MergeProgramMaps, MintAccountInfo, NativeBalanceInfo, NonEmptyReadonlyArray, NotSubmittedTransactionOutcome, OperationCallbackPhase, OperationExecutionEvent, OperationExecutionHost, OperationExecutionOptions, OperationExecutionSuccessEvent, OperationInspection, OperationInspectionOptions, OperationKind, OperationNamespace, OperationPlan, OperationReceiptFor, OperationTransactionReceipt, PdaConfig, PdaDeriveContext, PdaFactory, PdaSeed, PreparedFlow, PreparedInstruction, PreparedOperation, PreparedOperationDescription, PreparedTransaction, PreparedTransactionBody, PreparedTransactionInstruction, PreparedTransactionOperation, ProgramAccountBatchItem, ProgramAccountBatchResult, ProgramAccountReadDefinition, ProgramError, ProgramExtensionInput, ProgramInterface, ProgramOperationContext, ProgramOperations, ProgramOperationsOf, ProgramPdas, ProgramQueryDefinition, ProgramReadBinding, ProgramReadBindingAuthTarget, ProgramReadDescriptor, ProgramReadDescriptors, ProgramReadOverride, ProgramReadOverrides, ProgramReadRequest, ProgramReadTransport, ProgramReleaseReference, ProgramRuntimeExtensionCarrier, ProgramRuntimeExtensions, ProgramSdkDefinition, ProgramsInterface, QueriesInterface, QueryLease, QuerySnapshot, RawAccountInfo, RawInstructionsInterface, RawProgramsInterface, ReadArgumentCount, ReadArgumentCounts, ReadTransportMethod, ResolvedAccount, ResolvedAccounts, RichUpdate, RichUpdateCallback, Schema, SchemaResult, SeedDef, SendOptions, SendResult, Session, SessionDefinition, SessionMemberOptions, SessionOptions, SignerRegistry, SingleTransactionOperationReceipt, SnapshotEntity, SnapshotFrame, SocketIssue, SocketIssueCallback, SolanaGatewayAuthMetadata, SolanaGatewayAuthScope, SolanaGatewayBindingAuthTarget, SortConfig, SortOrder, StackConnectedExtensions, StackDefinition, StackEndpoints, StackExtensionClient, StackExtensionInput, StackQueryDefinition, StackRuntimeExtensionCarrier, StackRuntimeExtensions, StackWithAttachedPrograms, StorageAdapter, StorageAdapterConfig, StringifiedBigints, SubmittedUnknownTransactionOutcome, SubscribeCallback, SubscribedFrame, Subscription, SubscriptionIdentity, SubscriptionOptions, SubscriptionQuery, SubscriptionRequest, SubscriptionSnapshotOptions, TokenAccountInfo, TokenBalanceInfo, TokenBalanceInput, TransactionCommitment, TransactionFailureOutcome, TransactionFailurePhase, TransactionFailureStatus, TransactionFeeResult, TransactionInspectionOptions, TransactionInspectionResult, TransactionOperation, TransactionOperationNamespace, TransactionOptions, TransactionOutcome, TransactionRequestContext, TransactionSendOptions, TransactionSendResult, TransactionSignatureStatus, TransactionSimulationOptions, TransactionSimulationResult, TransactionTransport, TransactionTransportErrorBody, TypedAccountReader, TypedInstruction, TypedListView, TypedQueryExecutor, TypedStateView, TypedViewGroup, TypedViews, UnsubscribeFn, UnsubscribedFrame, Update, UpdateCallback, ViewDef, ViewGroup, ViewKeyFields, ViewKeyValue, ViewSortConfig, WaitForProcessedSlotOptions, WalletAdapter, WalletConnectOptions, WalletExecutionContext, WalletState, WatchOptions, WebSocketFactoryInit };
|
|
2392
|
+
export type { AccountCategory, AccountLoader, AccountMeta, AccountResolutionOptions, AccountResolutionResult, AmountInput, AnyOperation, AreteConfig, AreteOptions, AreteOptionsWithStorage, ArgSchema, ArgType, AuthConfig, AuthTokenRequest, AuthTokenResult, AuthTokenTarget, BuildOptions, BuiltAccountMeta, BuiltInstruction, ChainClient, ChainClock, ChainFailedTransactionOutcome, CompositionSessionOptions, ConfirmationLevel, ConfirmedTransactionOutcome, ConnectOptions, ConnectedArete, ConnectedStackClient, ConnectionState, ConnectionStateCallback, ContextSlotOptions, CreatePreparedFlowInput, CreatePreparedInstructionInput, CreatePreparedTransactionInput, DefaultViewKey, EntityFrame, ErrorFrame, ErrorMetadata, ExecuteOptions, ExecutionResult, ExtendedProgramDefinition, ExtendedStackDefinition, FlowOperation, FlowOperationNamespace, FlowOperationReceipt, Frame, FrameMode, FrameOp, FrameProcessorConfig, FrameValidationDiagnostic, HostedSolanaGatewayBindings, HostedSolanaGatewayCapabilityBinding, HostedSolanaGatewayTransportOptions, HostedSolanaGatewayTransports, HttpAuthMetadata, InstructionExecutor, InstructionHandler, InstructionHandlerConfig, InstructionOperation, InstructionOperationNamespace, JsonObject, JsonPrimitive, JsonValue, LatestBlockhashResult, MergeProgramMaps, MintAccountInfo, NativeBalanceInfo, NonEmptyReadonlyArray, NotSubmittedTransactionOutcome, OperationCallbackPhase, OperationExecutionEvent, OperationExecutionHost, OperationExecutionOptions, OperationExecutionSuccessEvent, OperationInspection, OperationInspectionOptions, OperationKind, OperationNamespace, OperationPlan, OperationReceiptFor, OperationTransactionReceipt, PdaConfig, PdaDeriveContext, PdaFactory, PdaProgram, PdaProgramSelector, PdaSeed, PreparedFlow, PreparedInstruction, PreparedOperation, PreparedOperationDescription, PreparedTransaction, PreparedTransactionBody, PreparedTransactionInstruction, PreparedTransactionOperation, ProgramAccountBatchItem, ProgramAccountBatchResult, ProgramAccountReadDefinition, ProgramError, ProgramExtensionInput, ProgramInterface, ProgramOperationContext, ProgramOperations, ProgramOperationsOf, ProgramPdas, ProgramQueryDefinition, ProgramReadBinding, ProgramReadBindingAuthTarget, ProgramReadDescriptor, ProgramReadDescriptors, ProgramReadOverride, ProgramReadOverrides, ProgramReadRequest, ProgramReadTransport, ProgramReleaseReference, ProgramRuntimeExtensionCarrier, ProgramRuntimeExtensions, ProgramSdkDefinition, ProgramsInterface, QueriesInterface, QueryLease, QuerySnapshot, RawAccountInfo, RawInstructionsInterface, RawProgramsInterface, ReadArgumentCount, ReadArgumentCounts, ReadTransportMethod, ResolvedAccount, ResolvedAccounts, RichUpdate, RichUpdateCallback, Schema, SchemaResult, SeedDef, SendOptions, SendResult, Session, SessionDefinition, SessionMemberOptions, SessionOptions, SignerRegistry, SingleTransactionOperationReceipt, SnapshotEntity, SnapshotFrame, SocketIssue, SocketIssueCallback, SolanaGatewayAuthMetadata, SolanaGatewayAuthScope, SolanaGatewayBindingAuthTarget, SortConfig, SortOrder, StackConnectedExtensions, StackDefinition, StackEndpoints, StackExtensionClient, StackExtensionInput, StackQueryDefinition, StackRuntimeExtensionCarrier, StackRuntimeExtensions, StackWithAttachedPrograms, StorageAdapter, StorageAdapterConfig, StringifiedBigints, SubmittedUnknownTransactionOutcome, SubscribeCallback, SubscribedFrame, Subscription, SubscriptionIdentity, SubscriptionOptions, SubscriptionQuery, SubscriptionRequest, SubscriptionSnapshotOptions, TokenAccountInfo, TokenBalanceInfo, TokenBalanceInput, TransactionCommitment, TransactionFailureOutcome, TransactionFailurePhase, TransactionFailureStatus, TransactionFeeResult, TransactionInspectionOptions, TransactionInspectionResult, TransactionOperation, TransactionOperationNamespace, TransactionOptions, TransactionOutcome, TransactionRequestContext, TransactionSendOptions, TransactionSendResult, TransactionSignatureStatus, TransactionSimulationOptions, TransactionSimulationResult, TransactionTransport, TransactionTransportErrorBody, TypedAccountReader, TypedInstruction, TypedListView, TypedQueryExecutor, TypedStateView, TypedViewGroup, TypedViews, UnsubscribeFn, UnsubscribedFrame, Update, UpdateCallback, ViewDef, ViewGroup, ViewKeyFields, ViewKeyValue, ViewSortConfig, WaitForProcessedSlotOptions, WalletAdapter, WalletConnectOptions, WalletExecutionContext, WalletState, WatchOptions, WebSocketFactoryInit };
|
package/dist/index.esm.js
CHANGED
|
@@ -4250,6 +4250,9 @@ function sortAccountsByDependency(accountMetas) {
|
|
|
4250
4250
|
deps.add(seed.accountName);
|
|
4251
4251
|
}
|
|
4252
4252
|
}
|
|
4253
|
+
if (meta.pdaConfig.program?.type === 'accountRef') {
|
|
4254
|
+
deps.add(meta.pdaConfig.program.accountName);
|
|
4255
|
+
}
|
|
4253
4256
|
}
|
|
4254
4257
|
pdaDeps.set(meta.name, deps);
|
|
4255
4258
|
}
|
|
@@ -4343,9 +4346,19 @@ function resolveAccounts(accountMetas, args, options) {
|
|
|
4343
4346
|
};
|
|
4344
4347
|
}
|
|
4345
4348
|
function resolveSingleAccount(meta, args, options, resolvedMap) {
|
|
4349
|
+
const explicit = options.accounts?.[meta.name];
|
|
4350
|
+
if (explicit !== undefined) {
|
|
4351
|
+
validateAccountAddress(meta.name, explicit);
|
|
4352
|
+
return {
|
|
4353
|
+
name: meta.name,
|
|
4354
|
+
address: explicit,
|
|
4355
|
+
isSigner: meta.isSigner,
|
|
4356
|
+
isWritable: meta.isWritable,
|
|
4357
|
+
};
|
|
4358
|
+
}
|
|
4346
4359
|
switch (meta.category) {
|
|
4347
4360
|
case 'signer':
|
|
4348
|
-
return resolveSignerAccount(meta, options.
|
|
4361
|
+
return resolveSignerAccount(meta, options.wallet);
|
|
4349
4362
|
case 'known':
|
|
4350
4363
|
return resolveKnownAccount(meta);
|
|
4351
4364
|
case 'pda':
|
|
@@ -4356,8 +4369,22 @@ function resolveSingleAccount(meta, args, options, resolvedMap) {
|
|
|
4356
4369
|
return null;
|
|
4357
4370
|
}
|
|
4358
4371
|
}
|
|
4359
|
-
function
|
|
4360
|
-
|
|
4372
|
+
function validateAccountAddress(name, address) {
|
|
4373
|
+
let decoded;
|
|
4374
|
+
try {
|
|
4375
|
+
decoded = decodeBase58(address);
|
|
4376
|
+
}
|
|
4377
|
+
catch {
|
|
4378
|
+
throw new Error(`Invalid account override for "${name}": expected a base58 public key`);
|
|
4379
|
+
}
|
|
4380
|
+
if (decoded.length !== 32) {
|
|
4381
|
+
throw new Error(`Invalid account override for "${name}": expected a 32-byte public key, got ${decoded.length} bytes`);
|
|
4382
|
+
}
|
|
4383
|
+
}
|
|
4384
|
+
function resolveSignerAccount(meta, wallet) {
|
|
4385
|
+
// An IDL only tells us that an account signs; it cannot prove that the
|
|
4386
|
+
// account is the connected wallet. Wallet fallback is therefore opt-in.
|
|
4387
|
+
const address = meta.signerKind === 'wallet' ? wallet?.publicKey : undefined;
|
|
4361
4388
|
if (!address) {
|
|
4362
4389
|
return null;
|
|
4363
4390
|
}
|
|
@@ -4384,7 +4411,7 @@ function resolvePdaAccount(meta, args, resolvedMap, programId, resolve) {
|
|
|
4384
4411
|
return null;
|
|
4385
4412
|
}
|
|
4386
4413
|
// Determine which program to derive against
|
|
4387
|
-
const pdaProgramId = meta.pdaConfig
|
|
4414
|
+
const pdaProgramId = resolvePdaProgram(meta.pdaConfig, args, resolvedMap, programId, resolve);
|
|
4388
4415
|
if (!pdaProgramId) {
|
|
4389
4416
|
throw new Error('Cannot derive PDA for "' + meta.name + '": no programId specified. ' +
|
|
4390
4417
|
'Either set pdaConfig.programId or pass programId in options.');
|
|
@@ -4431,6 +4458,24 @@ function resolvePdaAccount(meta, args, resolvedMap, programId, resolve) {
|
|
|
4431
4458
|
isWritable: meta.isWritable,
|
|
4432
4459
|
};
|
|
4433
4460
|
}
|
|
4461
|
+
function resolvePdaProgram(config, args, resolvedMap, defaultProgramId, resolve) {
|
|
4462
|
+
if (config.program?.type === 'accountRef') {
|
|
4463
|
+
const account = resolvedMap[config.program.accountName];
|
|
4464
|
+
if (!account) {
|
|
4465
|
+
throw new Error('PDA program references unresolved account: ' + config.program.accountName);
|
|
4466
|
+
}
|
|
4467
|
+
return account.address;
|
|
4468
|
+
}
|
|
4469
|
+
if (config.program?.type === 'argRef') {
|
|
4470
|
+
const value = getValueByPath(args, config.program.argName)
|
|
4471
|
+
?? getValueByPath(resolve, config.program.argName);
|
|
4472
|
+
if (typeof value !== 'string' || value.length === 0) {
|
|
4473
|
+
throw new Error('PDA program references missing or non-address argument: ' + config.program.argName);
|
|
4474
|
+
}
|
|
4475
|
+
return value;
|
|
4476
|
+
}
|
|
4477
|
+
return config.programId || defaultProgramId;
|
|
4478
|
+
}
|
|
4434
4479
|
function resolveUserProvidedAccount(meta, accounts) {
|
|
4435
4480
|
const address = accounts?.[meta.name];
|
|
4436
4481
|
if (!address) {
|
|
@@ -5054,10 +5099,10 @@ function createInstructionHandler(config) {
|
|
|
5054
5099
|
*
|
|
5055
5100
|
* Keys matching a declared argument name are args; keys matching a declared
|
|
5056
5101
|
* account name (with a string value) are account address overrides. This
|
|
5057
|
-
* applies to signer slots too, allowing explicit signer addresses to
|
|
5058
|
-
*
|
|
5102
|
+
* applies to signer slots too, allowing explicit signer addresses to fill or
|
|
5103
|
+
* override those slots. Anything else throws — a typo'd key silently dropped
|
|
5059
5104
|
* here would otherwise change the built instruction. `options.accounts` on
|
|
5060
|
-
* {@link BuildOptions}
|
|
5105
|
+
* {@link BuildOptions} is the explicit override map and wins over merged params.
|
|
5061
5106
|
*/
|
|
5062
5107
|
function splitParams(handler, params) {
|
|
5063
5108
|
const argNameSet = new Set(handler.argNames);
|
|
@@ -5206,22 +5251,39 @@ function resolveSeeds(seeds, context) {
|
|
|
5206
5251
|
}
|
|
5207
5252
|
});
|
|
5208
5253
|
}
|
|
5209
|
-
function
|
|
5254
|
+
function resolveProgram(selector, context) {
|
|
5255
|
+
if (typeof selector === 'string')
|
|
5256
|
+
return context.programId ?? selector;
|
|
5257
|
+
if (selector.type === 'accountRef') {
|
|
5258
|
+
const address = context.accounts?.[selector.accountName];
|
|
5259
|
+
if (!address)
|
|
5260
|
+
throw new Error(`Missing account for PDA program: ${selector.accountName}`);
|
|
5261
|
+
return address;
|
|
5262
|
+
}
|
|
5263
|
+
const value = getValueByPath(context.args, selector.argName)
|
|
5264
|
+
?? getValueByPath(context.resolve, selector.argName);
|
|
5265
|
+
if (typeof value !== 'string' || value.length === 0) {
|
|
5266
|
+
throw new Error(`Missing argument for PDA program: ${selector.argName}`);
|
|
5267
|
+
}
|
|
5268
|
+
return value;
|
|
5269
|
+
}
|
|
5270
|
+
function pda(programSelector, ...seeds) {
|
|
5210
5271
|
return {
|
|
5211
5272
|
seeds,
|
|
5212
|
-
programId,
|
|
5273
|
+
programId: typeof programSelector === 'string' ? programSelector : undefined,
|
|
5274
|
+
programSelector,
|
|
5213
5275
|
program(newProgramId) {
|
|
5214
5276
|
return pda(newProgramId, ...seeds);
|
|
5215
5277
|
},
|
|
5216
5278
|
async derive(context) {
|
|
5217
5279
|
const resolvedSeeds = resolveSeeds(this.seeds, context);
|
|
5218
|
-
const pid =
|
|
5280
|
+
const pid = resolveProgram(this.programSelector, context);
|
|
5219
5281
|
const [address] = await findProgramAddress(resolvedSeeds, pid);
|
|
5220
5282
|
return address;
|
|
5221
5283
|
},
|
|
5222
5284
|
deriveSync(context) {
|
|
5223
5285
|
const resolvedSeeds = resolveSeeds(this.seeds, context);
|
|
5224
|
-
const pid =
|
|
5286
|
+
const pid = resolveProgram(this.programSelector, context);
|
|
5225
5287
|
const [address] = findProgramAddressSync(resolvedSeeds, pid);
|
|
5226
5288
|
return address;
|
|
5227
5289
|
},
|
|
@@ -5384,6 +5446,7 @@ function createPreparedTransactionBody(input) {
|
|
|
5384
5446
|
name: input.name,
|
|
5385
5447
|
instructions,
|
|
5386
5448
|
requiredSignerAddresses: dedupe(input.requiredSignerAddresses ?? inferSignerAddresses(instructions)),
|
|
5449
|
+
signers: [...new Set(input.signers ?? [])],
|
|
5387
5450
|
errors: [...(input.errors ?? [])],
|
|
5388
5451
|
};
|
|
5389
5452
|
}
|
|
@@ -5399,6 +5462,7 @@ function createPreparedInstruction(input) {
|
|
|
5399
5462
|
name: input.name,
|
|
5400
5463
|
instructions: [input.instruction],
|
|
5401
5464
|
requiredSignerAddresses: input.requiredSignerAddresses,
|
|
5465
|
+
signers: input.signers,
|
|
5402
5466
|
errors: input.errors,
|
|
5403
5467
|
});
|
|
5404
5468
|
return {
|
|
@@ -5429,6 +5493,10 @@ function createPreparedTransaction(input) {
|
|
|
5429
5493
|
instructions: transactionParts.flatMap((part) => part.instructions),
|
|
5430
5494
|
requiredSignerAddresses: input.requiredSignerAddresses
|
|
5431
5495
|
?? transactionParts.flatMap((part) => part.requiredSignerAddresses),
|
|
5496
|
+
signers: [
|
|
5497
|
+
...transactionParts.flatMap((part) => part.signers),
|
|
5498
|
+
...(input.signers ?? []),
|
|
5499
|
+
],
|
|
5432
5500
|
errors: input.errors ?? transactionParts.flatMap((part) => part.errors),
|
|
5433
5501
|
});
|
|
5434
5502
|
return {
|
|
@@ -5505,8 +5573,8 @@ function inferSignerAddress(value) {
|
|
|
5505
5573
|
const publicKey = candidate.publicKey;
|
|
5506
5574
|
return typeof publicKey?.toBase58 === 'function' ? publicKey.toBase58() : null;
|
|
5507
5575
|
}
|
|
5508
|
-
function validateTransactionSigners(transaction, host, options) {
|
|
5509
|
-
const signerAddresses =
|
|
5576
|
+
function validateTransactionSigners(transaction, host, options, signers) {
|
|
5577
|
+
const signerAddresses = signers.map(inferSignerAddress);
|
|
5510
5578
|
const available = new Set(options.availableSignerAddresses ?? []);
|
|
5511
5579
|
for (const address of options.signerRegistry?.addresses() ?? []) {
|
|
5512
5580
|
available.add(address);
|
|
@@ -5592,15 +5660,16 @@ async function runOperationCallback(input, callbackErrors, onCallbackError) {
|
|
|
5592
5660
|
async function executePreparedOperation(host, operation, options = {}) {
|
|
5593
5661
|
const receipts = [];
|
|
5594
5662
|
const callbackErrors = [];
|
|
5595
|
-
const signers = [
|
|
5596
|
-
...new Set([
|
|
5597
|
-
...(options.signerRegistry?.values() ?? []),
|
|
5598
|
-
...(options.signers ?? []),
|
|
5599
|
-
]),
|
|
5600
|
-
];
|
|
5601
5663
|
for (const [transactionIndex, transaction] of operation.plan.transactions.entries()) {
|
|
5664
|
+
const signers = [
|
|
5665
|
+
...new Set([
|
|
5666
|
+
...(transaction.signers ?? []),
|
|
5667
|
+
...(options.signerRegistry?.values() ?? []),
|
|
5668
|
+
...(options.signers ?? []),
|
|
5669
|
+
]),
|
|
5670
|
+
];
|
|
5602
5671
|
try {
|
|
5603
|
-
validateTransactionSigners(transaction, host, options);
|
|
5672
|
+
validateTransactionSigners(transaction, host, options, signers);
|
|
5604
5673
|
}
|
|
5605
5674
|
catch (cause) {
|
|
5606
5675
|
throw new OperationExecutionError({
|