@solana/instructions 2.1.0 → 2.1.1-canary-20250310215239
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/README.md +3 -3
- package/dist/index.browser.cjs +4 -4
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.mjs +4 -4
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.native.mjs +4 -4
- package/dist/index.native.mjs.map +1 -1
- package/dist/index.node.cjs +4 -4
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +4 -4
- package/dist/index.node.mjs.map +1 -1
- package/dist/types/accounts.d.ts +57 -0
- package/dist/types/accounts.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/instruction.d.ts +43 -0
- package/dist/types/instruction.d.ts.map +1 -1
- package/dist/types/roles.d.ts +42 -1
- package/dist/types/roles.d.ts.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -75,7 +75,7 @@ type StakeProgramInstruction = IInstruction<'StakeConfig111111111111111111111111
|
|
|
75
75
|
|
|
76
76
|
### `IInstructionWithAccounts<TAccounts>`
|
|
77
77
|
|
|
78
|
-
Use this type to specify an instruction that
|
|
78
|
+
Use this type to specify an instruction that loads certain accounts.
|
|
79
79
|
|
|
80
80
|
```ts
|
|
81
81
|
type InstructionWithTwoAccounts = IInstructionWithAccounts<
|
|
@@ -88,7 +88,7 @@ type InstructionWithTwoAccounts = IInstructionWithAccounts<
|
|
|
88
88
|
|
|
89
89
|
### `IInstructionWithData<TData>`
|
|
90
90
|
|
|
91
|
-
Use this type to specify an instruction whose data conforms to a certain type. This is most useful when you have a branded `Uint8Array` that represents a particular instruction.
|
|
91
|
+
Use this type to specify an instruction whose data conforms to a certain type. This is most useful when you have a branded `Uint8Array` that represents a particular instruction's data.
|
|
92
92
|
|
|
93
93
|
For example, here is how the `AdvanceNonce` instruction is typed.
|
|
94
94
|
|
|
@@ -134,7 +134,7 @@ Returns an `AccountRole` representing the non-signer variant of the supplied rol
|
|
|
134
134
|
|
|
135
135
|
### `downgradeRoleToReadonly(role: AccountRole)`
|
|
136
136
|
|
|
137
|
-
Returns an `AccountRole` representing the
|
|
137
|
+
Returns an `AccountRole` representing the read-only variant of the supplied role.
|
|
138
138
|
|
|
139
139
|
### `upgradeRoleToSigner(role: AccountRole)`
|
|
140
140
|
|
package/dist/index.browser.cjs
CHANGED
|
@@ -15,10 +15,10 @@ function assertIsInstructionForProgram(instruction, programAddress) {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
function isInstructionWithAccounts(instruction) {
|
|
18
|
-
return instruction.accounts !==
|
|
18
|
+
return instruction.accounts !== void 0;
|
|
19
19
|
}
|
|
20
20
|
function assertIsInstructionWithAccounts(instruction) {
|
|
21
|
-
if (instruction.accounts ===
|
|
21
|
+
if (instruction.accounts === void 0) {
|
|
22
22
|
throw new errors.SolanaError(errors.SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS, {
|
|
23
23
|
data: instruction.data,
|
|
24
24
|
programAddress: instruction.programAddress
|
|
@@ -26,10 +26,10 @@ function assertIsInstructionWithAccounts(instruction) {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
function isInstructionWithData(instruction) {
|
|
29
|
-
return instruction.data !==
|
|
29
|
+
return instruction.data !== void 0;
|
|
30
30
|
}
|
|
31
31
|
function assertIsInstructionWithData(instruction) {
|
|
32
|
-
if (instruction.data ===
|
|
32
|
+
if (instruction.data === void 0) {
|
|
33
33
|
throw new errors.SolanaError(errors.SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA, {
|
|
34
34
|
accountAddresses: instruction.accounts?.map((a) => a.address),
|
|
35
35
|
programAddress: instruction.programAddress
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/instruction.ts","../src/roles.ts"],"names":["SolanaError","SOLANA_ERROR__INSTRUCTION__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AA,CAAA;AAAA,EAA0B,CAA1B,CAAA,GAAA,iBAAA;AACA,EAAAA,YAAA,CAAA,YAAA,CAAA,iBAAA,CAAA;AAAA,EAA0B,CAA1B,CAAA,GAAA,iBAAA;AACA,EAAAA,YAAA,CAAA,YAAA,CAAA,UAAA,CAAA;AAAA,EAA0B,CAA1B,CAAA,GAAA,UAAA;AACA,EAAAA,YAAA,CAAA,YAAA,CAAA,UAAA,CAAA;AAAA,EAA0B,CAA1B,CAAA,GAAA,UAAA;AALQ,EAAAA,OAAAA,YAAAA;AAAA,CAAA,EAAA,WAAA,IAAA,EAAA;AAQZ,IAAM,iBAAoB,GAAA,CAAA;AAC1B,IAAM,mBAAsB,GAAA,CAAA;AAKrB,SAAS,yBAAyB,IAAgC,EAAA;AACrE,EAAA,OAAO,OAAO,EAAC;AACnB;AAKO,SAAS,wBAAwB,IAAgC,EAAA;AACpE,EAAA,OAAO,OAAO,EAAC;AACnB;AAEO,SAAS,aAAa,IAAsF,EAAA;AAC/G,EAAA,OAAO,IAAQ,IAAA,CAAA;AACnB;AAEO,SAAS,eAAe,IAA+E,EAAA;AAC1G,EAAA,OAAA,CAAQ,OAAO,mBAAyB,MAAA,CAAA;AAC5C;AAYO,SAAS,UAAA,CAAW,OAAoB,KAAiC,EAAA;AAC5E,EAAA,OAAO,KAAQ,GAAA,KAAA;AACnB;AAKO,SAAS,oBAAoB,IAAgC,EAAA;AAChE,EAAA,OAAO,IAAO,GAAA,iBAAA;AAClB;AAKO,SAAS,sBAAsB,IAAgC,EAAA;AAClE,EAAA,OAAO,IAAO,GAAA,mBAAA;AAClB","file":"index.browser.cjs","sourcesContent":["import { Address } from '@solana/addresses';\nimport { ReadonlyUint8Array } from '@solana/codecs-core';\nimport {\n SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS,\n SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA,\n SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH,\n SolanaError,\n} from '@solana/errors';\n\nimport { IAccountLookupMeta, IAccountMeta } from './accounts';\n\nexport interface IInstruction<\n TProgramAddress extends string = string,\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n> {\n readonly accounts?: TAccounts;\n readonly data?: ReadonlyUint8Array;\n readonly programAddress: Address<TProgramAddress>;\n}\n\nexport interface IInstructionWithAccounts<TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[]>\n extends IInstruction {\n readonly accounts: TAccounts;\n}\n\nexport function isInstructionForProgram<TProgramAddress extends string, TInstruction extends IInstruction>(\n instruction: TInstruction,\n programAddress: Address<TProgramAddress>,\n): instruction is TInstruction & { programAddress: Address<TProgramAddress> } {\n return instruction.programAddress === programAddress;\n}\n\nexport function assertIsInstructionForProgram<TProgramAddress extends string, TInstruction extends IInstruction>(\n instruction: TInstruction,\n programAddress: Address<TProgramAddress>,\n): asserts instruction is TInstruction & { programAddress: Address<TProgramAddress> } {\n if (instruction.programAddress !== programAddress) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH, {\n actualProgramAddress: instruction.programAddress,\n expectedProgramAddress: programAddress,\n });\n }\n}\n\nexport function isInstructionWithAccounts<\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): instruction is IInstructionWithAccounts<TAccounts> & TInstruction {\n return instruction.accounts !== undefined;\n}\n\nexport function assertIsInstructionWithAccounts<\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): asserts instruction is IInstructionWithAccounts<TAccounts> & TInstruction {\n if (instruction.accounts === undefined) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS, {\n data: instruction.data,\n programAddress: instruction.programAddress,\n });\n }\n}\n\nexport interface IInstructionWithData<TData extends ReadonlyUint8Array> extends IInstruction {\n readonly data: TData;\n}\n\nexport function isInstructionWithData<\n TData extends ReadonlyUint8Array = ReadonlyUint8Array,\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): instruction is IInstructionWithData<TData> & TInstruction {\n return instruction.data !== undefined;\n}\n\nexport function assertIsInstructionWithData<\n TData extends ReadonlyUint8Array = ReadonlyUint8Array,\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): asserts instruction is IInstructionWithData<TData> & TInstruction {\n if (instruction.data === undefined) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA, {\n accountAddresses: instruction.accounts?.map(a => a.address),\n programAddress: instruction.programAddress,\n });\n }\n}\n","/**\n * Quick primer on bitwise operations: https://stackoverflow.com/a/1436448/802047\n */\n\nexport enum AccountRole {\n // Bitflag guide: is signer ⌄⌄ is writable\n WRITABLE_SIGNER = /* 3 */ 0b11, // prettier-ignore\n READONLY_SIGNER = /* 2 */ 0b10, // prettier-ignore\n WRITABLE = /* 1 */ 0b01, // prettier-ignore\n READONLY = /* 0 */ 0b00, // prettier-ignore\n}\n\nconst IS_SIGNER_BITMASK = 0b10;\nconst IS_WRITABLE_BITMASK = 0b01;\n\nexport function downgradeRoleToNonSigner(role: AccountRole.READONLY_SIGNER): AccountRole.READONLY;\nexport function downgradeRoleToNonSigner(role: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE;\nexport function downgradeRoleToNonSigner(role: AccountRole): AccountRole;\nexport function downgradeRoleToNonSigner(role: AccountRole): AccountRole {\n return role & ~IS_SIGNER_BITMASK;\n}\n\nexport function downgradeRoleToReadonly(role: AccountRole.WRITABLE): AccountRole.READONLY;\nexport function downgradeRoleToReadonly(role: AccountRole.WRITABLE_SIGNER): AccountRole.READONLY_SIGNER;\nexport function downgradeRoleToReadonly(role: AccountRole): AccountRole;\nexport function downgradeRoleToReadonly(role: AccountRole): AccountRole {\n return role & ~IS_WRITABLE_BITMASK;\n}\n\nexport function isSignerRole(role: AccountRole): role is AccountRole.READONLY_SIGNER | AccountRole.WRITABLE_SIGNER {\n return role >= AccountRole.READONLY_SIGNER;\n}\n\nexport function isWritableRole(role: AccountRole): role is AccountRole.WRITABLE | AccountRole.WRITABLE_SIGNER {\n return (role & IS_WRITABLE_BITMASK) !== 0;\n}\n\nexport function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.WRITABLE_SIGNER, roleB: AccountRole): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.READONLY_SIGNER): AccountRole.READONLY_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole): AccountRole.READONLY_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole): AccountRole.WRITABLE; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY, roleB: AccountRole.READONLY): AccountRole.READONLY; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole): AccountRole; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole): AccountRole {\n return roleA | roleB;\n}\n\nexport function upgradeRoleToSigner(role: AccountRole.READONLY): AccountRole.READONLY_SIGNER;\nexport function upgradeRoleToSigner(role: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER;\nexport function upgradeRoleToSigner(role: AccountRole): AccountRole;\nexport function upgradeRoleToSigner(role: AccountRole): AccountRole {\n return role | IS_SIGNER_BITMASK;\n}\n\nexport function upgradeRoleToWritable(role: AccountRole.READONLY): AccountRole.WRITABLE;\nexport function upgradeRoleToWritable(role: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER;\nexport function upgradeRoleToWritable(role: AccountRole): AccountRole;\nexport function upgradeRoleToWritable(role: AccountRole): AccountRole {\n return role | IS_WRITABLE_BITMASK;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/instruction.ts","../src/roles.ts"],"names":["SolanaError","SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH","SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS","SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA","AccountRole"],"mappings":";;;;;AA8CO,SAAS,uBAAA,CACZ,aACA,cAC0E,EAAA;AAC1E,EAAA,OAAO,YAAY,cAAmB,KAAA,cAAA;AAC1C;AAEO,SAAS,6BAAA,CACZ,aACA,cACkF,EAAA;AAClF,EAAI,IAAA,WAAA,CAAY,mBAAmB,cAAgB,EAAA;AAC/C,IAAM,MAAA,IAAIA,mBAAYC,qDAAgD,EAAA;AAAA,MAClE,sBAAsB,WAAY,CAAA,cAAA;AAAA,MAClC,sBAAwB,EAAA;AAAA,KAC3B,CAAA;AAAA;AAET;AAEO,SAAS,0BAGd,WAA8F,EAAA;AAC5F,EAAA,OAAO,YAAY,QAAa,KAAA,MAAA;AACpC;AAEO,SAAS,gCAGd,WAAsG,EAAA;AACpG,EAAI,IAAA,WAAA,CAAY,aAAa,MAAW,EAAA;AACpC,IAAM,MAAA,IAAID,mBAAYE,2DAAsD,EAAA;AAAA,MACxE,MAAM,WAAY,CAAA,IAAA;AAAA,MAClB,gBAAgB,WAAY,CAAA;AAAA,KAC/B,CAAA;AAAA;AAET;AA4BO,S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EAAA;AAC5E,EAAA,OAAO,KAAQ,GAAA,KAAA;AACnB;AAQO,SAAS,oBAAoB,IAAgC,EAAA;AAChE,EAAA,OAAO,IAAO,GAAA,iBAAA;AAClB;AAQO,SAAS,sBAAsB,IAAgC,EAAA;AAClE,EAAA,OAAO,IAAO,GAAA,mBAAA;AAClB","file":"index.browser.cjs","sourcesContent":["import { Address } from '@solana/addresses';\nimport { ReadonlyUint8Array } from '@solana/codecs-core';\nimport {\n SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS,\n SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA,\n SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH,\n SolanaError,\n} from '@solana/errors';\n\nimport { IAccountLookupMeta, IAccountMeta } from './accounts';\n\n/**\n * An instruction destined for a given program.\n *\n * @example\n * ```ts\n * type StakeProgramInstruction = IInstruction<'StakeConfig11111111111111111111111111111111'>;\n * ```\n */\nexport interface IInstruction<\n TProgramAddress extends string = string,\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n> {\n readonly accounts?: TAccounts;\n readonly data?: ReadonlyUint8Array;\n readonly programAddress: Address<TProgramAddress>;\n}\n\n/**\n * An instruction that loads certain accounts.\n *\n * @example\n * ```ts\n * type InstructionWithTwoAccounts = IInstructionWithAccounts<\n * [\n * WritableAccount, // First account\n * RentSysvar, // Second account\n * ]\n * >;\n * ```\n */\nexport interface IInstructionWithAccounts<TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[]>\n extends IInstruction {\n readonly accounts: TAccounts;\n}\n\nexport function isInstructionForProgram<TProgramAddress extends string, TInstruction extends IInstruction>(\n instruction: TInstruction,\n programAddress: Address<TProgramAddress>,\n): instruction is TInstruction & { programAddress: Address<TProgramAddress> } {\n return instruction.programAddress === programAddress;\n}\n\nexport function assertIsInstructionForProgram<TProgramAddress extends string, TInstruction extends IInstruction>(\n instruction: TInstruction,\n programAddress: Address<TProgramAddress>,\n): asserts instruction is TInstruction & { programAddress: Address<TProgramAddress> } {\n if (instruction.programAddress !== programAddress) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH, {\n actualProgramAddress: instruction.programAddress,\n expectedProgramAddress: programAddress,\n });\n }\n}\n\nexport function isInstructionWithAccounts<\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): instruction is IInstructionWithAccounts<TAccounts> & TInstruction {\n return instruction.accounts !== undefined;\n}\n\nexport function assertIsInstructionWithAccounts<\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): asserts instruction is IInstructionWithAccounts<TAccounts> & TInstruction {\n if (instruction.accounts === undefined) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS, {\n data: instruction.data,\n programAddress: instruction.programAddress,\n });\n }\n}\n\n/**\n * An instruction whose data conforms to a certain type.\n *\n * This is most useful when you have a branded `Uint8Array` that represents a particular\n * instruction's data.\n *\n * @example A type for the \\`AdvanceNonce\\` instruction of the System program\n * ```ts\n * type AdvanceNonceAccountInstruction<\n * TNonceAccountAddress extends string = string,\n * TNonceAuthorityAddress extends string = string,\n * > = IInstruction<'11111111111111111111111111111111'> &\n * IInstructionWithAccounts<\n * [\n * WritableAccount<TNonceAccountAddress>,\n * ReadonlyAccount<'SysvarRecentB1ockHashes11111111111111111111'>,\n * ReadonlySignerAccount<TNonceAuthorityAddress>,\n * ]\n * > &\n * IInstructionWithData<AdvanceNonceAccountInstructionData>;\n * ```\n */\nexport interface IInstructionWithData<TData extends ReadonlyUint8Array> extends IInstruction {\n readonly data: TData;\n}\n\nexport function isInstructionWithData<\n TData extends ReadonlyUint8Array = ReadonlyUint8Array,\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): instruction is IInstructionWithData<TData> & TInstruction {\n return instruction.data !== undefined;\n}\n\nexport function assertIsInstructionWithData<\n TData extends ReadonlyUint8Array = ReadonlyUint8Array,\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): asserts instruction is IInstructionWithData<TData> & TInstruction {\n if (instruction.data === undefined) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA, {\n accountAddresses: instruction.accounts?.map(a => a.address),\n programAddress: instruction.programAddress,\n });\n }\n}\n","/**\n * Describes the purpose for which an account participates in a transaction.\n *\n * Every account that participates in a transaction can be read from, but only ones that you mark as\n * writable may be written to, and only ones that you indicate must sign the transaction will gain\n * the privileges associated with signers at runtime.\n *\n * | | `isSigner` | `isWritable` |\n * | ----------------------------- | ---------- | ------------ |\n * | `AccountRole.READONLY` | ❌ | ❌ |\n * | `AccountRole.WRITABLE` | ❌ | ✅ |\n * | `AccountRole.READONLY_SIGNER` | ✅ | ❌ |\n * | `AccountRole.WRITABLE_SIGNER` | ✅ | ✅ |\n */\nexport enum AccountRole {\n // Bitflag guide: is signer ⌄⌄ is writable\n WRITABLE_SIGNER = /* 3 */ 0b11, // prettier-ignore\n READONLY_SIGNER = /* 2 */ 0b10, // prettier-ignore\n WRITABLE = /* 1 */ 0b01, // prettier-ignore\n READONLY = /* 0 */ 0b00, // prettier-ignore\n}\n\n// Quick primer on bitwise operations: https://stackoverflow.com/a/1436448/802047\nconst IS_SIGNER_BITMASK = 0b10;\nconst IS_WRITABLE_BITMASK = 0b01;\n\n/**\n * @returns An {@link AccountRole} representing the non-signer variant of the supplied role.\n */\nexport function downgradeRoleToNonSigner(role: AccountRole.READONLY_SIGNER): AccountRole.READONLY;\nexport function downgradeRoleToNonSigner(role: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE;\nexport function downgradeRoleToNonSigner(role: AccountRole): AccountRole;\nexport function downgradeRoleToNonSigner(role: AccountRole): AccountRole {\n return role & ~IS_SIGNER_BITMASK;\n}\n\n/**\n * @returns An {@link AccountRole} representing the read-only variant of the supplied role.\n */\nexport function downgradeRoleToReadonly(role: AccountRole.WRITABLE): AccountRole.READONLY;\nexport function downgradeRoleToReadonly(role: AccountRole.WRITABLE_SIGNER): AccountRole.READONLY_SIGNER;\nexport function downgradeRoleToReadonly(role: AccountRole): AccountRole;\nexport function downgradeRoleToReadonly(role: AccountRole): AccountRole {\n return role & ~IS_WRITABLE_BITMASK;\n}\n\n/**\n * Returns `true` if the {@link AccountRole} given represents that of a signer. Also refines the\n * TypeScript type of the supplied role.\n */\nexport function isSignerRole(role: AccountRole): role is AccountRole.READONLY_SIGNER | AccountRole.WRITABLE_SIGNER {\n return role >= AccountRole.READONLY_SIGNER;\n}\n\n/**\n * Returns `true` if the {@link AccountRole} given represents that of a writable account. Also\n * refines the TypeScript type of the supplied role.\n */\nexport function isWritableRole(role: AccountRole): role is AccountRole.WRITABLE | AccountRole.WRITABLE_SIGNER {\n return (role & IS_WRITABLE_BITMASK) !== 0;\n}\n\n/**\n * Given two {@link AccountRole | AccountRoles}, will return the {@link AccountRole} that grants the\n * highest privileges of both.\n *\n * @example\n * ```ts\n * // Returns `AccountRole.WRITABLE_SIGNER`\n * mergeRoles(AccountRole.READONLY_SIGNER, AccountRole.WRITABLE);\n * ```\n */\nexport function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.WRITABLE_SIGNER, roleB: AccountRole): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.READONLY_SIGNER): AccountRole.READONLY_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole): AccountRole.READONLY_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole): AccountRole.WRITABLE; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY, roleB: AccountRole.READONLY): AccountRole.READONLY; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole): AccountRole; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole): AccountRole {\n return roleA | roleB;\n}\n\n/**\n * @returns An {@link AccountRole} representing the signer variant of the supplied role.\n */\nexport function upgradeRoleToSigner(role: AccountRole.READONLY): AccountRole.READONLY_SIGNER;\nexport function upgradeRoleToSigner(role: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER;\nexport function upgradeRoleToSigner(role: AccountRole): AccountRole;\nexport function upgradeRoleToSigner(role: AccountRole): AccountRole {\n return role | IS_SIGNER_BITMASK;\n}\n\n/**\n * @returns An {@link AccountRole} representing the writable variant of the supplied role.\n */\nexport function upgradeRoleToWritable(role: AccountRole.READONLY): AccountRole.WRITABLE;\nexport function upgradeRoleToWritable(role: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER;\nexport function upgradeRoleToWritable(role: AccountRole): AccountRole;\nexport function upgradeRoleToWritable(role: AccountRole): AccountRole {\n return role | IS_WRITABLE_BITMASK;\n}\n"]}
|
package/dist/index.browser.mjs
CHANGED
|
@@ -13,10 +13,10 @@ function assertIsInstructionForProgram(instruction, programAddress) {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
function isInstructionWithAccounts(instruction) {
|
|
16
|
-
return instruction.accounts !==
|
|
16
|
+
return instruction.accounts !== void 0;
|
|
17
17
|
}
|
|
18
18
|
function assertIsInstructionWithAccounts(instruction) {
|
|
19
|
-
if (instruction.accounts ===
|
|
19
|
+
if (instruction.accounts === void 0) {
|
|
20
20
|
throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS, {
|
|
21
21
|
data: instruction.data,
|
|
22
22
|
programAddress: instruction.programAddress
|
|
@@ -24,10 +24,10 @@ function assertIsInstructionWithAccounts(instruction) {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
function isInstructionWithData(instruction) {
|
|
27
|
-
return instruction.data !==
|
|
27
|
+
return instruction.data !== void 0;
|
|
28
28
|
}
|
|
29
29
|
function assertIsInstructionWithData(instruction) {
|
|
30
|
-
if (instruction.data ===
|
|
30
|
+
if (instruction.data === void 0) {
|
|
31
31
|
throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA, {
|
|
32
32
|
accountAddresses: instruction.accounts?.map((a) => a.address),
|
|
33
33
|
programAddress: instruction.programAddress
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/instruction.ts","../src/roles.ts"],"names":["AccountRole"],"mappings":";;;AAyBO,SAAS,uBAAA,CACZ,aACA,cAC0E,EAAA;AAC1E,EAAA,OAAO,YAAY,cAAmB,KAAA,cAAA;AAC1C;AAEO,SAAS,6BAAA,CACZ,aACA,cACkF,EAAA;AAClF,EAAI,IAAA,WAAA,CAAY,mBAAmB,cAAgB,EAAA;AAC/C,IAAM,MAAA,IAAI,YAAY,8CAAgD,EAAA;AAAA,MAClE,sBAAsB,WAAY,CAAA,cAAA;AAAA,MAClC,sBAAwB,EAAA;AAAA,KAC3B,CAAA;AAAA;AAET;AAEO,SAAS,0BAGd,WAA8F,EAAA;AAC5F,EAAA,OAAO,YAAY,QAAa,KAAA,SAAA;AACpC;AAEO,SAAS,gCAGd,WAAsG,EAAA;AACpG,EAAI,IAAA,WAAA,CAAY,aAAa,SAAW,EA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,IAAA,CAAA;AACnB;AAEO,SAAS,eAAe,IAA+E,EAAA;AAC1G,EAAA,OAAA,CAAQ,OAAO,mBAAyB,MAAA,CAAA;AAC5C;AAYO,SAAS,UAAA,CAAW,OAAoB,KAAiC,EAAA;AAC5E,EAAA,OAAO,KAAQ,GAAA,KAAA;AACnB;AAKO,SAAS,oBAAoB,IAAgC,EAAA;AAChE,EAAA,OAAO,IAAO,GAAA,iBAAA;AAClB;AAKO,SAAS,sBAAsB,IAAgC,EAAA;AAClE,EAAA,OAAO,IAAO,GAAA,mBAAA;AAClB","file":"index.browser.mjs","sourcesContent":["import { Address } from '@solana/addresses';\nimport { ReadonlyUint8Array } from '@solana/codecs-core';\nimport {\n SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS,\n SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA,\n SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH,\n SolanaError,\n} from '@solana/errors';\n\nimport { IAccountLookupMeta, IAccountMeta } from './accounts';\n\nexport interface IInstruction<\n TProgramAddress extends string = string,\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n> {\n readonly accounts?: TAccounts;\n readonly data?: ReadonlyUint8Array;\n readonly programAddress: Address<TProgramAddress>;\n}\n\nexport interface IInstructionWithAccounts<TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[]>\n extends IInstruction {\n readonly accounts: TAccounts;\n}\n\nexport function isInstructionForProgram<TProgramAddress extends string, TInstruction extends IInstruction>(\n instruction: TInstruction,\n programAddress: Address<TProgramAddress>,\n): instruction is TInstruction & { programAddress: Address<TProgramAddress> } {\n return instruction.programAddress === programAddress;\n}\n\nexport function assertIsInstructionForProgram<TProgramAddress extends string, TInstruction extends IInstruction>(\n instruction: TInstruction,\n programAddress: Address<TProgramAddress>,\n): asserts instruction is TInstruction & { programAddress: Address<TProgramAddress> } {\n if (instruction.programAddress !== programAddress) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH, {\n actualProgramAddress: instruction.programAddress,\n expectedProgramAddress: programAddress,\n });\n }\n}\n\nexport function isInstructionWithAccounts<\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): instruction is IInstructionWithAccounts<TAccounts> & TInstruction {\n return instruction.accounts !== undefined;\n}\n\nexport function assertIsInstructionWithAccounts<\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): asserts instruction is IInstructionWithAccounts<TAccounts> & TInstruction {\n if (instruction.accounts === undefined) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS, {\n data: instruction.data,\n programAddress: instruction.programAddress,\n });\n }\n}\n\nexport interface IInstructionWithData<TData extends ReadonlyUint8Array> extends IInstruction {\n readonly data: TData;\n}\n\nexport function isInstructionWithData<\n TData extends ReadonlyUint8Array = ReadonlyUint8Array,\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): instruction is IInstructionWithData<TData> & TInstruction {\n return instruction.data !== undefined;\n}\n\nexport function assertIsInstructionWithData<\n TData extends ReadonlyUint8Array = ReadonlyUint8Array,\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): asserts instruction is IInstructionWithData<TData> & TInstruction {\n if (instruction.data === undefined) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA, {\n accountAddresses: instruction.accounts?.map(a => a.address),\n programAddress: instruction.programAddress,\n });\n }\n}\n","/**\n * Quick primer on bitwise operations: https://stackoverflow.com/a/1436448/802047\n */\n\nexport enum AccountRole {\n // Bitflag guide: is signer ⌄⌄ is writable\n WRITABLE_SIGNER = /* 3 */ 0b11, // prettier-ignore\n READONLY_SIGNER = /* 2 */ 0b10, // prettier-ignore\n WRITABLE = /* 1 */ 0b01, // prettier-ignore\n READONLY = /* 0 */ 0b00, // prettier-ignore\n}\n\nconst IS_SIGNER_BITMASK = 0b10;\nconst IS_WRITABLE_BITMASK = 0b01;\n\nexport function downgradeRoleToNonSigner(role: AccountRole.READONLY_SIGNER): AccountRole.READONLY;\nexport function downgradeRoleToNonSigner(role: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE;\nexport function downgradeRoleToNonSigner(role: AccountRole): AccountRole;\nexport function downgradeRoleToNonSigner(role: AccountRole): AccountRole {\n return role & ~IS_SIGNER_BITMASK;\n}\n\nexport function downgradeRoleToReadonly(role: AccountRole.WRITABLE): AccountRole.READONLY;\nexport function downgradeRoleToReadonly(role: AccountRole.WRITABLE_SIGNER): AccountRole.READONLY_SIGNER;\nexport function downgradeRoleToReadonly(role: AccountRole): AccountRole;\nexport function downgradeRoleToReadonly(role: AccountRole): AccountRole {\n return role & ~IS_WRITABLE_BITMASK;\n}\n\nexport function isSignerRole(role: AccountRole): role is AccountRole.READONLY_SIGNER | AccountRole.WRITABLE_SIGNER {\n return role >= AccountRole.READONLY_SIGNER;\n}\n\nexport function isWritableRole(role: AccountRole): role is AccountRole.WRITABLE | AccountRole.WRITABLE_SIGNER {\n return (role & IS_WRITABLE_BITMASK) !== 0;\n}\n\nexport function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.WRITABLE_SIGNER, roleB: AccountRole): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.READONLY_SIGNER): AccountRole.READONLY_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole): AccountRole.READONLY_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole): AccountRole.WRITABLE; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY, roleB: AccountRole.READONLY): AccountRole.READONLY; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole): AccountRole; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole): AccountRole {\n return roleA | roleB;\n}\n\nexport function upgradeRoleToSigner(role: AccountRole.READONLY): AccountRole.READONLY_SIGNER;\nexport function upgradeRoleToSigner(role: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER;\nexport function upgradeRoleToSigner(role: AccountRole): AccountRole;\nexport function upgradeRoleToSigner(role: AccountRole): AccountRole {\n return role | IS_SIGNER_BITMASK;\n}\n\nexport function upgradeRoleToWritable(role: AccountRole.READONLY): AccountRole.WRITABLE;\nexport function upgradeRoleToWritable(role: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER;\nexport function upgradeRoleToWritable(role: AccountRole): AccountRole;\nexport function upgradeRoleToWritable(role: AccountRole): AccountRole {\n return role | IS_WRITABLE_BITMASK;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/instruction.ts","../src/roles.ts"],"names":["AccountRole"],"mappings":";;;AA8CO,SAAS,uBAAA,CACZ,aACA,cAC0E,EAAA;AAC1E,EAAA,OAAO,YAAY,cAAmB,KAAA,cAAA;AAC1C;AAEO,SAAS,6BAAA,CACZ,aACA,cACkF,EAAA;AAClF,EAAI,IAAA,WAAA,CAAY,mBAAmB,cAAgB,EAAA;AAC/C,IAAM,MAAA,IAA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A,IAAA,EAAA;AASZ,IAAM,iBAAoB,GAAA,CAAA;AAC1B,IAAM,mBAAsB,GAAA,CAAA;AAQrB,SAAS,yBAAyB,IAAgC,EAAA;AACrE,EAAA,OAAO,OAAO,EAAC;AACnB;AAQO,SAAS,wBAAwB,IAAgC,EAAA;AACpE,EAAA,OAAO,OAAO,EAAC;AACnB;AAMO,SAAS,aAAa,IAAsF,EAAA;AAC/G,EAAA,OAAO,IAAQ,IAAA,CAAA;AACnB;AAMO,SAAS,eAAe,IAA+E,EAAA;AAC1G,EAAA,OAAA,CAAQ,OAAO,mBAAyB,MAAA,CAAA;AAC5C;AAsBO,SAAS,UAAA,CAAW,OAAoB,KAAiC,EAAA;AAC5E,EAAA,OAAO,KAAQ,GAAA,KAAA;AACnB;AAQO,SAAS,oBAAoB,IAAgC,EAAA;AAChE,EAAA,OAAO,IAAO,GAAA,iBAAA;AAClB;AAQO,SAAS,sBAAsB,IAAgC,EAAA;AAClE,EAAA,OAAO,IAAO,GAAA,mBAAA;AAClB","file":"index.browser.mjs","sourcesContent":["import { Address } from '@solana/addresses';\nimport { ReadonlyUint8Array } from '@solana/codecs-core';\nimport {\n SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS,\n SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA,\n SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH,\n SolanaError,\n} from '@solana/errors';\n\nimport { IAccountLookupMeta, IAccountMeta } from './accounts';\n\n/**\n * An instruction destined for a given program.\n *\n * @example\n * ```ts\n * type StakeProgramInstruction = IInstruction<'StakeConfig11111111111111111111111111111111'>;\n * ```\n */\nexport interface IInstruction<\n TProgramAddress extends string = string,\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n> {\n readonly accounts?: TAccounts;\n readonly data?: ReadonlyUint8Array;\n readonly programAddress: Address<TProgramAddress>;\n}\n\n/**\n * An instruction that loads certain accounts.\n *\n * @example\n * ```ts\n * type InstructionWithTwoAccounts = IInstructionWithAccounts<\n * [\n * WritableAccount, // First account\n * RentSysvar, // Second account\n * ]\n * >;\n * ```\n */\nexport interface IInstructionWithAccounts<TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[]>\n extends IInstruction {\n readonly accounts: TAccounts;\n}\n\nexport function isInstructionForProgram<TProgramAddress extends string, TInstruction extends IInstruction>(\n instruction: TInstruction,\n programAddress: Address<TProgramAddress>,\n): instruction is TInstruction & { programAddress: Address<TProgramAddress> } {\n return instruction.programAddress === programAddress;\n}\n\nexport function assertIsInstructionForProgram<TProgramAddress extends string, TInstruction extends IInstruction>(\n instruction: TInstruction,\n programAddress: Address<TProgramAddress>,\n): asserts instruction is TInstruction & { programAddress: Address<TProgramAddress> } {\n if (instruction.programAddress !== programAddress) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH, {\n actualProgramAddress: instruction.programAddress,\n expectedProgramAddress: programAddress,\n });\n }\n}\n\nexport function isInstructionWithAccounts<\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): instruction is IInstructionWithAccounts<TAccounts> & TInstruction {\n return instruction.accounts !== undefined;\n}\n\nexport function assertIsInstructionWithAccounts<\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): asserts instruction is IInstructionWithAccounts<TAccounts> & TInstruction {\n if (instruction.accounts === undefined) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS, {\n data: instruction.data,\n programAddress: instruction.programAddress,\n });\n }\n}\n\n/**\n * An instruction whose data conforms to a certain type.\n *\n * This is most useful when you have a branded `Uint8Array` that represents a particular\n * instruction's data.\n *\n * @example A type for the \\`AdvanceNonce\\` instruction of the System program\n * ```ts\n * type AdvanceNonceAccountInstruction<\n * TNonceAccountAddress extends string = string,\n * TNonceAuthorityAddress extends string = string,\n * > = IInstruction<'11111111111111111111111111111111'> &\n * IInstructionWithAccounts<\n * [\n * WritableAccount<TNonceAccountAddress>,\n * ReadonlyAccount<'SysvarRecentB1ockHashes11111111111111111111'>,\n * ReadonlySignerAccount<TNonceAuthorityAddress>,\n * ]\n * > &\n * IInstructionWithData<AdvanceNonceAccountInstructionData>;\n * ```\n */\nexport interface IInstructionWithData<TData extends ReadonlyUint8Array> extends IInstruction {\n readonly data: TData;\n}\n\nexport function isInstructionWithData<\n TData extends ReadonlyUint8Array = ReadonlyUint8Array,\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): instruction is IInstructionWithData<TData> & TInstruction {\n return instruction.data !== undefined;\n}\n\nexport function assertIsInstructionWithData<\n TData extends ReadonlyUint8Array = ReadonlyUint8Array,\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): asserts instruction is IInstructionWithData<TData> & TInstruction {\n if (instruction.data === undefined) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA, {\n accountAddresses: instruction.accounts?.map(a => a.address),\n programAddress: instruction.programAddress,\n });\n }\n}\n","/**\n * Describes the purpose for which an account participates in a transaction.\n *\n * Every account that participates in a transaction can be read from, but only ones that you mark as\n * writable may be written to, and only ones that you indicate must sign the transaction will gain\n * the privileges associated with signers at runtime.\n *\n * | | `isSigner` | `isWritable` |\n * | ----------------------------- | ---------- | ------------ |\n * | `AccountRole.READONLY` | ❌ | ❌ |\n * | `AccountRole.WRITABLE` | ❌ | ✅ |\n * | `AccountRole.READONLY_SIGNER` | ✅ | ❌ |\n * | `AccountRole.WRITABLE_SIGNER` | ✅ | ✅ |\n */\nexport enum AccountRole {\n // Bitflag guide: is signer ⌄⌄ is writable\n WRITABLE_SIGNER = /* 3 */ 0b11, // prettier-ignore\n READONLY_SIGNER = /* 2 */ 0b10, // prettier-ignore\n WRITABLE = /* 1 */ 0b01, // prettier-ignore\n READONLY = /* 0 */ 0b00, // prettier-ignore\n}\n\n// Quick primer on bitwise operations: https://stackoverflow.com/a/1436448/802047\nconst IS_SIGNER_BITMASK = 0b10;\nconst IS_WRITABLE_BITMASK = 0b01;\n\n/**\n * @returns An {@link AccountRole} representing the non-signer variant of the supplied role.\n */\nexport function downgradeRoleToNonSigner(role: AccountRole.READONLY_SIGNER): AccountRole.READONLY;\nexport function downgradeRoleToNonSigner(role: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE;\nexport function downgradeRoleToNonSigner(role: AccountRole): AccountRole;\nexport function downgradeRoleToNonSigner(role: AccountRole): AccountRole {\n return role & ~IS_SIGNER_BITMASK;\n}\n\n/**\n * @returns An {@link AccountRole} representing the read-only variant of the supplied role.\n */\nexport function downgradeRoleToReadonly(role: AccountRole.WRITABLE): AccountRole.READONLY;\nexport function downgradeRoleToReadonly(role: AccountRole.WRITABLE_SIGNER): AccountRole.READONLY_SIGNER;\nexport function downgradeRoleToReadonly(role: AccountRole): AccountRole;\nexport function downgradeRoleToReadonly(role: AccountRole): AccountRole {\n return role & ~IS_WRITABLE_BITMASK;\n}\n\n/**\n * Returns `true` if the {@link AccountRole} given represents that of a signer. Also refines the\n * TypeScript type of the supplied role.\n */\nexport function isSignerRole(role: AccountRole): role is AccountRole.READONLY_SIGNER | AccountRole.WRITABLE_SIGNER {\n return role >= AccountRole.READONLY_SIGNER;\n}\n\n/**\n * Returns `true` if the {@link AccountRole} given represents that of a writable account. Also\n * refines the TypeScript type of the supplied role.\n */\nexport function isWritableRole(role: AccountRole): role is AccountRole.WRITABLE | AccountRole.WRITABLE_SIGNER {\n return (role & IS_WRITABLE_BITMASK) !== 0;\n}\n\n/**\n * Given two {@link AccountRole | AccountRoles}, will return the {@link AccountRole} that grants the\n * highest privileges of both.\n *\n * @example\n * ```ts\n * // Returns `AccountRole.WRITABLE_SIGNER`\n * mergeRoles(AccountRole.READONLY_SIGNER, AccountRole.WRITABLE);\n * ```\n */\nexport function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.WRITABLE_SIGNER, roleB: AccountRole): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.READONLY_SIGNER): AccountRole.READONLY_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole): AccountRole.READONLY_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole): AccountRole.WRITABLE; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY, roleB: AccountRole.READONLY): AccountRole.READONLY; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole): AccountRole; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole): AccountRole {\n return roleA | roleB;\n}\n\n/**\n * @returns An {@link AccountRole} representing the signer variant of the supplied role.\n */\nexport function upgradeRoleToSigner(role: AccountRole.READONLY): AccountRole.READONLY_SIGNER;\nexport function upgradeRoleToSigner(role: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER;\nexport function upgradeRoleToSigner(role: AccountRole): AccountRole;\nexport function upgradeRoleToSigner(role: AccountRole): AccountRole {\n return role | IS_SIGNER_BITMASK;\n}\n\n/**\n * @returns An {@link AccountRole} representing the writable variant of the supplied role.\n */\nexport function upgradeRoleToWritable(role: AccountRole.READONLY): AccountRole.WRITABLE;\nexport function upgradeRoleToWritable(role: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER;\nexport function upgradeRoleToWritable(role: AccountRole): AccountRole;\nexport function upgradeRoleToWritable(role: AccountRole): AccountRole {\n return role | IS_WRITABLE_BITMASK;\n}\n"]}
|
package/dist/index.native.mjs
CHANGED
|
@@ -13,10 +13,10 @@ function assertIsInstructionForProgram(instruction, programAddress) {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
function isInstructionWithAccounts(instruction) {
|
|
16
|
-
return instruction.accounts !==
|
|
16
|
+
return instruction.accounts !== void 0;
|
|
17
17
|
}
|
|
18
18
|
function assertIsInstructionWithAccounts(instruction) {
|
|
19
|
-
if (instruction.accounts ===
|
|
19
|
+
if (instruction.accounts === void 0) {
|
|
20
20
|
throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS, {
|
|
21
21
|
data: instruction.data,
|
|
22
22
|
programAddress: instruction.programAddress
|
|
@@ -24,10 +24,10 @@ function assertIsInstructionWithAccounts(instruction) {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
function isInstructionWithData(instruction) {
|
|
27
|
-
return instruction.data !==
|
|
27
|
+
return instruction.data !== void 0;
|
|
28
28
|
}
|
|
29
29
|
function assertIsInstructionWithData(instruction) {
|
|
30
|
-
if (instruction.data ===
|
|
30
|
+
if (instruction.data === void 0) {
|
|
31
31
|
throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA, {
|
|
32
32
|
accountAddresses: instruction.accounts?.map((a) => a.address),
|
|
33
33
|
programAddress: instruction.programAddress
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/instruction.ts","../src/roles.ts"],"names":["AccountRole"],"mappings":";;;AAyBO,SAAS,uBAAA,CACZ,aACA,cAC0E,EAAA;AAC1E,EAAA,OAAO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GAAA,UAAA;AACA,EAAAA,YAAA,CAAA,YAAA,CAAA,UAAA,CAAA;AAAA,EAA0B,CAA1B,CAAA,GAAA,UAAA;AALQ,EAAAA,OAAAA,YAAAA;AAAA,CAAA,EAAA,WAAA,IAAA,EAAA;AAQZ,IAAM,iBAAoB,GAAA,CAAA;AAC1B,IAAM,mBAAsB,GAAA,CAAA;AAKrB,SAAS,yBAAyB,IAAgC,EAAA;AACrE,EAAA,OAAO,OAAO,EAAC;AACnB;AAKO,SAAS,wBAAwB,IAAgC,EAAA;AACpE,EAAA,OAAO,OAAO,EAAC;AACnB;AAEO,SAAS,aAAa,IAAsF,EAAA;AAC/G,EAAA,OAAO,IAAQ,IAAA,CAAA;AACnB;AAEO,SAAS,eAAe,IAA+E,EAAA;AAC1G,EAAA,OAAA,CAAQ,OAAO,mBAAyB,MAAA,CAAA;AAC5C;AAYO,SAAS,UAAA,CAAW,OAAoB,KAAiC,EAAA;AAC5E,EAAA,OAAO,KAAQ,GAAA,KAAA;AACnB;AAKO,SAAS,oBAAoB,IAAgC,EAAA;AAChE,EAAA,OAAO,IAAO,GAAA,iBAAA;AAClB;AAKO,SAAS,sBAAsB,IAAgC,EAAA;AAClE,EAAA,OAAO,IAAO,GAAA,mBAAA;AAClB","file":"index.native.mjs","sourcesContent":["import { Address } from '@solana/addresses';\nimport { ReadonlyUint8Array } from '@solana/codecs-core';\nimport {\n SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS,\n SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA,\n SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH,\n SolanaError,\n} from '@solana/errors';\n\nimport { IAccountLookupMeta, IAccountMeta } from './accounts';\n\nexport interface IInstruction<\n TProgramAddress extends string = string,\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n> {\n readonly accounts?: TAccounts;\n readonly data?: ReadonlyUint8Array;\n readonly programAddress: Address<TProgramAddress>;\n}\n\nexport interface IInstructionWithAccounts<TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[]>\n extends IInstruction {\n readonly accounts: TAccounts;\n}\n\nexport function isInstructionForProgram<TProgramAddress extends string, TInstruction extends IInstruction>(\n instruction: TInstruction,\n programAddress: Address<TProgramAddress>,\n): instruction is TInstruction & { programAddress: Address<TProgramAddress> } {\n return instruction.programAddress === programAddress;\n}\n\nexport function assertIsInstructionForProgram<TProgramAddress extends string, TInstruction extends IInstruction>(\n instruction: TInstruction,\n programAddress: Address<TProgramAddress>,\n): asserts instruction is TInstruction & { programAddress: Address<TProgramAddress> } {\n if (instruction.programAddress !== programAddress) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH, {\n actualProgramAddress: instruction.programAddress,\n expectedProgramAddress: programAddress,\n });\n }\n}\n\nexport function isInstructionWithAccounts<\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): instruction is IInstructionWithAccounts<TAccounts> & TInstruction {\n return instruction.accounts !== undefined;\n}\n\nexport function assertIsInstructionWithAccounts<\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): asserts instruction is IInstructionWithAccounts<TAccounts> & TInstruction {\n if (instruction.accounts === undefined) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS, {\n data: instruction.data,\n programAddress: instruction.programAddress,\n });\n }\n}\n\nexport interface IInstructionWithData<TData extends ReadonlyUint8Array> extends IInstruction {\n readonly data: TData;\n}\n\nexport function isInstructionWithData<\n TData extends ReadonlyUint8Array = ReadonlyUint8Array,\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): instruction is IInstructionWithData<TData> & TInstruction {\n return instruction.data !== undefined;\n}\n\nexport function assertIsInstructionWithData<\n TData extends ReadonlyUint8Array = ReadonlyUint8Array,\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): asserts instruction is IInstructionWithData<TData> & TInstruction {\n if (instruction.data === undefined) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA, {\n accountAddresses: instruction.accounts?.map(a => a.address),\n programAddress: instruction.programAddress,\n });\n }\n}\n","/**\n * Quick primer on bitwise operations: https://stackoverflow.com/a/1436448/802047\n */\n\nexport enum AccountRole {\n // Bitflag guide: is signer ⌄⌄ is writable\n WRITABLE_SIGNER = /* 3 */ 0b11, // prettier-ignore\n READONLY_SIGNER = /* 2 */ 0b10, // prettier-ignore\n WRITABLE = /* 1 */ 0b01, // prettier-ignore\n READONLY = /* 0 */ 0b00, // prettier-ignore\n}\n\nconst IS_SIGNER_BITMASK = 0b10;\nconst IS_WRITABLE_BITMASK = 0b01;\n\nexport function downgradeRoleToNonSigner(role: AccountRole.READONLY_SIGNER): AccountRole.READONLY;\nexport function downgradeRoleToNonSigner(role: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE;\nexport function downgradeRoleToNonSigner(role: AccountRole): AccountRole;\nexport function downgradeRoleToNonSigner(role: AccountRole): AccountRole {\n return role & ~IS_SIGNER_BITMASK;\n}\n\nexport function downgradeRoleToReadonly(role: AccountRole.WRITABLE): AccountRole.READONLY;\nexport function downgradeRoleToReadonly(role: AccountRole.WRITABLE_SIGNER): AccountRole.READONLY_SIGNER;\nexport function downgradeRoleToReadonly(role: AccountRole): AccountRole;\nexport function downgradeRoleToReadonly(role: AccountRole): AccountRole {\n return role & ~IS_WRITABLE_BITMASK;\n}\n\nexport function isSignerRole(role: AccountRole): role is AccountRole.READONLY_SIGNER | AccountRole.WRITABLE_SIGNER {\n return role >= AccountRole.READONLY_SIGNER;\n}\n\nexport function isWritableRole(role: AccountRole): role is AccountRole.WRITABLE | AccountRole.WRITABLE_SIGNER {\n return (role & IS_WRITABLE_BITMASK) !== 0;\n}\n\nexport function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.WRITABLE_SIGNER, roleB: AccountRole): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.READONLY_SIGNER): AccountRole.READONLY_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole): AccountRole.READONLY_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole): AccountRole.WRITABLE; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY, roleB: AccountRole.READONLY): AccountRole.READONLY; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole): AccountRole; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole): AccountRole {\n return roleA | roleB;\n}\n\nexport function upgradeRoleToSigner(role: AccountRole.READONLY): AccountRole.READONLY_SIGNER;\nexport function upgradeRoleToSigner(role: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER;\nexport function upgradeRoleToSigner(role: AccountRole): AccountRole;\nexport function upgradeRoleToSigner(role: AccountRole): AccountRole {\n return role | IS_SIGNER_BITMASK;\n}\n\nexport function upgradeRoleToWritable(role: AccountRole.READONLY): AccountRole.WRITABLE;\nexport function upgradeRoleToWritable(role: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER;\nexport function upgradeRoleToWritable(role: AccountRole): AccountRole;\nexport function upgradeRoleToWritable(role: AccountRole): AccountRole {\n return role | IS_WRITABLE_BITMASK;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/instruction.ts","../src/roles.ts"],"names":["AccountRole"],"mappings":";;;AA8CO,SAAS,uBAAA,CACZ,aACA,cAC0E,EAAA;AAC1E,EAAA,OAAO,YAAY,cAAmB,KAAA,cAAA;AAC1C;AAEO,SAAS,6BAAA,CACZ,aACA,cACkF,EAAA;AAClF,EAAI,IAAA,WAAA,CAAY,mBAAmB,cAAgB,EAAA;AAC/C,IAAM,MAAA,IAAI,YAAY,8CAAgD,EAAA;AAAA,MAClE,sBAAsB,WAAY,CAAA,cAAA;AAAA,MAClC,sBAAwB,EAAA;AAAA,KAC3B,CAAA;AAAA;AAET;AAEO,SAAS,0BAGd,WAA8F,EAAA;AAC5F,EAAA,OAAO,YAAY,QAAa,KAAA,MAAA;AACpC;AAEO,SAAS,gCAGd,WAAsG,EAAA;AACpG,EAAI,IAAA,WAAA,CAAY,aAAa,MAAW,EAAA;AACpC,IAAM,MAAA,IAAI,YAAY,oDAAsD,EAAA;AAAA,MACxE,MAAM,WAAY,CAAA,IAAA;AAAA,MAClB,gBAAgB,WAAY,CAAA;AAAA,KAC/B,CAAA;AAAA;AAET;AA4BO,SAAS,sBAGd,WAAsF,EAAA;AACpF,EAAA,OAAO,YAAY,IAAS,KAAA,MAAA;AAChC;AAEO,SAAS,4BAGd,WAA8F,EAAA;AAC5F,EAAI,IAAA,WAAA,CAAY,SAAS,MAAW,EAAA;AAChC,IAAM,MAAA,IAAI,YAAY,gDAAkD,EAAA;AAAA,MACpE,kBAAkB,WAAY,CAAA,QAAA,EAAU,GAAI,CAAA,CAAA,CAAA,KAAK,EAAE,OAAO,CAAA;AAAA,MAC1D,gBAAgB,WAAY,CAAA;AAAA,KAC/B,CAAA;AAAA;AAET;;;ACjHY,IAAA,WAAA,qBAAAA,YAAL,KAAA;AAEH,EAAAA,YAAA,CAAA,YAAA,CAAA,iBAAA,CAAA;AAAA,EAA0B,CAA1B,CAAA,GAAA,iBAAA;AACA,EAAAA,YAAA,CAAA,YAAA,CAAA,iBAAA,CAAA;AAAA,EAA0B,CAA1B,CAAA,GAAA,iBAAA;AACA,EAAAA,YAAA,CAAA,YAAA,CAAA,UAAA,CAAA;AAAA,EAA0B,CAA1B,CAAA,GAAA,UAAA;AACA,EAAAA,YAAA,CAAA,YAAA,CAAA,UAAA,CAAA;AAAA,EAA0B,CAA1B,CAAA,GAAA,UAAA;AALQ,EAAAA,OAAAA,YAAAA;AAAA,CAAA,EAAA,WAAA,IAAA,EAAA;AASZ,IAAM,iBAAoB,GAAA,CAAA;AAC1B,IAAM,mBAAsB,GAAA,CAAA;AAQrB,SAAS,yBAAyB,IAAgC,EAAA;AACrE,EAAA,OAAO,OAAO,EAAC;AACnB;AAQO,SAAS,wBAAwB,IAAgC,EAAA;AACpE,EAAA,OAAO,OAAO,EAAC;AACnB;AAMO,SAAS,aAAa,IAAsF,EAAA;AAC/G,EAAA,OAAO,IAAQ,IAAA,CAAA;AACnB;AAMO,SAAS,eAAe,IAA+E,EAAA;AAC1G,EAAA,OAAA,CAAQ,OAAO,mBAAyB,MAAA,CAAA;AAC5C;AAsBO,SAAS,UAAA,CAAW,OAAoB,KAAiC,EAAA;AAC5E,EAAA,OAAO,KAAQ,GAAA,KAAA;AACnB;AAQO,SAAS,oBAAoB,IAAgC,EAAA;AAChE,EAAA,OAAO,IAAO,GAAA,iBAAA;AAClB;AAQO,SAAS,sBAAsB,IAAgC,EAAA;AAClE,EAAA,OAAO,IAAO,GAAA,mBAAA;AAClB","file":"index.native.mjs","sourcesContent":["import { Address } from '@solana/addresses';\nimport { ReadonlyUint8Array } from '@solana/codecs-core';\nimport {\n SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS,\n SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA,\n SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH,\n SolanaError,\n} from '@solana/errors';\n\nimport { IAccountLookupMeta, IAccountMeta } from './accounts';\n\n/**\n * An instruction destined for a given program.\n *\n * @example\n * ```ts\n * type StakeProgramInstruction = IInstruction<'StakeConfig11111111111111111111111111111111'>;\n * ```\n */\nexport interface IInstruction<\n TProgramAddress extends string = string,\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n> {\n readonly accounts?: TAccounts;\n readonly data?: ReadonlyUint8Array;\n readonly programAddress: Address<TProgramAddress>;\n}\n\n/**\n * An instruction that loads certain accounts.\n *\n * @example\n * ```ts\n * type InstructionWithTwoAccounts = IInstructionWithAccounts<\n * [\n * WritableAccount, // First account\n * RentSysvar, // Second account\n * ]\n * >;\n * ```\n */\nexport interface IInstructionWithAccounts<TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[]>\n extends IInstruction {\n readonly accounts: TAccounts;\n}\n\nexport function isInstructionForProgram<TProgramAddress extends string, TInstruction extends IInstruction>(\n instruction: TInstruction,\n programAddress: Address<TProgramAddress>,\n): instruction is TInstruction & { programAddress: Address<TProgramAddress> } {\n return instruction.programAddress === programAddress;\n}\n\nexport function assertIsInstructionForProgram<TProgramAddress extends string, TInstruction extends IInstruction>(\n instruction: TInstruction,\n programAddress: Address<TProgramAddress>,\n): asserts instruction is TInstruction & { programAddress: Address<TProgramAddress> } {\n if (instruction.programAddress !== programAddress) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH, {\n actualProgramAddress: instruction.programAddress,\n expectedProgramAddress: programAddress,\n });\n }\n}\n\nexport function isInstructionWithAccounts<\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): instruction is IInstructionWithAccounts<TAccounts> & TInstruction {\n return instruction.accounts !== undefined;\n}\n\nexport function assertIsInstructionWithAccounts<\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): asserts instruction is IInstructionWithAccounts<TAccounts> & TInstruction {\n if (instruction.accounts === undefined) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS, {\n data: instruction.data,\n programAddress: instruction.programAddress,\n });\n }\n}\n\n/**\n * An instruction whose data conforms to a certain type.\n *\n * This is most useful when you have a branded `Uint8Array` that represents a particular\n * instruction's data.\n *\n * @example A type for the \\`AdvanceNonce\\` instruction of the System program\n * ```ts\n * type AdvanceNonceAccountInstruction<\n * TNonceAccountAddress extends string = string,\n * TNonceAuthorityAddress extends string = string,\n * > = IInstruction<'11111111111111111111111111111111'> &\n * IInstructionWithAccounts<\n * [\n * WritableAccount<TNonceAccountAddress>,\n * ReadonlyAccount<'SysvarRecentB1ockHashes11111111111111111111'>,\n * ReadonlySignerAccount<TNonceAuthorityAddress>,\n * ]\n * > &\n * IInstructionWithData<AdvanceNonceAccountInstructionData>;\n * ```\n */\nexport interface IInstructionWithData<TData extends ReadonlyUint8Array> extends IInstruction {\n readonly data: TData;\n}\n\nexport function isInstructionWithData<\n TData extends ReadonlyUint8Array = ReadonlyUint8Array,\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): instruction is IInstructionWithData<TData> & TInstruction {\n return instruction.data !== undefined;\n}\n\nexport function assertIsInstructionWithData<\n TData extends ReadonlyUint8Array = ReadonlyUint8Array,\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): asserts instruction is IInstructionWithData<TData> & TInstruction {\n if (instruction.data === undefined) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA, {\n accountAddresses: instruction.accounts?.map(a => a.address),\n programAddress: instruction.programAddress,\n });\n }\n}\n","/**\n * Describes the purpose for which an account participates in a transaction.\n *\n * Every account that participates in a transaction can be read from, but only ones that you mark as\n * writable may be written to, and only ones that you indicate must sign the transaction will gain\n * the privileges associated with signers at runtime.\n *\n * | | `isSigner` | `isWritable` |\n * | ----------------------------- | ---------- | ------------ |\n * | `AccountRole.READONLY` | ❌ | ❌ |\n * | `AccountRole.WRITABLE` | ❌ | ✅ |\n * | `AccountRole.READONLY_SIGNER` | ✅ | ❌ |\n * | `AccountRole.WRITABLE_SIGNER` | ✅ | ✅ |\n */\nexport enum AccountRole {\n // Bitflag guide: is signer ⌄⌄ is writable\n WRITABLE_SIGNER = /* 3 */ 0b11, // prettier-ignore\n READONLY_SIGNER = /* 2 */ 0b10, // prettier-ignore\n WRITABLE = /* 1 */ 0b01, // prettier-ignore\n READONLY = /* 0 */ 0b00, // prettier-ignore\n}\n\n// Quick primer on bitwise operations: https://stackoverflow.com/a/1436448/802047\nconst IS_SIGNER_BITMASK = 0b10;\nconst IS_WRITABLE_BITMASK = 0b01;\n\n/**\n * @returns An {@link AccountRole} representing the non-signer variant of the supplied role.\n */\nexport function downgradeRoleToNonSigner(role: AccountRole.READONLY_SIGNER): AccountRole.READONLY;\nexport function downgradeRoleToNonSigner(role: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE;\nexport function downgradeRoleToNonSigner(role: AccountRole): AccountRole;\nexport function downgradeRoleToNonSigner(role: AccountRole): AccountRole {\n return role & ~IS_SIGNER_BITMASK;\n}\n\n/**\n * @returns An {@link AccountRole} representing the read-only variant of the supplied role.\n */\nexport function downgradeRoleToReadonly(role: AccountRole.WRITABLE): AccountRole.READONLY;\nexport function downgradeRoleToReadonly(role: AccountRole.WRITABLE_SIGNER): AccountRole.READONLY_SIGNER;\nexport function downgradeRoleToReadonly(role: AccountRole): AccountRole;\nexport function downgradeRoleToReadonly(role: AccountRole): AccountRole {\n return role & ~IS_WRITABLE_BITMASK;\n}\n\n/**\n * Returns `true` if the {@link AccountRole} given represents that of a signer. Also refines the\n * TypeScript type of the supplied role.\n */\nexport function isSignerRole(role: AccountRole): role is AccountRole.READONLY_SIGNER | AccountRole.WRITABLE_SIGNER {\n return role >= AccountRole.READONLY_SIGNER;\n}\n\n/**\n * Returns `true` if the {@link AccountRole} given represents that of a writable account. Also\n * refines the TypeScript type of the supplied role.\n */\nexport function isWritableRole(role: AccountRole): role is AccountRole.WRITABLE | AccountRole.WRITABLE_SIGNER {\n return (role & IS_WRITABLE_BITMASK) !== 0;\n}\n\n/**\n * Given two {@link AccountRole | AccountRoles}, will return the {@link AccountRole} that grants the\n * highest privileges of both.\n *\n * @example\n * ```ts\n * // Returns `AccountRole.WRITABLE_SIGNER`\n * mergeRoles(AccountRole.READONLY_SIGNER, AccountRole.WRITABLE);\n * ```\n */\nexport function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.WRITABLE_SIGNER, roleB: AccountRole): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.READONLY_SIGNER): AccountRole.READONLY_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole): AccountRole.READONLY_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole): AccountRole.WRITABLE; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY, roleB: AccountRole.READONLY): AccountRole.READONLY; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole): AccountRole; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole): AccountRole {\n return roleA | roleB;\n}\n\n/**\n * @returns An {@link AccountRole} representing the signer variant of the supplied role.\n */\nexport function upgradeRoleToSigner(role: AccountRole.READONLY): AccountRole.READONLY_SIGNER;\nexport function upgradeRoleToSigner(role: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER;\nexport function upgradeRoleToSigner(role: AccountRole): AccountRole;\nexport function upgradeRoleToSigner(role: AccountRole): AccountRole {\n return role | IS_SIGNER_BITMASK;\n}\n\n/**\n * @returns An {@link AccountRole} representing the writable variant of the supplied role.\n */\nexport function upgradeRoleToWritable(role: AccountRole.READONLY): AccountRole.WRITABLE;\nexport function upgradeRoleToWritable(role: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER;\nexport function upgradeRoleToWritable(role: AccountRole): AccountRole;\nexport function upgradeRoleToWritable(role: AccountRole): AccountRole {\n return role | IS_WRITABLE_BITMASK;\n}\n"]}
|
package/dist/index.node.cjs
CHANGED
|
@@ -15,10 +15,10 @@ function assertIsInstructionForProgram(instruction, programAddress) {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
function isInstructionWithAccounts(instruction) {
|
|
18
|
-
return instruction.accounts !==
|
|
18
|
+
return instruction.accounts !== void 0;
|
|
19
19
|
}
|
|
20
20
|
function assertIsInstructionWithAccounts(instruction) {
|
|
21
|
-
if (instruction.accounts ===
|
|
21
|
+
if (instruction.accounts === void 0) {
|
|
22
22
|
throw new errors.SolanaError(errors.SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS, {
|
|
23
23
|
data: instruction.data,
|
|
24
24
|
programAddress: instruction.programAddress
|
|
@@ -26,10 +26,10 @@ function assertIsInstructionWithAccounts(instruction) {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
function isInstructionWithData(instruction) {
|
|
29
|
-
return instruction.data !==
|
|
29
|
+
return instruction.data !== void 0;
|
|
30
30
|
}
|
|
31
31
|
function assertIsInstructionWithData(instruction) {
|
|
32
|
-
if (instruction.data ===
|
|
32
|
+
if (instruction.data === void 0) {
|
|
33
33
|
throw new errors.SolanaError(errors.SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA, {
|
|
34
34
|
accountAddresses: instruction.accounts?.map((a) => a.address),
|
|
35
35
|
programAddress: instruction.programAddress
|
package/dist/index.node.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/instruction.ts","../src/roles.ts"],"names":["SolanaError","SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH","SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS","SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA","AccountRole"],"mappings":";;;;;AAyBO,SAAS,uBAAA,CACZ,aACA,cAC0E,EAAA;AAC1E,EAAA,OAAO,YAAY,cAAmB,KAAA,cAAA;AAC1C;AAEO,SAAS,6BAAA,CACZ,aACA,cACkF,EAAA;AAClF,EAAI,IAAA,WAAA,CAAY,mBAAmB,cAAgB,EAAA;AAC/C,IAAM,MAAA,IAAIA,mBAAYC,qDAAgD,EAAA;AAAA,MAClE,sBAAsB,WAAY,CAAA,cAAA;AAAA,MAClC,sBAAwB,EAAA;AAAA,KAC3B,CAAA;AAAA;AAET;AAEO,SAAS,0BAGd,WAA8F,EAAA;AAC5F,EAAA,OAAO,YAAY,QAAa,KAAA,SAAA;AACpC;AAEO,SAAS,gCAGd,WAAsG,EAAA;AACpG,EAAI,IAAA,WAAA,CAAY,aAAa,SAAW,EAAA;AACpC,IAAM,MAAA,IAAID,mBAAYE,2DAAsD,EAAA;AAAA,MACxE,MAAM,WAAY,CAAA,IAAA;AAAA,MAClB,gBAAgB,WAAY,CAAA;AAAA,KAC/B,CAAA;AAAA;AAET;AAMO,SAAS,sBAGd,WAAsF,EAAA;A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AQ,GAAA,KAAA;AACnB;AAKO,SAAS,oBAAoB,IAAgC,EAAA;AAChE,EAAA,OAAO,IAAO,GAAA,iBAAA;AAClB;AAKO,SAAS,sBAAsB,IAAgC,EAAA;AAClE,EAAA,OAAO,IAAO,GAAA,mBAAA;AAClB","file":"index.node.cjs","sourcesContent":["import { Address } from '@solana/addresses';\nimport { ReadonlyUint8Array } from '@solana/codecs-core';\nimport {\n SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS,\n SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA,\n SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH,\n SolanaError,\n} from '@solana/errors';\n\nimport { IAccountLookupMeta, IAccountMeta } from './accounts';\n\nexport interface IInstruction<\n TProgramAddress extends string = string,\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n> {\n readonly accounts?: TAccounts;\n readonly data?: ReadonlyUint8Array;\n readonly programAddress: Address<TProgramAddress>;\n}\n\nexport interface IInstructionWithAccounts<TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[]>\n extends IInstruction {\n readonly accounts: TAccounts;\n}\n\nexport function isInstructionForProgram<TProgramAddress extends string, TInstruction extends IInstruction>(\n instruction: TInstruction,\n programAddress: Address<TProgramAddress>,\n): instruction is TInstruction & { programAddress: Address<TProgramAddress> } {\n return instruction.programAddress === programAddress;\n}\n\nexport function assertIsInstructionForProgram<TProgramAddress extends string, TInstruction extends IInstruction>(\n instruction: TInstruction,\n programAddress: Address<TProgramAddress>,\n): asserts instruction is TInstruction & { programAddress: Address<TProgramAddress> } {\n if (instruction.programAddress !== programAddress) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH, {\n actualProgramAddress: instruction.programAddress,\n expectedProgramAddress: programAddress,\n });\n }\n}\n\nexport function isInstructionWithAccounts<\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): instruction is IInstructionWithAccounts<TAccounts> & TInstruction {\n return instruction.accounts !== undefined;\n}\n\nexport function assertIsInstructionWithAccounts<\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): asserts instruction is IInstructionWithAccounts<TAccounts> & TInstruction {\n if (instruction.accounts === undefined) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS, {\n data: instruction.data,\n programAddress: instruction.programAddress,\n });\n }\n}\n\nexport interface IInstructionWithData<TData extends ReadonlyUint8Array> extends IInstruction {\n readonly data: TData;\n}\n\nexport function isInstructionWithData<\n TData extends ReadonlyUint8Array = ReadonlyUint8Array,\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): instruction is IInstructionWithData<TData> & TInstruction {\n return instruction.data !== undefined;\n}\n\nexport function assertIsInstructionWithData<\n TData extends ReadonlyUint8Array = ReadonlyUint8Array,\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): asserts instruction is IInstructionWithData<TData> & TInstruction {\n if (instruction.data === undefined) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA, {\n accountAddresses: instruction.accounts?.map(a => a.address),\n programAddress: instruction.programAddress,\n });\n }\n}\n","/**\n * Quick primer on bitwise operations: https://stackoverflow.com/a/1436448/802047\n */\n\nexport enum AccountRole {\n // Bitflag guide: is signer ⌄⌄ is writable\n WRITABLE_SIGNER = /* 3 */ 0b11, // prettier-ignore\n READONLY_SIGNER = /* 2 */ 0b10, // prettier-ignore\n WRITABLE = /* 1 */ 0b01, // prettier-ignore\n READONLY = /* 0 */ 0b00, // prettier-ignore\n}\n\nconst IS_SIGNER_BITMASK = 0b10;\nconst IS_WRITABLE_BITMASK = 0b01;\n\nexport function downgradeRoleToNonSigner(role: AccountRole.READONLY_SIGNER): AccountRole.READONLY;\nexport function downgradeRoleToNonSigner(role: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE;\nexport function downgradeRoleToNonSigner(role: AccountRole): AccountRole;\nexport function downgradeRoleToNonSigner(role: AccountRole): AccountRole {\n return role & ~IS_SIGNER_BITMASK;\n}\n\nexport function downgradeRoleToReadonly(role: AccountRole.WRITABLE): AccountRole.READONLY;\nexport function downgradeRoleToReadonly(role: AccountRole.WRITABLE_SIGNER): AccountRole.READONLY_SIGNER;\nexport function downgradeRoleToReadonly(role: AccountRole): AccountRole;\nexport function downgradeRoleToReadonly(role: AccountRole): AccountRole {\n return role & ~IS_WRITABLE_BITMASK;\n}\n\nexport function isSignerRole(role: AccountRole): role is AccountRole.READONLY_SIGNER | AccountRole.WRITABLE_SIGNER {\n return role >= AccountRole.READONLY_SIGNER;\n}\n\nexport function isWritableRole(role: AccountRole): role is AccountRole.WRITABLE | AccountRole.WRITABLE_SIGNER {\n return (role & IS_WRITABLE_BITMASK) !== 0;\n}\n\nexport function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.WRITABLE_SIGNER, roleB: AccountRole): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.READONLY_SIGNER): AccountRole.READONLY_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole): AccountRole.READONLY_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole): AccountRole.WRITABLE; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY, roleB: AccountRole.READONLY): AccountRole.READONLY; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole): AccountRole; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole): AccountRole {\n return roleA | roleB;\n}\n\nexport function upgradeRoleToSigner(role: AccountRole.READONLY): AccountRole.READONLY_SIGNER;\nexport function upgradeRoleToSigner(role: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER;\nexport function upgradeRoleToSigner(role: AccountRole): AccountRole;\nexport function upgradeRoleToSigner(role: AccountRole): AccountRole {\n return role | IS_SIGNER_BITMASK;\n}\n\nexport function upgradeRoleToWritable(role: AccountRole.READONLY): AccountRole.WRITABLE;\nexport function upgradeRoleToWritable(role: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER;\nexport function upgradeRoleToWritable(role: AccountRole): AccountRole;\nexport function upgradeRoleToWritable(role: AccountRole): AccountRole {\n return role | IS_WRITABLE_BITMASK;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/instruction.ts","../src/roles.ts"],"names":["SolanaError","SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH","SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS","SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA","AccountRole"],"mappings":";;;;;AA8CO,SAAS,uBAAA,CACZ,aACA,cAC0E,EAAA;AAC1E,EAAA,OAAO,YAAY,cAAmB,KAAA,cAAA;AAC1C;AAEO,SAAS,6BAAA,CACZ,aACA,cACkF,EAAA;AAClF,EAAI,IAAA,WAAA,CAAY,mBAAmB,cAAgB,EAAA;AAC/C,IAAM,MAAA,IAAIA,mBAAYC,qDAAgD,EAA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AASZ,IAAM,iBAAoB,GAAA,CAAA;AAC1B,IAAM,mBAAsB,GAAA,CAAA;AAQrB,SAAS,yBAAyB,IAAgC,EAAA;AACrE,EAAA,OAAO,OAAO,EAAC;AACnB;AAQO,SAAS,wBAAwB,IAAgC,EAAA;AACpE,EAAA,OAAO,OAAO,EAAC;AACnB;AAMO,SAAS,aAAa,IAAsF,EAAA;AAC/G,EAAA,OAAO,IAAQ,IAAA,CAAA;AACnB;AAMO,SAAS,eAAe,IAA+E,EAAA;AAC1G,EAAA,OAAA,CAAQ,OAAO,mBAAyB,MAAA,CAAA;AAC5C;AAsBO,SAAS,UAAA,CAAW,OAAoB,KAAiC,EAAA;AAC5E,EAAA,OAAO,KAAQ,GAAA,KAAA;AACnB;AAQO,SAAS,oBAAoB,IAAgC,EAAA;AAChE,EAAA,OAAO,IAAO,GAAA,iBAAA;AAClB;AAQO,SAAS,sBAAsB,IAAgC,EAAA;AAClE,EAAA,OAAO,IAAO,GAAA,mBAAA;AAClB","file":"index.node.cjs","sourcesContent":["import { Address } from '@solana/addresses';\nimport { ReadonlyUint8Array } from '@solana/codecs-core';\nimport {\n SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS,\n SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA,\n SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH,\n SolanaError,\n} from '@solana/errors';\n\nimport { IAccountLookupMeta, IAccountMeta } from './accounts';\n\n/**\n * An instruction destined for a given program.\n *\n * @example\n * ```ts\n * type StakeProgramInstruction = IInstruction<'StakeConfig11111111111111111111111111111111'>;\n * ```\n */\nexport interface IInstruction<\n TProgramAddress extends string = string,\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n> {\n readonly accounts?: TAccounts;\n readonly data?: ReadonlyUint8Array;\n readonly programAddress: Address<TProgramAddress>;\n}\n\n/**\n * An instruction that loads certain accounts.\n *\n * @example\n * ```ts\n * type InstructionWithTwoAccounts = IInstructionWithAccounts<\n * [\n * WritableAccount, // First account\n * RentSysvar, // Second account\n * ]\n * >;\n * ```\n */\nexport interface IInstructionWithAccounts<TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[]>\n extends IInstruction {\n readonly accounts: TAccounts;\n}\n\nexport function isInstructionForProgram<TProgramAddress extends string, TInstruction extends IInstruction>(\n instruction: TInstruction,\n programAddress: Address<TProgramAddress>,\n): instruction is TInstruction & { programAddress: Address<TProgramAddress> } {\n return instruction.programAddress === programAddress;\n}\n\nexport function assertIsInstructionForProgram<TProgramAddress extends string, TInstruction extends IInstruction>(\n instruction: TInstruction,\n programAddress: Address<TProgramAddress>,\n): asserts instruction is TInstruction & { programAddress: Address<TProgramAddress> } {\n if (instruction.programAddress !== programAddress) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH, {\n actualProgramAddress: instruction.programAddress,\n expectedProgramAddress: programAddress,\n });\n }\n}\n\nexport function isInstructionWithAccounts<\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): instruction is IInstructionWithAccounts<TAccounts> & TInstruction {\n return instruction.accounts !== undefined;\n}\n\nexport function assertIsInstructionWithAccounts<\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): asserts instruction is IInstructionWithAccounts<TAccounts> & TInstruction {\n if (instruction.accounts === undefined) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS, {\n data: instruction.data,\n programAddress: instruction.programAddress,\n });\n }\n}\n\n/**\n * An instruction whose data conforms to a certain type.\n *\n * This is most useful when you have a branded `Uint8Array` that represents a particular\n * instruction's data.\n *\n * @example A type for the \\`AdvanceNonce\\` instruction of the System program\n * ```ts\n * type AdvanceNonceAccountInstruction<\n * TNonceAccountAddress extends string = string,\n * TNonceAuthorityAddress extends string = string,\n * > = IInstruction<'11111111111111111111111111111111'> &\n * IInstructionWithAccounts<\n * [\n * WritableAccount<TNonceAccountAddress>,\n * ReadonlyAccount<'SysvarRecentB1ockHashes11111111111111111111'>,\n * ReadonlySignerAccount<TNonceAuthorityAddress>,\n * ]\n * > &\n * IInstructionWithData<AdvanceNonceAccountInstructionData>;\n * ```\n */\nexport interface IInstructionWithData<TData extends ReadonlyUint8Array> extends IInstruction {\n readonly data: TData;\n}\n\nexport function isInstructionWithData<\n TData extends ReadonlyUint8Array = ReadonlyUint8Array,\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): instruction is IInstructionWithData<TData> & TInstruction {\n return instruction.data !== undefined;\n}\n\nexport function assertIsInstructionWithData<\n TData extends ReadonlyUint8Array = ReadonlyUint8Array,\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): asserts instruction is IInstructionWithData<TData> & TInstruction {\n if (instruction.data === undefined) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA, {\n accountAddresses: instruction.accounts?.map(a => a.address),\n programAddress: instruction.programAddress,\n });\n }\n}\n","/**\n * Describes the purpose for which an account participates in a transaction.\n *\n * Every account that participates in a transaction can be read from, but only ones that you mark as\n * writable may be written to, and only ones that you indicate must sign the transaction will gain\n * the privileges associated with signers at runtime.\n *\n * | | `isSigner` | `isWritable` |\n * | ----------------------------- | ---------- | ------------ |\n * | `AccountRole.READONLY` | ❌ | ❌ |\n * | `AccountRole.WRITABLE` | ❌ | ✅ |\n * | `AccountRole.READONLY_SIGNER` | ✅ | ❌ |\n * | `AccountRole.WRITABLE_SIGNER` | ✅ | ✅ |\n */\nexport enum AccountRole {\n // Bitflag guide: is signer ⌄⌄ is writable\n WRITABLE_SIGNER = /* 3 */ 0b11, // prettier-ignore\n READONLY_SIGNER = /* 2 */ 0b10, // prettier-ignore\n WRITABLE = /* 1 */ 0b01, // prettier-ignore\n READONLY = /* 0 */ 0b00, // prettier-ignore\n}\n\n// Quick primer on bitwise operations: https://stackoverflow.com/a/1436448/802047\nconst IS_SIGNER_BITMASK = 0b10;\nconst IS_WRITABLE_BITMASK = 0b01;\n\n/**\n * @returns An {@link AccountRole} representing the non-signer variant of the supplied role.\n */\nexport function downgradeRoleToNonSigner(role: AccountRole.READONLY_SIGNER): AccountRole.READONLY;\nexport function downgradeRoleToNonSigner(role: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE;\nexport function downgradeRoleToNonSigner(role: AccountRole): AccountRole;\nexport function downgradeRoleToNonSigner(role: AccountRole): AccountRole {\n return role & ~IS_SIGNER_BITMASK;\n}\n\n/**\n * @returns An {@link AccountRole} representing the read-only variant of the supplied role.\n */\nexport function downgradeRoleToReadonly(role: AccountRole.WRITABLE): AccountRole.READONLY;\nexport function downgradeRoleToReadonly(role: AccountRole.WRITABLE_SIGNER): AccountRole.READONLY_SIGNER;\nexport function downgradeRoleToReadonly(role: AccountRole): AccountRole;\nexport function downgradeRoleToReadonly(role: AccountRole): AccountRole {\n return role & ~IS_WRITABLE_BITMASK;\n}\n\n/**\n * Returns `true` if the {@link AccountRole} given represents that of a signer. Also refines the\n * TypeScript type of the supplied role.\n */\nexport function isSignerRole(role: AccountRole): role is AccountRole.READONLY_SIGNER | AccountRole.WRITABLE_SIGNER {\n return role >= AccountRole.READONLY_SIGNER;\n}\n\n/**\n * Returns `true` if the {@link AccountRole} given represents that of a writable account. Also\n * refines the TypeScript type of the supplied role.\n */\nexport function isWritableRole(role: AccountRole): role is AccountRole.WRITABLE | AccountRole.WRITABLE_SIGNER {\n return (role & IS_WRITABLE_BITMASK) !== 0;\n}\n\n/**\n * Given two {@link AccountRole | AccountRoles}, will return the {@link AccountRole} that grants the\n * highest privileges of both.\n *\n * @example\n * ```ts\n * // Returns `AccountRole.WRITABLE_SIGNER`\n * mergeRoles(AccountRole.READONLY_SIGNER, AccountRole.WRITABLE);\n * ```\n */\nexport function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.WRITABLE_SIGNER, roleB: AccountRole): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.READONLY_SIGNER): AccountRole.READONLY_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole): AccountRole.READONLY_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole): AccountRole.WRITABLE; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY, roleB: AccountRole.READONLY): AccountRole.READONLY; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole): AccountRole; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole): AccountRole {\n return roleA | roleB;\n}\n\n/**\n * @returns An {@link AccountRole} representing the signer variant of the supplied role.\n */\nexport function upgradeRoleToSigner(role: AccountRole.READONLY): AccountRole.READONLY_SIGNER;\nexport function upgradeRoleToSigner(role: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER;\nexport function upgradeRoleToSigner(role: AccountRole): AccountRole;\nexport function upgradeRoleToSigner(role: AccountRole): AccountRole {\n return role | IS_SIGNER_BITMASK;\n}\n\n/**\n * @returns An {@link AccountRole} representing the writable variant of the supplied role.\n */\nexport function upgradeRoleToWritable(role: AccountRole.READONLY): AccountRole.WRITABLE;\nexport function upgradeRoleToWritable(role: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER;\nexport function upgradeRoleToWritable(role: AccountRole): AccountRole;\nexport function upgradeRoleToWritable(role: AccountRole): AccountRole {\n return role | IS_WRITABLE_BITMASK;\n}\n"]}
|
package/dist/index.node.mjs
CHANGED
|
@@ -13,10 +13,10 @@ function assertIsInstructionForProgram(instruction, programAddress) {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
function isInstructionWithAccounts(instruction) {
|
|
16
|
-
return instruction.accounts !==
|
|
16
|
+
return instruction.accounts !== void 0;
|
|
17
17
|
}
|
|
18
18
|
function assertIsInstructionWithAccounts(instruction) {
|
|
19
|
-
if (instruction.accounts ===
|
|
19
|
+
if (instruction.accounts === void 0) {
|
|
20
20
|
throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS, {
|
|
21
21
|
data: instruction.data,
|
|
22
22
|
programAddress: instruction.programAddress
|
|
@@ -24,10 +24,10 @@ function assertIsInstructionWithAccounts(instruction) {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
function isInstructionWithData(instruction) {
|
|
27
|
-
return instruction.data !==
|
|
27
|
+
return instruction.data !== void 0;
|
|
28
28
|
}
|
|
29
29
|
function assertIsInstructionWithData(instruction) {
|
|
30
|
-
if (instruction.data ===
|
|
30
|
+
if (instruction.data === void 0) {
|
|
31
31
|
throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA, {
|
|
32
32
|
accountAddresses: instruction.accounts?.map((a) => a.address),
|
|
33
33
|
programAddress: instruction.programAddress
|
package/dist/index.node.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/instruction.ts","../src/roles.ts"],"names":["AccountRole"],"mappings":";;;AAyBO,SAAS,uBAAA,CACZ,aACA,cAC0E,EAAA;AAC1E,E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1B,CAAA,GAAA,UAAA;AACA,EAAAA,YAAA,CAAA,YAAA,CAAA,UAAA,CAAA;AAAA,EAA0B,CAA1B,CAAA,GAAA,UAAA;AALQ,EAAAA,OAAAA,YAAAA;AAAA,CAAA,EAAA,WAAA,IAAA,EAAA;AAQZ,IAAM,iBAAoB,GAAA,CAAA;AAC1B,IAAM,mBAAsB,GAAA,CAAA;AAKrB,SAAS,yBAAyB,IAAgC,EAAA;AACrE,EAAA,OAAO,OAAO,EAAC;AACnB;AAKO,SAAS,wBAAwB,IAAgC,EAAA;AACpE,EAAA,OAAO,OAAO,EAAC;AACnB;AAEO,SAAS,aAAa,IAAsF,EAAA;AAC/G,EAAA,OAAO,IAAQ,IAAA,CAAA;AACnB;AAEO,SAAS,eAAe,IAA+E,EAAA;AAC1G,EAAA,OAAA,CAAQ,OAAO,mBAAyB,MAAA,CAAA;AAC5C;AAYO,SAAS,UAAA,CAAW,OAAoB,KAAiC,EAAA;AAC5E,EAAA,OAAO,KAAQ,GAAA,KAAA;AACnB;AAKO,SAAS,oBAAoB,IAAgC,EAAA;AAChE,EAAA,OAAO,IAAO,GAAA,iBAAA;AAClB;AAKO,SAAS,sBAAsB,IAAgC,EAAA;AAClE,EAAA,OAAO,IAAO,GAAA,mBAAA;AAClB","file":"index.node.mjs","sourcesContent":["import { Address } from '@solana/addresses';\nimport { ReadonlyUint8Array } from '@solana/codecs-core';\nimport {\n SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS,\n SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA,\n SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH,\n SolanaError,\n} from '@solana/errors';\n\nimport { IAccountLookupMeta, IAccountMeta } from './accounts';\n\nexport interface IInstruction<\n TProgramAddress extends string = string,\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n> {\n readonly accounts?: TAccounts;\n readonly data?: ReadonlyUint8Array;\n readonly programAddress: Address<TProgramAddress>;\n}\n\nexport interface IInstructionWithAccounts<TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[]>\n extends IInstruction {\n readonly accounts: TAccounts;\n}\n\nexport function isInstructionForProgram<TProgramAddress extends string, TInstruction extends IInstruction>(\n instruction: TInstruction,\n programAddress: Address<TProgramAddress>,\n): instruction is TInstruction & { programAddress: Address<TProgramAddress> } {\n return instruction.programAddress === programAddress;\n}\n\nexport function assertIsInstructionForProgram<TProgramAddress extends string, TInstruction extends IInstruction>(\n instruction: TInstruction,\n programAddress: Address<TProgramAddress>,\n): asserts instruction is TInstruction & { programAddress: Address<TProgramAddress> } {\n if (instruction.programAddress !== programAddress) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH, {\n actualProgramAddress: instruction.programAddress,\n expectedProgramAddress: programAddress,\n });\n }\n}\n\nexport function isInstructionWithAccounts<\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): instruction is IInstructionWithAccounts<TAccounts> & TInstruction {\n return instruction.accounts !== undefined;\n}\n\nexport function assertIsInstructionWithAccounts<\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): asserts instruction is IInstructionWithAccounts<TAccounts> & TInstruction {\n if (instruction.accounts === undefined) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS, {\n data: instruction.data,\n programAddress: instruction.programAddress,\n });\n }\n}\n\nexport interface IInstructionWithData<TData extends ReadonlyUint8Array> extends IInstruction {\n readonly data: TData;\n}\n\nexport function isInstructionWithData<\n TData extends ReadonlyUint8Array = ReadonlyUint8Array,\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): instruction is IInstructionWithData<TData> & TInstruction {\n return instruction.data !== undefined;\n}\n\nexport function assertIsInstructionWithData<\n TData extends ReadonlyUint8Array = ReadonlyUint8Array,\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): asserts instruction is IInstructionWithData<TData> & TInstruction {\n if (instruction.data === undefined) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA, {\n accountAddresses: instruction.accounts?.map(a => a.address),\n programAddress: instruction.programAddress,\n });\n }\n}\n","/**\n * Quick primer on bitwise operations: https://stackoverflow.com/a/1436448/802047\n */\n\nexport enum AccountRole {\n // Bitflag guide: is signer ⌄⌄ is writable\n WRITABLE_SIGNER = /* 3 */ 0b11, // prettier-ignore\n READONLY_SIGNER = /* 2 */ 0b10, // prettier-ignore\n WRITABLE = /* 1 */ 0b01, // prettier-ignore\n READONLY = /* 0 */ 0b00, // prettier-ignore\n}\n\nconst IS_SIGNER_BITMASK = 0b10;\nconst IS_WRITABLE_BITMASK = 0b01;\n\nexport function downgradeRoleToNonSigner(role: AccountRole.READONLY_SIGNER): AccountRole.READONLY;\nexport function downgradeRoleToNonSigner(role: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE;\nexport function downgradeRoleToNonSigner(role: AccountRole): AccountRole;\nexport function downgradeRoleToNonSigner(role: AccountRole): AccountRole {\n return role & ~IS_SIGNER_BITMASK;\n}\n\nexport function downgradeRoleToReadonly(role: AccountRole.WRITABLE): AccountRole.READONLY;\nexport function downgradeRoleToReadonly(role: AccountRole.WRITABLE_SIGNER): AccountRole.READONLY_SIGNER;\nexport function downgradeRoleToReadonly(role: AccountRole): AccountRole;\nexport function downgradeRoleToReadonly(role: AccountRole): AccountRole {\n return role & ~IS_WRITABLE_BITMASK;\n}\n\nexport function isSignerRole(role: AccountRole): role is AccountRole.READONLY_SIGNER | AccountRole.WRITABLE_SIGNER {\n return role >= AccountRole.READONLY_SIGNER;\n}\n\nexport function isWritableRole(role: AccountRole): role is AccountRole.WRITABLE | AccountRole.WRITABLE_SIGNER {\n return (role & IS_WRITABLE_BITMASK) !== 0;\n}\n\nexport function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.WRITABLE_SIGNER, roleB: AccountRole): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.READONLY_SIGNER): AccountRole.READONLY_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole): AccountRole.READONLY_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole): AccountRole.WRITABLE; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY, roleB: AccountRole.READONLY): AccountRole.READONLY; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole): AccountRole; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole): AccountRole {\n return roleA | roleB;\n}\n\nexport function upgradeRoleToSigner(role: AccountRole.READONLY): AccountRole.READONLY_SIGNER;\nexport function upgradeRoleToSigner(role: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER;\nexport function upgradeRoleToSigner(role: AccountRole): AccountRole;\nexport function upgradeRoleToSigner(role: AccountRole): AccountRole {\n return role | IS_SIGNER_BITMASK;\n}\n\nexport function upgradeRoleToWritable(role: AccountRole.READONLY): AccountRole.WRITABLE;\nexport function upgradeRoleToWritable(role: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER;\nexport function upgradeRoleToWritable(role: AccountRole): AccountRole;\nexport function upgradeRoleToWritable(role: AccountRole): AccountRole {\n return role | IS_WRITABLE_BITMASK;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/instruction.ts","../src/roles.ts"],"names":["AccountRole"],"mappings":";;;AA8CO,SAAS,uBAAA,CACZ,aACA,cAC0E,EAAA;AAC1E,EAAA,OAAO,YAAY,cAAmB,KAAA,cAAA;AAC1C;AAEO,SAAS,6BAAA,CACZ,aACA,cACkF,EAAA;AAClF,EAAI,IAAA,WAAA,CAAY,mBAAmB,cAAgB,EAAA;AAC/C,IAAM,MAAA,IAAI,YAAY,8CAAgD,EAAA;AAAA,MAClE,sBAAsB,WAAY,CAAA,cAAA;AAAA,MAClC,sBAAwB,EAAA;AAAA,KAC3B,CAAA;AAAA;AAET;AAEO,SAAS,0BAGd,WAA8F,EAAA;AAC5F,EAAA,OAAO,YAAY,QAAa,KAAA,MAAA;AACpC;AAEO,SAAS,gCAGd,WAAsG,EAAA;AACpG,EAAI,IAAA,WAAA,CAAY,aAAa,MAAW,EAAA;AACpC,IAAM,MAAA,IAAI,YAAY,oDAAsD,EAAA;AAAA,MACxE,MAAM,WAAY,CAAA,IAAA;AAAA,MAClB,gBAAgB,WAAY,CAAA;AAAA,KAC/B,CAAA;AAAA;AAET;AA4BO,SAAS,sBAGd,WAAsF,EAAA;AACpF,EAAA,OAAO,YAAY,IAAS,KAAA,MAAA;AAChC;AAEO,SAAS,4BAGd,WAA8F,EAAA;AAC5F,EAAI,IAAA,WAAA,CAAY,SAAS,MAAW,EAAA;AAChC,IAAM,MAAA,IAAI,YAAY,gDAAkD,EAAA;AAAA,MACpE,kBAAkB,WAAY,CAAA,QAAA,EAAU,GAAI,CAAA,CAAA,CAAA,KAAK,EAAE,OAAO,CAAA;AAAA,MAC1D,gBAAgB,WAAY,CAAA;AAAA,KAC/B,CAAA;AAAA;AAET;;;ACjHY,IAAA,WAAA,qBAAAA,YAAL,KAAA;AAEH,EAAAA,YAAA,CAAA,YAAA,CAAA,iBAAA,CAAA;AAAA,EAA0B,CAA1B,CAAA,GAAA,iBAAA;AACA,EAAAA,YAAA,CAAA,YAAA,CAAA,iBAAA,CAAA;AAAA,EAA0B,CAA1B,CAAA,GAAA,iBAAA;AACA,EAAAA,YAAA,CAAA,YAAA,CAAA,UAAA,CAAA;AAAA,EAA0B,CAA1B,CAAA,GAAA,UAAA;AACA,EAAAA,YAAA,CAAA,YAAA,CAAA,UAAA,CAAA;AAAA,EAA0B,CAA1B,CAAA,GAAA,UAAA;AALQ,EAAAA,OAAAA,YAAAA;AAAA,CAAA,EAAA,WAAA,IAAA,EAAA;AASZ,IAAM,iBAAoB,GAAA,CAAA;AAC1B,IAAM,mBAAsB,GAAA,CAAA;AAQrB,SAAS,yBAAyB,IAAgC,EAAA;AACrE,EAAA,OAAO,OAAO,EAAC;AACnB;AAQO,SAAS,wBAAwB,IAAgC,EAAA;AACpE,EAAA,OAAO,OAAO,EAAC;AACnB;AAMO,SAAS,aAAa,IAAsF,EAAA;AAC/G,EAAA,OAAO,IAAQ,IAAA,CAAA;AACnB;AAMO,SAAS,eAAe,IAA+E,EAAA;AAC1G,EAAA,OAAA,CAAQ,OAAO,mBAAyB,MAAA,CAAA;AAC5C;AAsBO,SAAS,UAAA,CAAW,OAAoB,KAAiC,EAAA;AAC5E,EAAA,OAAO,KAAQ,GAAA,KAAA;AACnB;AAQO,SAAS,oBAAoB,IAAgC,EAAA;AAChE,EAAA,OAAO,IAAO,GAAA,iBAAA;AAClB;AAQO,SAAS,sBAAsB,IAAgC,EAAA;AAClE,EAAA,OAAO,IAAO,GAAA,mBAAA;AAClB","file":"index.node.mjs","sourcesContent":["import { Address } from '@solana/addresses';\nimport { ReadonlyUint8Array } from '@solana/codecs-core';\nimport {\n SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS,\n SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA,\n SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH,\n SolanaError,\n} from '@solana/errors';\n\nimport { IAccountLookupMeta, IAccountMeta } from './accounts';\n\n/**\n * An instruction destined for a given program.\n *\n * @example\n * ```ts\n * type StakeProgramInstruction = IInstruction<'StakeConfig11111111111111111111111111111111'>;\n * ```\n */\nexport interface IInstruction<\n TProgramAddress extends string = string,\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n> {\n readonly accounts?: TAccounts;\n readonly data?: ReadonlyUint8Array;\n readonly programAddress: Address<TProgramAddress>;\n}\n\n/**\n * An instruction that loads certain accounts.\n *\n * @example\n * ```ts\n * type InstructionWithTwoAccounts = IInstructionWithAccounts<\n * [\n * WritableAccount, // First account\n * RentSysvar, // Second account\n * ]\n * >;\n * ```\n */\nexport interface IInstructionWithAccounts<TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[]>\n extends IInstruction {\n readonly accounts: TAccounts;\n}\n\nexport function isInstructionForProgram<TProgramAddress extends string, TInstruction extends IInstruction>(\n instruction: TInstruction,\n programAddress: Address<TProgramAddress>,\n): instruction is TInstruction & { programAddress: Address<TProgramAddress> } {\n return instruction.programAddress === programAddress;\n}\n\nexport function assertIsInstructionForProgram<TProgramAddress extends string, TInstruction extends IInstruction>(\n instruction: TInstruction,\n programAddress: Address<TProgramAddress>,\n): asserts instruction is TInstruction & { programAddress: Address<TProgramAddress> } {\n if (instruction.programAddress !== programAddress) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH, {\n actualProgramAddress: instruction.programAddress,\n expectedProgramAddress: programAddress,\n });\n }\n}\n\nexport function isInstructionWithAccounts<\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): instruction is IInstructionWithAccounts<TAccounts> & TInstruction {\n return instruction.accounts !== undefined;\n}\n\nexport function assertIsInstructionWithAccounts<\n TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[],\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): asserts instruction is IInstructionWithAccounts<TAccounts> & TInstruction {\n if (instruction.accounts === undefined) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS, {\n data: instruction.data,\n programAddress: instruction.programAddress,\n });\n }\n}\n\n/**\n * An instruction whose data conforms to a certain type.\n *\n * This is most useful when you have a branded `Uint8Array` that represents a particular\n * instruction's data.\n *\n * @example A type for the \\`AdvanceNonce\\` instruction of the System program\n * ```ts\n * type AdvanceNonceAccountInstruction<\n * TNonceAccountAddress extends string = string,\n * TNonceAuthorityAddress extends string = string,\n * > = IInstruction<'11111111111111111111111111111111'> &\n * IInstructionWithAccounts<\n * [\n * WritableAccount<TNonceAccountAddress>,\n * ReadonlyAccount<'SysvarRecentB1ockHashes11111111111111111111'>,\n * ReadonlySignerAccount<TNonceAuthorityAddress>,\n * ]\n * > &\n * IInstructionWithData<AdvanceNonceAccountInstructionData>;\n * ```\n */\nexport interface IInstructionWithData<TData extends ReadonlyUint8Array> extends IInstruction {\n readonly data: TData;\n}\n\nexport function isInstructionWithData<\n TData extends ReadonlyUint8Array = ReadonlyUint8Array,\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): instruction is IInstructionWithData<TData> & TInstruction {\n return instruction.data !== undefined;\n}\n\nexport function assertIsInstructionWithData<\n TData extends ReadonlyUint8Array = ReadonlyUint8Array,\n TInstruction extends IInstruction = IInstruction,\n>(instruction: TInstruction): asserts instruction is IInstructionWithData<TData> & TInstruction {\n if (instruction.data === undefined) {\n throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA, {\n accountAddresses: instruction.accounts?.map(a => a.address),\n programAddress: instruction.programAddress,\n });\n }\n}\n","/**\n * Describes the purpose for which an account participates in a transaction.\n *\n * Every account that participates in a transaction can be read from, but only ones that you mark as\n * writable may be written to, and only ones that you indicate must sign the transaction will gain\n * the privileges associated with signers at runtime.\n *\n * | | `isSigner` | `isWritable` |\n * | ----------------------------- | ---------- | ------------ |\n * | `AccountRole.READONLY` | ❌ | ❌ |\n * | `AccountRole.WRITABLE` | ❌ | ✅ |\n * | `AccountRole.READONLY_SIGNER` | ✅ | ❌ |\n * | `AccountRole.WRITABLE_SIGNER` | ✅ | ✅ |\n */\nexport enum AccountRole {\n // Bitflag guide: is signer ⌄⌄ is writable\n WRITABLE_SIGNER = /* 3 */ 0b11, // prettier-ignore\n READONLY_SIGNER = /* 2 */ 0b10, // prettier-ignore\n WRITABLE = /* 1 */ 0b01, // prettier-ignore\n READONLY = /* 0 */ 0b00, // prettier-ignore\n}\n\n// Quick primer on bitwise operations: https://stackoverflow.com/a/1436448/802047\nconst IS_SIGNER_BITMASK = 0b10;\nconst IS_WRITABLE_BITMASK = 0b01;\n\n/**\n * @returns An {@link AccountRole} representing the non-signer variant of the supplied role.\n */\nexport function downgradeRoleToNonSigner(role: AccountRole.READONLY_SIGNER): AccountRole.READONLY;\nexport function downgradeRoleToNonSigner(role: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE;\nexport function downgradeRoleToNonSigner(role: AccountRole): AccountRole;\nexport function downgradeRoleToNonSigner(role: AccountRole): AccountRole {\n return role & ~IS_SIGNER_BITMASK;\n}\n\n/**\n * @returns An {@link AccountRole} representing the read-only variant of the supplied role.\n */\nexport function downgradeRoleToReadonly(role: AccountRole.WRITABLE): AccountRole.READONLY;\nexport function downgradeRoleToReadonly(role: AccountRole.WRITABLE_SIGNER): AccountRole.READONLY_SIGNER;\nexport function downgradeRoleToReadonly(role: AccountRole): AccountRole;\nexport function downgradeRoleToReadonly(role: AccountRole): AccountRole {\n return role & ~IS_WRITABLE_BITMASK;\n}\n\n/**\n * Returns `true` if the {@link AccountRole} given represents that of a signer. Also refines the\n * TypeScript type of the supplied role.\n */\nexport function isSignerRole(role: AccountRole): role is AccountRole.READONLY_SIGNER | AccountRole.WRITABLE_SIGNER {\n return role >= AccountRole.READONLY_SIGNER;\n}\n\n/**\n * Returns `true` if the {@link AccountRole} given represents that of a writable account. Also\n * refines the TypeScript type of the supplied role.\n */\nexport function isWritableRole(role: AccountRole): role is AccountRole.WRITABLE | AccountRole.WRITABLE_SIGNER {\n return (role & IS_WRITABLE_BITMASK) !== 0;\n}\n\n/**\n * Given two {@link AccountRole | AccountRoles}, will return the {@link AccountRole} that grants the\n * highest privileges of both.\n *\n * @example\n * ```ts\n * // Returns `AccountRole.WRITABLE_SIGNER`\n * mergeRoles(AccountRole.READONLY_SIGNER, AccountRole.WRITABLE);\n * ```\n */\nexport function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.WRITABLE_SIGNER, roleB: AccountRole): AccountRole.WRITABLE_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.READONLY_SIGNER): AccountRole.READONLY_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole): AccountRole.READONLY_SIGNER; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole): AccountRole.WRITABLE; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole.READONLY, roleB: AccountRole.READONLY): AccountRole.READONLY; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole): AccountRole; // prettier-ignore\nexport function mergeRoles(roleA: AccountRole, roleB: AccountRole): AccountRole {\n return roleA | roleB;\n}\n\n/**\n * @returns An {@link AccountRole} representing the signer variant of the supplied role.\n */\nexport function upgradeRoleToSigner(role: AccountRole.READONLY): AccountRole.READONLY_SIGNER;\nexport function upgradeRoleToSigner(role: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER;\nexport function upgradeRoleToSigner(role: AccountRole): AccountRole;\nexport function upgradeRoleToSigner(role: AccountRole): AccountRole {\n return role | IS_SIGNER_BITMASK;\n}\n\n/**\n * @returns An {@link AccountRole} representing the writable variant of the supplied role.\n */\nexport function upgradeRoleToWritable(role: AccountRole.READONLY): AccountRole.WRITABLE;\nexport function upgradeRoleToWritable(role: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER;\nexport function upgradeRoleToWritable(role: AccountRole): AccountRole;\nexport function upgradeRoleToWritable(role: AccountRole): AccountRole {\n return role | IS_WRITABLE_BITMASK;\n}\n"]}
|
package/dist/types/accounts.d.ts
CHANGED
|
@@ -1,30 +1,87 @@
|
|
|
1
1
|
import { Address } from '@solana/addresses';
|
|
2
2
|
import { AccountRole } from './roles';
|
|
3
|
+
/**
|
|
4
|
+
* Represents an account's address and metadata about its mutability and whether it must be a signer
|
|
5
|
+
* of the transaction.
|
|
6
|
+
*
|
|
7
|
+
* Typically, you will use one of its subtypes.
|
|
8
|
+
*
|
|
9
|
+
* | | `role` | `isSigner` | `isWritable` |
|
|
10
|
+
* | --------------------------------- | ----------------------------- | ---------- | ------------ |
|
|
11
|
+
* | `ReadonlyAccount<TAddress>` | `AccountRole.READONLY` | No | No |
|
|
12
|
+
* | `WritableAccount<TAddress>` | `AccountRole.WRITABLE` | No | Yes |
|
|
13
|
+
* | `ReadonlySignerAccount<TAddress>` | `AccountRole.READONLY_SIGNER` | Yes | No |
|
|
14
|
+
* | `WritableSignerAccount<TAddress>` | `AccountRole.WRITABLE_SIGNER` | Yes | Yes |
|
|
15
|
+
*
|
|
16
|
+
* @example A type for the Rent sysvar account
|
|
17
|
+
* ```ts
|
|
18
|
+
* type RentSysvar = ReadonlyAccount<'SysvarRent111111111111111111111111111111111'>;
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
3
21
|
export interface IAccountMeta<TAddress extends string = string> {
|
|
4
22
|
readonly address: Address<TAddress>;
|
|
5
23
|
readonly role: AccountRole;
|
|
6
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* @see {@link IAccountMeta}
|
|
27
|
+
*/
|
|
7
28
|
export type ReadonlyAccount<TAddress extends string = string> = IAccountMeta<TAddress> & {
|
|
8
29
|
readonly role: AccountRole.READONLY;
|
|
9
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* @see {@link IAccountMeta}
|
|
33
|
+
*/
|
|
10
34
|
export type WritableAccount<TAddress extends string = string> = IAccountMeta<TAddress> & {
|
|
11
35
|
role: AccountRole.WRITABLE;
|
|
12
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* @see {@link IAccountMeta}
|
|
39
|
+
*/
|
|
13
40
|
export type ReadonlySignerAccount<TAddress extends string = string> = IAccountMeta<TAddress> & {
|
|
14
41
|
role: AccountRole.READONLY_SIGNER;
|
|
15
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* @see {@link IAccountMeta}
|
|
45
|
+
*/
|
|
16
46
|
export type WritableSignerAccount<TAddress extends string = string> = IAccountMeta<TAddress> & {
|
|
17
47
|
role: AccountRole.WRITABLE_SIGNER;
|
|
18
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* Represents a lookup of the account's address in an address lookup table. It specifies which
|
|
51
|
+
* lookup table account in which to perform the lookup, the index of the desired account address in
|
|
52
|
+
* that table, and metadata about its mutability. Notably, account addresses obtained via lookups
|
|
53
|
+
* may not act as signers.
|
|
54
|
+
*
|
|
55
|
+
* Typically, you will use one of its subtypes.
|
|
56
|
+
*
|
|
57
|
+
* | | `role` | `isSigner` | `isWritable` |
|
|
58
|
+
* | ------------------------------------------------------ | ---------------------- | ---------- | ------------ |
|
|
59
|
+
* | `ReadonlyLookupAccount<TAddress, TLookupTableAddress>` | `AccountRole.READONLY` | No | No |
|
|
60
|
+
* | `WritableLookupAccount<TAddress, TLookupTableAddress>` | `AccountRole.WRITABLE` | No | Yes |
|
|
61
|
+
*
|
|
62
|
+
* @example A type for the Rent sysvar account that you looked up in a lookup table
|
|
63
|
+
* ```ts
|
|
64
|
+
* type RentSysvar = ReadonlyLookupAccount<
|
|
65
|
+
* 'SysvarRent111111111111111111111111111111111',
|
|
66
|
+
* 'MyLookupTable111111111111111111111111111111'
|
|
67
|
+
* >;
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
19
70
|
export interface IAccountLookupMeta<TAddress extends string = string, TLookupTableAddress extends string = string> {
|
|
20
71
|
readonly address: Address<TAddress>;
|
|
21
72
|
readonly addressIndex: number;
|
|
22
73
|
readonly lookupTableAddress: Address<TLookupTableAddress>;
|
|
23
74
|
readonly role: AccountRole.READONLY | AccountRole.WRITABLE;
|
|
24
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* @see {@link IAccountLookupMeta}
|
|
78
|
+
*/
|
|
25
79
|
export type ReadonlyAccountLookup<TAddress extends string = string, TLookupTableAddress extends string = string> = IAccountLookupMeta<TAddress, TLookupTableAddress> & {
|
|
26
80
|
readonly role: AccountRole.READONLY;
|
|
27
81
|
};
|
|
82
|
+
/**
|
|
83
|
+
* @see {@link IAccountLookupMeta}
|
|
84
|
+
*/
|
|
28
85
|
export type WritableAccountLookup<TAddress extends string = string, TLookupTableAddress extends string = string> = IAccountLookupMeta<TAddress, TLookupTableAddress> & {
|
|
29
86
|
readonly role: AccountRole.WRITABLE;
|
|
30
87
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../../src/accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MA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
|
1
|
+
/**
|
|
2
|
+
* This package contains types for creating transaction instructions. It can be used standalone, but it is also exported as part of Kit [`@solana/kit`](https://github.com/anza-xyz/kit/tree/main/packages/kit).
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
1
5
|
export * from './accounts';
|
|
2
6
|
export * from './instruction';
|
|
3
7
|
export * from './roles';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC"}
|
|
@@ -1,11 +1,32 @@
|
|
|
1
1
|
import { Address } from '@solana/addresses';
|
|
2
2
|
import { ReadonlyUint8Array } from '@solana/codecs-core';
|
|
3
3
|
import { IAccountLookupMeta, IAccountMeta } from './accounts';
|
|
4
|
+
/**
|
|
5
|
+
* An instruction destined for a given program.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* type StakeProgramInstruction = IInstruction<'StakeConfig11111111111111111111111111111111'>;
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
4
12
|
export interface IInstruction<TProgramAddress extends string = string, TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[]> {
|
|
5
13
|
readonly accounts?: TAccounts;
|
|
6
14
|
readonly data?: ReadonlyUint8Array;
|
|
7
15
|
readonly programAddress: Address<TProgramAddress>;
|
|
8
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* An instruction that loads certain accounts.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* type InstructionWithTwoAccounts = IInstructionWithAccounts<
|
|
23
|
+
* [
|
|
24
|
+
* WritableAccount, // First account
|
|
25
|
+
* RentSysvar, // Second account
|
|
26
|
+
* ]
|
|
27
|
+
* >;
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
9
30
|
export interface IInstructionWithAccounts<TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[]> extends IInstruction {
|
|
10
31
|
readonly accounts: TAccounts;
|
|
11
32
|
}
|
|
@@ -17,6 +38,28 @@ export declare function assertIsInstructionForProgram<TProgramAddress extends st
|
|
|
17
38
|
};
|
|
18
39
|
export declare function isInstructionWithAccounts<TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[], TInstruction extends IInstruction = IInstruction>(instruction: TInstruction): instruction is IInstructionWithAccounts<TAccounts> & TInstruction;
|
|
19
40
|
export declare function assertIsInstructionWithAccounts<TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[], TInstruction extends IInstruction = IInstruction>(instruction: TInstruction): asserts instruction is IInstructionWithAccounts<TAccounts> & TInstruction;
|
|
41
|
+
/**
|
|
42
|
+
* An instruction whose data conforms to a certain type.
|
|
43
|
+
*
|
|
44
|
+
* This is most useful when you have a branded `Uint8Array` that represents a particular
|
|
45
|
+
* instruction's data.
|
|
46
|
+
*
|
|
47
|
+
* @example A type for the \`AdvanceNonce\` instruction of the System program
|
|
48
|
+
* ```ts
|
|
49
|
+
* type AdvanceNonceAccountInstruction<
|
|
50
|
+
* TNonceAccountAddress extends string = string,
|
|
51
|
+
* TNonceAuthorityAddress extends string = string,
|
|
52
|
+
* > = IInstruction<'11111111111111111111111111111111'> &
|
|
53
|
+
* IInstructionWithAccounts<
|
|
54
|
+
* [
|
|
55
|
+
* WritableAccount<TNonceAccountAddress>,
|
|
56
|
+
* ReadonlyAccount<'SysvarRecentB1ockHashes11111111111111111111'>,
|
|
57
|
+
* ReadonlySignerAccount<TNonceAuthorityAddress>,
|
|
58
|
+
* ]
|
|
59
|
+
* > &
|
|
60
|
+
* IInstructionWithData<AdvanceNonceAccountInstructionData>;
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
20
63
|
export interface IInstructionWithData<TData extends ReadonlyUint8Array> extends IInstruction {
|
|
21
64
|
readonly data: TData;
|
|
22
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instruction.d.ts","sourceRoot":"","sources":["../../src/instruction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAQzD,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE9D,MAAM,WAAW,YAAY,CACzB,eAAe,SAAS,MAAM,GAAG,MAAM,EACvC,SAAS,SAAS,SAAS,CAAC,kBAAkB,GAAG,YAAY,CAAC,EAAE,GAAG,SAAS,CAAC,kBAAkB,GAAG,YAAY,CAAC,EAAE;IAEjH,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,IAAI,CAAC,EAAE,kBAAkB,CAAC;IACnC,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;CACrD;AAED,MAAM,WAAW,wBAAwB,CAAC,SAAS,SAAS,SAAS,CAAC,kBAAkB,GAAG,YAAY,CAAC,EAAE,CACtG,SAAQ,YAAY;IACpB,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;CAChC;AAED,wBAAgB,uBAAuB,CAAC,eAAe,SAAS,MAAM,EAAE,YAAY,SAAS,YAAY,EACrG,WAAW,EAAE,YAAY,EACzB,cAAc,EAAE,OAAO,CAAC,eAAe,CAAC,GACzC,WAAW,IAAI,YAAY,GAAG;IAAE,cAAc,EAAE,OAAO,CAAC,eAAe,CAAC,CAAA;CAAE,CAE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
*
|
|
2
|
+
* Describes the purpose for which an account participates in a transaction.
|
|
3
|
+
*
|
|
4
|
+
* Every account that participates in a transaction can be read from, but only ones that you mark as
|
|
5
|
+
* writable may be written to, and only ones that you indicate must sign the transaction will gain
|
|
6
|
+
* the privileges associated with signers at runtime.
|
|
7
|
+
*
|
|
8
|
+
* | | `isSigner` | `isWritable` |
|
|
9
|
+
* | ----------------------------- | ---------- | ------------ |
|
|
10
|
+
* | `AccountRole.READONLY` | ❌ | ❌ |
|
|
11
|
+
* | `AccountRole.WRITABLE` | ❌ | ✅ |
|
|
12
|
+
* | `AccountRole.READONLY_SIGNER` | ✅ | ❌ |
|
|
13
|
+
* | `AccountRole.WRITABLE_SIGNER` | ✅ | ✅ |
|
|
3
14
|
*/
|
|
4
15
|
export declare enum AccountRole {
|
|
5
16
|
WRITABLE_SIGNER = 3,// prettier-ignore
|
|
@@ -7,14 +18,38 @@ export declare enum AccountRole {
|
|
|
7
18
|
WRITABLE = 1,// prettier-ignore
|
|
8
19
|
READONLY = 0
|
|
9
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* @returns An {@link AccountRole} representing the non-signer variant of the supplied role.
|
|
23
|
+
*/
|
|
10
24
|
export declare function downgradeRoleToNonSigner(role: AccountRole.READONLY_SIGNER): AccountRole.READONLY;
|
|
11
25
|
export declare function downgradeRoleToNonSigner(role: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE;
|
|
12
26
|
export declare function downgradeRoleToNonSigner(role: AccountRole): AccountRole;
|
|
27
|
+
/**
|
|
28
|
+
* @returns An {@link AccountRole} representing the read-only variant of the supplied role.
|
|
29
|
+
*/
|
|
13
30
|
export declare function downgradeRoleToReadonly(role: AccountRole.WRITABLE): AccountRole.READONLY;
|
|
14
31
|
export declare function downgradeRoleToReadonly(role: AccountRole.WRITABLE_SIGNER): AccountRole.READONLY_SIGNER;
|
|
15
32
|
export declare function downgradeRoleToReadonly(role: AccountRole): AccountRole;
|
|
33
|
+
/**
|
|
34
|
+
* Returns `true` if the {@link AccountRole} given represents that of a signer. Also refines the
|
|
35
|
+
* TypeScript type of the supplied role.
|
|
36
|
+
*/
|
|
16
37
|
export declare function isSignerRole(role: AccountRole): role is AccountRole.READONLY_SIGNER | AccountRole.WRITABLE_SIGNER;
|
|
38
|
+
/**
|
|
39
|
+
* Returns `true` if the {@link AccountRole} given represents that of a writable account. Also
|
|
40
|
+
* refines the TypeScript type of the supplied role.
|
|
41
|
+
*/
|
|
17
42
|
export declare function isWritableRole(role: AccountRole): role is AccountRole.WRITABLE | AccountRole.WRITABLE_SIGNER;
|
|
43
|
+
/**
|
|
44
|
+
* Given two {@link AccountRole | AccountRoles}, will return the {@link AccountRole} that grants the
|
|
45
|
+
* highest privileges of both.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* // Returns `AccountRole.WRITABLE_SIGNER`
|
|
50
|
+
* mergeRoles(AccountRole.READONLY_SIGNER, AccountRole.WRITABLE);
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
18
53
|
export declare function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER;
|
|
19
54
|
export declare function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER;
|
|
20
55
|
export declare function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE_SIGNER;
|
|
@@ -25,9 +60,15 @@ export declare function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITAB
|
|
|
25
60
|
export declare function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole): AccountRole.WRITABLE;
|
|
26
61
|
export declare function mergeRoles(roleA: AccountRole.READONLY, roleB: AccountRole.READONLY): AccountRole.READONLY;
|
|
27
62
|
export declare function mergeRoles(roleA: AccountRole, roleB: AccountRole): AccountRole;
|
|
63
|
+
/**
|
|
64
|
+
* @returns An {@link AccountRole} representing the signer variant of the supplied role.
|
|
65
|
+
*/
|
|
28
66
|
export declare function upgradeRoleToSigner(role: AccountRole.READONLY): AccountRole.READONLY_SIGNER;
|
|
29
67
|
export declare function upgradeRoleToSigner(role: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER;
|
|
30
68
|
export declare function upgradeRoleToSigner(role: AccountRole): AccountRole;
|
|
69
|
+
/**
|
|
70
|
+
* @returns An {@link AccountRole} representing the writable variant of the supplied role.
|
|
71
|
+
*/
|
|
31
72
|
export declare function upgradeRoleToWritable(role: AccountRole.READONLY): AccountRole.WRITABLE;
|
|
32
73
|
export declare function upgradeRoleToWritable(role: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER;
|
|
33
74
|
export declare function upgradeRoleToWritable(role: AccountRole): AccountRole;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"roles.d.ts","sourceRoot":"","sources":["../../src/roles.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"roles.d.ts","sourceRoot":"","sources":["../../src/roles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,oBAAY,WAAW;IAEnB,eAAe,IAAe,CAAE,kBAAkB;IAClD,eAAe,IAAe,CAAE,kBAAkB;IAClD,QAAQ,IAAsB,CAAE,kBAAkB;IAClD,QAAQ,IAAsB;CACjC;AAMD;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,WAAW,CAAC,eAAe,GAAG,WAAW,CAAC,QAAQ,CAAC;AAClG,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,WAAW,CAAC,eAAe,GAAG,WAAW,CAAC,QAAQ,CAAC;AAClG,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,WAAW,GAAG,WAAW,CAAC;AAKzE;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC;AAC1F,wBAA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AAU,CAAC,KAAK,EAAE,WAAW,CAAC,QAAQ,EAAE,KAAK,EAAE,WAAW,GAAG,WAAW,CAAC,QAAQ,CAAC;AAClG,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC,QAAQ,EAAE,KAAK,EAAE,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC;AAC3G,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,GAAG,WAAW,CAAC;AAKhF;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC,eAAe,CAAC;AAC7F,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC,eAAe,CAAC;AAC7F,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,WAAW,GAAG,WAAW,CAAC;AAKpE;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC;AACxF,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,WAAW,CAAC,eAAe,GAAG,WAAW,CAAC,eAAe,CAAC;AACtG,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,WAAW,GAAG,WAAW,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana/instructions",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.1-canary-20250310215239",
|
|
4
4
|
"description": "Helpers for creating transaction instructions",
|
|
5
5
|
"exports": {
|
|
6
6
|
"edge-light": {
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"maintained node versions"
|
|
55
55
|
],
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@solana/
|
|
58
|
-
"@solana/
|
|
57
|
+
"@solana/codecs-core": "2.1.1-canary-20250310215239",
|
|
58
|
+
"@solana/errors": "2.1.1-canary-20250310215239"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"typescript": ">=5"
|