@solana/instructions 2.0.0-experimental.ffeddf6 → 2.0.0-preview.1

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.
@@ -1,5 +1,42 @@
1
1
  'use strict';
2
2
 
3
+ var errors = require('@solana/errors');
4
+
5
+ // src/instruction.ts
6
+ function isInstructionForProgram(instruction, programAddress) {
7
+ return instruction.programAddress === programAddress;
8
+ }
9
+ function assertIsInstructionForProgram(instruction, programAddress) {
10
+ if (instruction.programAddress !== programAddress) {
11
+ throw new errors.SolanaError(errors.SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH, {
12
+ actualProgramAddress: instruction.programAddress,
13
+ expectedProgramAddress: programAddress
14
+ });
15
+ }
16
+ }
17
+ function isInstructionWithAccounts(instruction) {
18
+ return instruction.accounts !== void 0;
19
+ }
20
+ function assertIsInstructionWithAccounts(instruction) {
21
+ if (instruction.accounts === void 0) {
22
+ throw new errors.SolanaError(errors.SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS, {
23
+ data: instruction.data,
24
+ programAddress: instruction.programAddress
25
+ });
26
+ }
27
+ }
28
+ function isInstructionWithData(instruction) {
29
+ return instruction.data !== void 0;
30
+ }
31
+ function assertIsInstructionWithData(instruction) {
32
+ if (instruction.data === void 0) {
33
+ throw new errors.SolanaError(errors.SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA, {
34
+ accountAddresses: instruction.accounts?.map((a) => a.address),
35
+ programAddress: instruction.programAddress
36
+ });
37
+ }
38
+ }
39
+
3
40
  // src/roles.ts
4
41
  var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
5
42
  AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
@@ -37,8 +74,14 @@ function upgradeRoleToWritable(role) {
37
74
  }
38
75
 
39
76
  exports.AccountRole = AccountRole;
77
+ exports.assertIsInstructionForProgram = assertIsInstructionForProgram;
78
+ exports.assertIsInstructionWithAccounts = assertIsInstructionWithAccounts;
79
+ exports.assertIsInstructionWithData = assertIsInstructionWithData;
40
80
  exports.downgradeRoleToNonSigner = downgradeRoleToNonSigner;
41
81
  exports.downgradeRoleToReadonly = downgradeRoleToReadonly;
82
+ exports.isInstructionForProgram = isInstructionForProgram;
83
+ exports.isInstructionWithAccounts = isInstructionWithAccounts;
84
+ exports.isInstructionWithData = isInstructionWithData;
42
85
  exports.isSignerRole = isSignerRole;
43
86
  exports.isWritableRole = isWritableRole;
44
87
  exports.mergeRoles = mergeRoles;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/roles.ts"],"names":["AccountRole"],"mappings":";AAIO,IAAK,cAAL,kBAAKA,iBAAL;AAEH,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AACA,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AACA,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AACA,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AALQ,SAAAA;AAAA,GAAA;AAQZ,IAAM,oBAAoB;AAC1B,IAAM,sBAAsB;AAKrB,SAAS,yBAAyB,MAAgC;AACrE,SAAO,OAAO,CAAC;AACnB;AAKO,SAAS,wBAAwB,MAAgC;AACpE,SAAO,OAAO,CAAC;AACnB;AAEO,SAAS,aAAa,MAAsF;AAC/G,SAAO,QAAQ;AACnB;AAEO,SAAS,eAAe,MAA+E;AAC1G,UAAQ,OAAO,yBAAyB;AAC5C;AAYO,SAAS,WAAW,OAAoB,OAAiC;AAC5E,SAAO,QAAQ;AACnB;AAKO,SAAS,oBAAoB,MAAgC;AAChE,SAAO,OAAO;AAClB;AAKO,SAAS,sBAAsB,MAAgC;AAClE,SAAO,OAAO;AAClB","sourcesContent":["/**\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":";AACA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAkBA,SAAS,wBACZ,aACA,gBAC0E;AAC1E,SAAO,YAAY,mBAAmB;AAC1C;AAEO,SAAS,8BACZ,aACA,gBACkF;AAClF,MAAI,YAAY,mBAAmB,gBAAgB;AAC/C,UAAM,IAAI,YAAY,gDAAgD;AAAA,MAClE,sBAAsB,YAAY;AAAA,MAClC,wB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\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?: Uint8Array;\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 Uint8Array> extends IInstruction {\n readonly data: TData;\n}\n\nexport function isInstructionWithData<\n TData extends Uint8Array = Uint8Array,\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 Uint8Array = Uint8Array,\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,3 +1,40 @@
1
+ import { SolanaError, SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH, SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS, SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA } from '@solana/errors';
2
+
3
+ // src/instruction.ts
4
+ function isInstructionForProgram(instruction, programAddress) {
5
+ return instruction.programAddress === programAddress;
6
+ }
7
+ function assertIsInstructionForProgram(instruction, programAddress) {
8
+ if (instruction.programAddress !== programAddress) {
9
+ throw new SolanaError(SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH, {
10
+ actualProgramAddress: instruction.programAddress,
11
+ expectedProgramAddress: programAddress
12
+ });
13
+ }
14
+ }
15
+ function isInstructionWithAccounts(instruction) {
16
+ return instruction.accounts !== void 0;
17
+ }
18
+ function assertIsInstructionWithAccounts(instruction) {
19
+ if (instruction.accounts === void 0) {
20
+ throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS, {
21
+ data: instruction.data,
22
+ programAddress: instruction.programAddress
23
+ });
24
+ }
25
+ }
26
+ function isInstructionWithData(instruction) {
27
+ return instruction.data !== void 0;
28
+ }
29
+ function assertIsInstructionWithData(instruction) {
30
+ if (instruction.data === void 0) {
31
+ throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA, {
32
+ accountAddresses: instruction.accounts?.map((a) => a.address),
33
+ programAddress: instruction.programAddress
34
+ });
35
+ }
36
+ }
37
+
1
38
  // src/roles.ts
2
39
  var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
3
40
  AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
@@ -34,6 +71,6 @@ function upgradeRoleToWritable(role) {
34
71
  return role | IS_WRITABLE_BITMASK;
35
72
  }
36
73
 
37
- export { AccountRole, downgradeRoleToNonSigner, downgradeRoleToReadonly, isSignerRole, isWritableRole, mergeRoles, upgradeRoleToSigner, upgradeRoleToWritable };
74
+ export { AccountRole, assertIsInstructionForProgram, assertIsInstructionWithAccounts, assertIsInstructionWithData, downgradeRoleToNonSigner, downgradeRoleToReadonly, isInstructionForProgram, isInstructionWithAccounts, isInstructionWithData, isSignerRole, isWritableRole, mergeRoles, upgradeRoleToSigner, upgradeRoleToWritable };
38
75
  //# sourceMappingURL=out.js.map
39
76
  //# sourceMappingURL=index.browser.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/roles.ts"],"names":["AccountRole"],"mappings":";AAIO,IAAK,cAAL,kBAAKA,iBAAL;AAEH,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AACA,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AACA,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AACA,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AALQ,SAAAA;AAAA,GAAA;AAQZ,IAAM,oBAAoB;AAC1B,IAAM,sBAAsB;AAKrB,SAAS,yBAAyB,MAAgC;AACrE,SAAO,OAAO,CAAC;AACnB;AAKO,SAAS,wBAAwB,MAAgC;AACpE,SAAO,OAAO,CAAC;AACnB;AAEO,SAAS,aAAa,MAAsF;AAC/G,SAAO,QAAQ;AACnB;AAEO,SAAS,eAAe,MAA+E;AAC1G,UAAQ,OAAO,yBAAyB;AAC5C;AAYO,SAAS,WAAW,OAAoB,OAAiC;AAC5E,SAAO,QAAQ;AACnB;AAKO,SAAS,oBAAoB,MAAgC;AAChE,SAAO,OAAO;AAClB;AAKO,SAAS,sBAAsB,MAAgC;AAClE,SAAO,OAAO;AAClB","sourcesContent":["/**\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":";AACA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAkBA,SAAS,wBACZ,aACA,gBAC0E;AAC1E,SAAO,YAAY,mBAAmB;AAC1C;AAEO,SAAS,8BACZ,aACA,gBACkF;AAClF,MAAI,YAAY,mBAAmB,gBAAgB;AAC/C,UAAM,IAAI,YAAY,gDAAgD;AAAA,MAClE,sBAAsB,YAAY;AAAA,MAClC,wBAAwB;AAAA,IAC5B,CAAC;AAAA,EACL;AACJ;AAEO,SAAS,0BAGd,aAA8F;AAC5F,SAAO,YAAY,aAAa;AACpC;AAEO,SAAS,gCAGd,aAAsG;AACpG,MAAI,YAAY,aAAa,QAAW;AACpC,UAAM,IAAI,YAAY,sDAAsD;AAAA,MACxE,MAAM,YAAY;AAAA,MAClB,gBAAgB,YAAY;AAAA,IAChC,CAAC;AAAA,EACL;AACJ;AAMO,SAAS,sBAGd,aAAsF;AACpF,SAAO,YAAY,SAAS;AAChC;AAEO,SAAS,4BAGd,aAA8F;AAC5F,MAAI,YAAY,SAAS,QAAW;AAChC,UAAM,IAAI,YAAY,kDAAkD;AAAA,MACpE,kBAAkB,YAAY,UAAU,IAAI,OAAK,EAAE,OAAO;AAAA,MAC1D,gBAAgB,YAAY;AAAA,IAChC,CAAC;AAAA,EACL;AACJ;;;AC/EO,IAAK,cAAL,kBAAKA,iBAAL;AAEH,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AACA,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AACA,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AACA,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AALQ,SAAAA;AAAA,GAAA;AAQZ,IAAM,oBAAoB;AAC1B,IAAM,sBAAsB;AAKrB,SAAS,yBAAyB,MAAgC;AACrE,SAAO,OAAO,CAAC;AACnB;AAKO,SAAS,wBAAwB,MAAgC;AACpE,SAAO,OAAO,CAAC;AACnB;AAEO,SAAS,aAAa,MAAsF;AAC/G,SAAO,QAAQ;AACnB;AAEO,SAAS,eAAe,MAA+E;AAC1G,UAAQ,OAAO,yBAAyB;AAC5C;AAYO,SAAS,WAAW,OAAoB,OAAiC;AAC5E,SAAO,QAAQ;AACnB;AAKO,SAAS,oBAAoB,MAAgC;AAChE,SAAO,OAAO;AAClB;AAKO,SAAS,sBAAsB,MAAgC;AAClE,SAAO,OAAO;AAClB","sourcesContent":["import { Address } from '@solana/addresses';\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?: Uint8Array;\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 Uint8Array> extends IInstruction {\n readonly data: TData;\n}\n\nexport function isInstructionWithData<\n TData extends Uint8Array = Uint8Array,\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 Uint8Array = Uint8Array,\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,3 +1,40 @@
1
+ import { SolanaError, SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH, SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS, SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA } from '@solana/errors';
2
+
3
+ // src/instruction.ts
4
+ function isInstructionForProgram(instruction, programAddress) {
5
+ return instruction.programAddress === programAddress;
6
+ }
7
+ function assertIsInstructionForProgram(instruction, programAddress) {
8
+ if (instruction.programAddress !== programAddress) {
9
+ throw new SolanaError(SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH, {
10
+ actualProgramAddress: instruction.programAddress,
11
+ expectedProgramAddress: programAddress
12
+ });
13
+ }
14
+ }
15
+ function isInstructionWithAccounts(instruction) {
16
+ return instruction.accounts !== void 0;
17
+ }
18
+ function assertIsInstructionWithAccounts(instruction) {
19
+ if (instruction.accounts === void 0) {
20
+ throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS, {
21
+ data: instruction.data,
22
+ programAddress: instruction.programAddress
23
+ });
24
+ }
25
+ }
26
+ function isInstructionWithData(instruction) {
27
+ return instruction.data !== void 0;
28
+ }
29
+ function assertIsInstructionWithData(instruction) {
30
+ if (instruction.data === void 0) {
31
+ throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA, {
32
+ accountAddresses: instruction.accounts?.map((a) => a.address),
33
+ programAddress: instruction.programAddress
34
+ });
35
+ }
36
+ }
37
+
1
38
  // src/roles.ts
2
39
  var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
3
40
  AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
@@ -34,6 +71,6 @@ function upgradeRoleToWritable(role) {
34
71
  return role | IS_WRITABLE_BITMASK;
35
72
  }
36
73
 
37
- export { AccountRole, downgradeRoleToNonSigner, downgradeRoleToReadonly, isSignerRole, isWritableRole, mergeRoles, upgradeRoleToSigner, upgradeRoleToWritable };
74
+ export { AccountRole, assertIsInstructionForProgram, assertIsInstructionWithAccounts, assertIsInstructionWithData, downgradeRoleToNonSigner, downgradeRoleToReadonly, isInstructionForProgram, isInstructionWithAccounts, isInstructionWithData, isSignerRole, isWritableRole, mergeRoles, upgradeRoleToSigner, upgradeRoleToWritable };
38
75
  //# sourceMappingURL=out.js.map
39
76
  //# sourceMappingURL=index.native.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/roles.ts"],"names":["AccountRole"],"mappings":";AAIO,IAAK,cAAL,kBAAKA,iBAAL;AAEH,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AACA,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AACA,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AACA,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AALQ,SAAAA;AAAA,GAAA;AAQZ,IAAM,oBAAoB;AAC1B,IAAM,sBAAsB;AAKrB,SAAS,yBAAyB,MAAgC;AACrE,SAAO,OAAO,CAAC;AACnB;AAKO,SAAS,wBAAwB,MAAgC;AACpE,SAAO,OAAO,CAAC;AACnB;AAEO,SAAS,aAAa,MAAsF;AAC/G,SAAO,QAAQ;AACnB;AAEO,SAAS,eAAe,MAA+E;AAC1G,UAAQ,OAAO,yBAAyB;AAC5C;AAYO,SAAS,WAAW,OAAoB,OAAiC;AAC5E,SAAO,QAAQ;AACnB;AAKO,SAAS,oBAAoB,MAAgC;AAChE,SAAO,OAAO;AAClB;AAKO,SAAS,sBAAsB,MAAgC;AAClE,SAAO,OAAO;AAClB","sourcesContent":["/**\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":";AACA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAkBA,SAAS,wBACZ,aACA,gBAC0E;AAC1E,SAAO,YAAY,mBAAmB;AAC1C;AAEO,SAAS,8BACZ,aACA,gBACkF;AAClF,MAAI,YAAY,mBAAmB,gBAAgB;AAC/C,UAAM,IAAI,YAAY,gDAAgD;AAAA,MAClE,sBAAsB,YAAY;AAAA,MAClC,wBAAwB;AAAA,IAC5B,CAAC;AAAA,EACL;AACJ;AAEO,SAAS,0BAGd,aAA8F;AAC5F,SAAO,YAAY,aAAa;AACpC;AAEO,SAAS,gCAGd,aAAsG;AACpG,MAAI,YAAY,aAAa,QAAW;AACpC,UAAM,IAAI,YAAY,sDAAsD;AAAA,MACxE,MAAM,YAAY;AAAA,MAClB,gBAAgB,YAAY;AAAA,IAChC,CAAC;AAAA,EACL;AACJ;AAMO,SAAS,sBAGd,aAAsF;AACpF,SAAO,YAAY,SAAS;AAChC;AAEO,SAAS,4BAGd,aAA8F;AAC5F,MAAI,YAAY,SAAS,QAAW;AAChC,UAAM,IAAI,YAAY,kDAAkD;AAAA,MACpE,kBAAkB,YAAY,UAAU,IAAI,OAAK,EAAE,OAAO;AAAA,MAC1D,gBAAgB,YAAY;AAAA,IAChC,CAAC;AAAA,EACL;AACJ;;;AC/EO,IAAK,cAAL,kBAAKA,iBAAL;AAEH,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AACA,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AACA,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AACA,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AALQ,SAAAA;AAAA,GAAA;AAQZ,IAAM,oBAAoB;AAC1B,IAAM,sBAAsB;AAKrB,SAAS,yBAAyB,MAAgC;AACrE,SAAO,OAAO,CAAC;AACnB;AAKO,SAAS,wBAAwB,MAAgC;AACpE,SAAO,OAAO,CAAC;AACnB;AAEO,SAAS,aAAa,MAAsF;AAC/G,SAAO,QAAQ;AACnB;AAEO,SAAS,eAAe,MAA+E;AAC1G,UAAQ,OAAO,yBAAyB;AAC5C;AAYO,SAAS,WAAW,OAAoB,OAAiC;AAC5E,SAAO,QAAQ;AACnB;AAKO,SAAS,oBAAoB,MAAgC;AAChE,SAAO,OAAO;AAClB;AAKO,SAAS,sBAAsB,MAAgC;AAClE,SAAO,OAAO;AAClB","sourcesContent":["import { Address } from '@solana/addresses';\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?: Uint8Array;\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 Uint8Array> extends IInstruction {\n readonly data: TData;\n}\n\nexport function isInstructionWithData<\n TData extends Uint8Array = Uint8Array,\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 Uint8Array = Uint8Array,\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,5 +1,42 @@
1
1
  'use strict';
2
2
 
3
+ var errors = require('@solana/errors');
4
+
5
+ // src/instruction.ts
6
+ function isInstructionForProgram(instruction, programAddress) {
7
+ return instruction.programAddress === programAddress;
8
+ }
9
+ function assertIsInstructionForProgram(instruction, programAddress) {
10
+ if (instruction.programAddress !== programAddress) {
11
+ throw new errors.SolanaError(errors.SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH, {
12
+ actualProgramAddress: instruction.programAddress,
13
+ expectedProgramAddress: programAddress
14
+ });
15
+ }
16
+ }
17
+ function isInstructionWithAccounts(instruction) {
18
+ return instruction.accounts !== void 0;
19
+ }
20
+ function assertIsInstructionWithAccounts(instruction) {
21
+ if (instruction.accounts === void 0) {
22
+ throw new errors.SolanaError(errors.SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS, {
23
+ data: instruction.data,
24
+ programAddress: instruction.programAddress
25
+ });
26
+ }
27
+ }
28
+ function isInstructionWithData(instruction) {
29
+ return instruction.data !== void 0;
30
+ }
31
+ function assertIsInstructionWithData(instruction) {
32
+ if (instruction.data === void 0) {
33
+ throw new errors.SolanaError(errors.SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA, {
34
+ accountAddresses: instruction.accounts?.map((a) => a.address),
35
+ programAddress: instruction.programAddress
36
+ });
37
+ }
38
+ }
39
+
3
40
  // src/roles.ts
4
41
  var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
5
42
  AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
@@ -37,8 +74,14 @@ function upgradeRoleToWritable(role) {
37
74
  }
38
75
 
39
76
  exports.AccountRole = AccountRole;
77
+ exports.assertIsInstructionForProgram = assertIsInstructionForProgram;
78
+ exports.assertIsInstructionWithAccounts = assertIsInstructionWithAccounts;
79
+ exports.assertIsInstructionWithData = assertIsInstructionWithData;
40
80
  exports.downgradeRoleToNonSigner = downgradeRoleToNonSigner;
41
81
  exports.downgradeRoleToReadonly = downgradeRoleToReadonly;
82
+ exports.isInstructionForProgram = isInstructionForProgram;
83
+ exports.isInstructionWithAccounts = isInstructionWithAccounts;
84
+ exports.isInstructionWithData = isInstructionWithData;
42
85
  exports.isSignerRole = isSignerRole;
43
86
  exports.isWritableRole = isWritableRole;
44
87
  exports.mergeRoles = mergeRoles;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/roles.ts"],"names":["AccountRole"],"mappings":";AAIO,IAAK,cAAL,kBAAKA,iBAAL;AAEH,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AACA,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AACA,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AACA,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AALQ,SAAAA;AAAA,GAAA;AAQZ,IAAM,oBAAoB;AAC1B,IAAM,sBAAsB;AAKrB,SAAS,yBAAyB,MAAgC;AACrE,SAAO,OAAO,CAAC;AACnB;AAKO,SAAS,wBAAwB,MAAgC;AACpE,SAAO,OAAO,CAAC;AACnB;AAEO,SAAS,aAAa,MAAsF;AAC/G,SAAO,QAAQ;AACnB;AAEO,SAAS,eAAe,MAA+E;AAC1G,UAAQ,OAAO,yBAAyB;AAC5C;AAYO,SAAS,WAAW,OAAoB,OAAiC;AAC5E,SAAO,QAAQ;AACnB;AAKO,SAAS,oBAAoB,MAAgC;AAChE,SAAO,OAAO;AAClB;AAKO,SAAS,sBAAsB,MAAgC;AAClE,SAAO,OAAO;AAClB","sourcesContent":["/**\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":";AACA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAkBA,SAAS,wBACZ,aACA,gBAC0E;AAC1E,SAAO,YAAY,mBAAmB;AAC1C;AAEO,SAAS,8BACZ,aACA,gBACkF;AAClF,MAAI,YAAY,mBAAmB,gBAAgB;AAC/C,UAAM,IAAI,YAAY,gDAAgD;AAAA,MAClE,sBAAsB,YAAY;AAAA,MAClC,wBAAwB;AAAA,IAC5B,CAAC;AAAA,EACL;AACJ;AAEO,SAAS,0BAGd,aAA8F;AAC5F,SAA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ION__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?: Uint8Array;\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 Uint8Array> extends IInstruction {\n readonly data: TData;\n}\n\nexport function isInstructionWithData<\n TData extends Uint8Array = Uint8Array,\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 Uint8Array = Uint8Array,\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,3 +1,40 @@
1
+ import { SolanaError, SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH, SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS, SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA } from '@solana/errors';
2
+
3
+ // src/instruction.ts
4
+ function isInstructionForProgram(instruction, programAddress) {
5
+ return instruction.programAddress === programAddress;
6
+ }
7
+ function assertIsInstructionForProgram(instruction, programAddress) {
8
+ if (instruction.programAddress !== programAddress) {
9
+ throw new SolanaError(SOLANA_ERROR__INSTRUCTION__PROGRAM_ID_MISMATCH, {
10
+ actualProgramAddress: instruction.programAddress,
11
+ expectedProgramAddress: programAddress
12
+ });
13
+ }
14
+ }
15
+ function isInstructionWithAccounts(instruction) {
16
+ return instruction.accounts !== void 0;
17
+ }
18
+ function assertIsInstructionWithAccounts(instruction) {
19
+ if (instruction.accounts === void 0) {
20
+ throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS, {
21
+ data: instruction.data,
22
+ programAddress: instruction.programAddress
23
+ });
24
+ }
25
+ }
26
+ function isInstructionWithData(instruction) {
27
+ return instruction.data !== void 0;
28
+ }
29
+ function assertIsInstructionWithData(instruction) {
30
+ if (instruction.data === void 0) {
31
+ throw new SolanaError(SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA, {
32
+ accountAddresses: instruction.accounts?.map((a) => a.address),
33
+ programAddress: instruction.programAddress
34
+ });
35
+ }
36
+ }
37
+
1
38
  // src/roles.ts
2
39
  var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
3
40
  AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
@@ -34,6 +71,6 @@ function upgradeRoleToWritable(role) {
34
71
  return role | IS_WRITABLE_BITMASK;
35
72
  }
36
73
 
37
- export { AccountRole, downgradeRoleToNonSigner, downgradeRoleToReadonly, isSignerRole, isWritableRole, mergeRoles, upgradeRoleToSigner, upgradeRoleToWritable };
74
+ export { AccountRole, assertIsInstructionForProgram, assertIsInstructionWithAccounts, assertIsInstructionWithData, downgradeRoleToNonSigner, downgradeRoleToReadonly, isInstructionForProgram, isInstructionWithAccounts, isInstructionWithData, isSignerRole, isWritableRole, mergeRoles, upgradeRoleToSigner, upgradeRoleToWritable };
38
75
  //# sourceMappingURL=out.js.map
39
76
  //# sourceMappingURL=index.node.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/roles.ts"],"names":["AccountRole"],"mappings":";AAIO,IAAK,cAAL,kBAAKA,iBAAL;AAEH,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AACA,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AACA,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AACA,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AALQ,SAAAA;AAAA,GAAA;AAQZ,IAAM,oBAAoB;AAC1B,IAAM,sBAAsB;AAKrB,SAAS,yBAAyB,MAAgC;AACrE,SAAO,OAAO,CAAC;AACnB;AAKO,SAAS,wBAAwB,MAAgC;AACpE,SAAO,OAAO,CAAC;AACnB;AAEO,SAAS,aAAa,MAAsF;AAC/G,SAAO,QAAQ;AACnB;AAEO,SAAS,eAAe,MAA+E;AAC1G,UAAQ,OAAO,yBAAyB;AAC5C;AAYO,SAAS,WAAW,OAAoB,OAAiC;AAC5E,SAAO,QAAQ;AACnB;AAKO,SAAS,oBAAoB,MAAgC;AAChE,SAAO,OAAO;AAClB;AAKO,SAAS,sBAAsB,MAAgC;AAClE,SAAO,OAAO;AAClB","sourcesContent":["/**\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
+ {"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O,CAAC;AACnB;AAEO,SAAS,aAAa,MAAsF;AAC/G,SAAO,QAAQ;AACnB;AAEO,SAAS,eAAe,MAA+E;AAC1G,UAAQ,OAAO,yBAAyB;AAC5C;AAYO,SAAS,WAAW,OAAoB,OAAiC;AAC5E,SAAO,QAAQ;AACnB;AAKO,SAAS,oBAAoB,MAAgC;AAChE,SAAO,OAAO;AAClB;AAKO,SAAS,sBAAsB,MAAgC;AAClE,SAAO,OAAO;AAClB","sourcesContent":["import { Address } from '@solana/addresses';\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?: Uint8Array;\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 Uint8Array> extends IInstruction {\n readonly data: TData;\n}\n\nexport function isInstructionWithData<\n TData extends Uint8Array = Uint8Array,\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 Uint8Array = Uint8Array,\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,7 +1,7 @@
1
- import { Base58EncodedAddress } from '@solana/addresses';
2
- import { AccountRole } from './roles';
1
+ import { Address } from '@solana/addresses';
2
+ import { AccountRole } from './roles.js';
3
3
  export interface IAccountMeta<TAddress extends string = string> {
4
- readonly address: Base58EncodedAddress<TAddress>;
4
+ readonly address: Address<TAddress>;
5
5
  readonly role: AccountRole;
6
6
  }
7
7
  export type ReadonlyAccount<TAddress extends string = string> = IAccountMeta<TAddress> & {
@@ -17,9 +17,9 @@ export type WritableSignerAccount<TAddress extends string = string> = IAccountMe
17
17
  role: AccountRole.WRITABLE_SIGNER;
18
18
  };
19
19
  export interface IAccountLookupMeta<TAddress extends string = string, TLookupTableAddress extends string = string> {
20
- readonly address: Base58EncodedAddress<TAddress>;
20
+ readonly address: Address<TAddress>;
21
21
  readonly addressIndex: number;
22
- readonly lookupTableAddress: Base58EncodedAddress<TLookupTableAddress>;
22
+ readonly lookupTableAddress: Address<TLookupTableAddress>;
23
23
  readonly role: AccountRole.READONLY | AccountRole.WRITABLE;
24
24
  }
25
25
  export type ReadonlyAccountLookup<TAddress extends string = string, TLookupTableAddress extends string = string> = IAccountLookupMeta<TAddress, TLookupTableAddress> & {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../../src/accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,MAAM,WAAW,YAAY,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM;IAC1D,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;CAC9B;AAED,MAAM,MAAM,eAAe,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG;IACrF,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,QAAQ,CAAC;CACvC,CAAC;AACF,MAAM,MAAM,eAAe,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG;IAAE,IAAI,EAAE,WAAW,CAAC,QAAQ,CAAA;CAAE,CAAC;AACxH,MAAM,MAAM,qBAAqB,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG;IAC3F,IAAI,EAAE,WAAW,CAAC,eAAe,CAAC;CACrC,CAAC;AACF,MAAM,MAAM,qBAAqB,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG;IAC3F,IAAI,EAAE,WAAW,CAAC,eAAe,CAAC;CACrC,CAAC;AAEF,MAAM,WAAW,kBAAkB,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,EAAE,mBAAmB,SAAS,MAAM,GAAG,MAAM;IAC7G,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,kBAAkB,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC1D,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC;CAC9D;AAED,MAAM,MAAM,qBAAqB,CAC7B,QAAQ,SAAS,MAAM,GAAG,MAAM,EAChC,mBAAmB,SAAS,MAAM,GAAG,MAAM,IAC3C,kBAAkB,CAAC,QAAQ,EAAE,mBAAmB,CAAC,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,QAAQ,CAAA;CAAE,CAAC;AAChG,MAAM,MAAM,qBAAqB,CAC7B,QAAQ,SAAS,MAAM,GAAG,MAAM,EAChC,mBAAmB,SAAS,MAAM,GAAG,MAAM,IAC3C,kBAAkB,CAAC,QAAQ,EAAE,mBAAmB,CAAC,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,QAAQ,CAAA;CAAE,CAAC"}
@@ -1,4 +1,4 @@
1
- export * from './accounts';
2
- export * from './instruction';
3
- export * from './roles';
1
+ export * from './accounts.js';
2
+ export * from './instruction.js';
3
+ export * from './roles.js';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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,14 +1,24 @@
1
- import { Base58EncodedAddress } from '@solana/addresses';
2
- import { IAccountLookupMeta, IAccountMeta } from './accounts';
3
- export interface IInstruction<TProgramAddress extends string = string> {
4
- readonly accounts?: readonly (IAccountMeta | IAccountLookupMeta)[];
1
+ import { Address } from '@solana/addresses';
2
+ import { IAccountLookupMeta, IAccountMeta } from './accounts.js';
3
+ export interface IInstruction<TProgramAddress extends string = string, TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[]> {
4
+ readonly accounts?: TAccounts;
5
5
  readonly data?: Uint8Array;
6
- readonly programAddress: Base58EncodedAddress<TProgramAddress>;
6
+ readonly programAddress: Address<TProgramAddress>;
7
7
  }
8
- export interface IInstructionWithAccounts<TAccounts extends readonly (IAccountMeta | IAccountLookupMeta)[]> extends IInstruction {
8
+ export interface IInstructionWithAccounts<TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[]> extends IInstruction {
9
9
  readonly accounts: TAccounts;
10
10
  }
11
+ export declare function isInstructionForProgram<TProgramAddress extends string, TInstruction extends IInstruction>(instruction: TInstruction, programAddress: Address<TProgramAddress>): instruction is TInstruction & {
12
+ programAddress: Address<TProgramAddress>;
13
+ };
14
+ export declare function assertIsInstructionForProgram<TProgramAddress extends string, TInstruction extends IInstruction>(instruction: TInstruction, programAddress: Address<TProgramAddress>): asserts instruction is TInstruction & {
15
+ programAddress: Address<TProgramAddress>;
16
+ };
17
+ export declare function isInstructionWithAccounts<TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[], TInstruction extends IInstruction = IInstruction>(instruction: TInstruction): instruction is IInstructionWithAccounts<TAccounts> & TInstruction;
18
+ export declare function assertIsInstructionWithAccounts<TAccounts extends readonly (IAccountLookupMeta | IAccountMeta)[] = readonly (IAccountLookupMeta | IAccountMeta)[], TInstruction extends IInstruction = IInstruction>(instruction: TInstruction): asserts instruction is IInstructionWithAccounts<TAccounts> & TInstruction;
11
19
  export interface IInstructionWithData<TData extends Uint8Array> extends IInstruction {
12
20
  readonly data: TData;
13
21
  }
22
+ export declare function isInstructionWithData<TData extends Uint8Array = Uint8Array, TInstruction extends IInstruction = IInstruction>(instruction: TInstruction): instruction is IInstructionWithData<TData> & TInstruction;
23
+ export declare function assertIsInstructionWithData<TData extends Uint8Array = Uint8Array, TInstruction extends IInstruction = IInstruction>(instruction: TInstruction): asserts instruction is IInstructionWithData<TData> & TInstruction;
14
24
  //# sourceMappingURL=instruction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instruction.d.ts","sourceRoot":"","sources":["../../src/instruction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAQ5C,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,UAAU,CAAC;IAC3B,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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AAI,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.0.0-experimental.ffeddf6",
3
+ "version": "2.0.0-preview.1",
4
4
  "description": "Helpers for creating transaction instructions",
5
5
  "exports": {
6
6
  "browser": {
@@ -45,26 +45,8 @@
45
45
  "supports bigint and not dead",
46
46
  "maintained node versions"
47
47
  ],
48
- "devDependencies": {
49
- "@solana/eslint-config-solana": "^1.0.2",
50
- "@swc/jest": "^0.2.29",
51
- "@types/jest": "^29.5.6",
52
- "@typescript-eslint/eslint-plugin": "^6.7.0",
53
- "@typescript-eslint/parser": "^6.3.0",
54
- "agadoo": "^3.0.0",
55
- "eslint": "^8.45.0",
56
- "eslint-plugin-sort-keys-fix": "^1.1.2",
57
- "jest": "^29.7.0",
58
- "jest-runner-eslint": "^2.1.2",
59
- "jest-runner-prettier": "^1.0.0",
60
- "prettier": "^2.8",
61
- "tsup": "7.2.0",
62
- "typescript": "^5.2.2",
63
- "version-from-git": "^1.1.1",
64
- "@solana/addresses": "2.0.0-experimental.ffeddf6",
65
- "test-config": "0.0.0",
66
- "build-scripts": "0.0.0",
67
- "tsconfig": "0.0.0"
48
+ "dependencies": {
49
+ "@solana/errors": "2.0.0-preview.1"
68
50
  },
69
51
  "bundlewatch": {
70
52
  "defaultCompression": "gzip",
@@ -75,18 +57,19 @@
75
57
  ]
76
58
  },
77
59
  "scripts": {
78
- "compile:js": "tsup --config build-scripts/tsup.config.library.ts",
79
- "compile:typedefs": "tsc -p ./tsconfig.declarations.json",
80
- "dev": "jest -c node_modules/test-config/jest-dev.config.ts --rootDir . --watch",
81
- "publish-packages": "pnpm publish --tag experimental --access public --no-git-checks",
60
+ "compile:js": "tsup --config build-scripts/tsup.config.package.ts",
61
+ "compile:typedefs": "tsc -p ./tsconfig.declarations.json && node ../../node_modules/@solana/build-scripts/add-js-extension-to-types.mjs",
62
+ "dev": "jest -c ../../node_modules/@solana/test-config/jest-dev.config.ts --rootDir . --watch",
63
+ "publish-impl": "npm view $npm_package_name@$npm_package_version > /dev/null 2>&1 || pnpm publish --tag preview --access public --no-git-checks",
64
+ "publish-packages": "pnpm prepublishOnly && pnpm publish-impl",
82
65
  "style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/* package.json",
83
- "test:lint": "jest -c node_modules/test-config/jest-lint.config.ts --rootDir . --silent",
84
- "test:prettier": "jest -c node_modules/test-config/jest-prettier.config.ts --rootDir . --silent",
66
+ "test:lint": "jest -c ../../node_modules/@solana/test-config/jest-lint.config.ts --rootDir . --silent",
67
+ "test:prettier": "jest -c ../../node_modules/@solana/test-config/jest-prettier.config.ts --rootDir . --silent",
85
68
  "test:treeshakability:browser": "agadoo dist/index.browser.js",
86
69
  "test:treeshakability:native": "agadoo dist/index.native.js",
87
70
  "test:treeshakability:node": "agadoo dist/index.node.js",
88
71
  "test:typecheck": "tsc --noEmit",
89
- "test:unit:browser": "jest -c node_modules/test-config/jest-unit.config.browser.ts --rootDir . --silent",
90
- "test:unit:node": "jest -c node_modules/test-config/jest-unit.config.node.ts --rootDir . --silent"
72
+ "test:unit:browser": "jest -c ../../node_modules/@solana/test-config/jest-unit.config.browser.ts --rootDir . --silent",
73
+ "test:unit:node": "jest -c ../../node_modules/@solana/test-config/jest-unit.config.node.ts --rootDir . --silent"
91
74
  }
92
75
  }
@@ -1,54 +0,0 @@
1
- this.globalThis = this.globalThis || {};
2
- this.globalThis.solanaWeb3 = (function (exports) {
3
- 'use strict';
4
-
5
- // src/roles.ts
6
- var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
7
- AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
8
- 3] = "WRITABLE_SIGNER";
9
- AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */
10
- 2] = "READONLY_SIGNER";
11
- AccountRole2[AccountRole2["WRITABLE"] = /* 1 */
12
- 1] = "WRITABLE";
13
- AccountRole2[AccountRole2["READONLY"] = /* 0 */
14
- 0] = "READONLY";
15
- return AccountRole2;
16
- })(AccountRole || {});
17
- var IS_SIGNER_BITMASK = 2;
18
- var IS_WRITABLE_BITMASK = 1;
19
- function downgradeRoleToNonSigner(role) {
20
- return role & ~IS_SIGNER_BITMASK;
21
- }
22
- function downgradeRoleToReadonly(role) {
23
- return role & ~IS_WRITABLE_BITMASK;
24
- }
25
- function isSignerRole(role) {
26
- return role >= 2 /* READONLY_SIGNER */;
27
- }
28
- function isWritableRole(role) {
29
- return (role & IS_WRITABLE_BITMASK) !== 0;
30
- }
31
- function mergeRoles(roleA, roleB) {
32
- return roleA | roleB;
33
- }
34
- function upgradeRoleToSigner(role) {
35
- return role | IS_SIGNER_BITMASK;
36
- }
37
- function upgradeRoleToWritable(role) {
38
- return role | IS_WRITABLE_BITMASK;
39
- }
40
-
41
- exports.AccountRole = AccountRole;
42
- exports.downgradeRoleToNonSigner = downgradeRoleToNonSigner;
43
- exports.downgradeRoleToReadonly = downgradeRoleToReadonly;
44
- exports.isSignerRole = isSignerRole;
45
- exports.isWritableRole = isWritableRole;
46
- exports.mergeRoles = mergeRoles;
47
- exports.upgradeRoleToSigner = upgradeRoleToSigner;
48
- exports.upgradeRoleToWritable = upgradeRoleToWritable;
49
-
50
- return exports;
51
-
52
- })({});
53
- //# sourceMappingURL=out.js.map
54
- //# sourceMappingURL=index.development.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/roles.ts"],"names":["AccountRole"],"mappings":";AAIO,IAAK,cAAL,kBAAKA,iBAAL;AAEH,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AACA,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AACA,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AACA,EAAAA,0BAAA;AAAA,EAA0B,KAA1B;AALQ,SAAAA;AAAA,GAAA;AAQZ,IAAM,oBAAoB;AAC1B,IAAM,sBAAsB;AAKrB,SAAS,yBAAyB,MAAgC;AACrE,SAAO,OAAO,CAAC;AACnB;AAKO,SAAS,wBAAwB,MAAgC;AACpE,SAAO,OAAO,CAAC;AACnB;AAEO,SAAS,aAAa,MAAsF;AAC/G,SAAO,QAAQ;AACnB;AAEO,SAAS,eAAe,MAA+E;AAC1G,UAAQ,OAAO,yBAAyB;AAC5C;AAYO,SAAS,WAAW,OAAoB,OAAiC;AAC5E,SAAO,QAAQ;AACnB;AAKO,SAAS,oBAAoB,MAAgC;AAChE,SAAO,OAAO;AAClB;AAKO,SAAS,sBAAsB,MAAgC;AAClE,SAAO,OAAO;AAClB","sourcesContent":["/**\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,18 +0,0 @@
1
- this.globalThis = this.globalThis || {};
2
- this.globalThis.solanaWeb3 = (function (exports) {
3
- 'use strict';
4
-
5
- var n=(e=>(e[e.WRITABLE_SIGNER=3]="WRITABLE_SIGNER",e[e.READONLY_SIGNER=2]="READONLY_SIGNER",e[e.WRITABLE=1]="WRITABLE",e[e.READONLY=0]="READONLY",e))(n||{});function l(o){return o&-3}function A(o){return o&-2}function r(o){return o>=2}function u(o){return (o&1)!==0}function E(o,R){return o|R}function I(o){return o|2}function N(o){return o|1}
6
-
7
- exports.AccountRole = n;
8
- exports.downgradeRoleToNonSigner = l;
9
- exports.downgradeRoleToReadonly = A;
10
- exports.isSignerRole = r;
11
- exports.isWritableRole = u;
12
- exports.mergeRoles = E;
13
- exports.upgradeRoleToSigner = I;
14
- exports.upgradeRoleToWritable = N;
15
-
16
- return exports;
17
-
18
- })({});