@solana/instructions 2.0.0-experimental.0099b2a
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/LICENSE +20 -0
- package/README.md +148 -0
- package/dist/index.browser.cjs +48 -0
- package/dist/index.browser.cjs.map +1 -0
- package/dist/index.browser.js +39 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/index.development.js +54 -0
- package/dist/index.development.js.map +1 -0
- package/dist/index.native.js +39 -0
- package/dist/index.native.js.map +1 -0
- package/dist/index.node.cjs +48 -0
- package/dist/index.node.cjs.map +1 -0
- package/dist/index.node.js +39 -0
- package/dist/index.node.js.map +1 -0
- package/dist/index.production.min.js +18 -0
- package/dist/types/accounts.d.ts +31 -0
- package/dist/types/accounts.d.ts.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/instruction.d.ts +14 -0
- package/dist/types/instruction.d.ts.map +1 -0
- package/dist/types/roles.d.ts +34 -0
- package/dist/types/roles.d.ts.map +1 -0
- package/package.json +92 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2023 Solana Labs, Inc
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
[![npm][npm-image]][npm-url]
|
|
2
|
+
[![npm-downloads][npm-downloads-image]][npm-url]
|
|
3
|
+
[![semantic-release][semantic-release-image]][semantic-release-url]
|
|
4
|
+
<br />
|
|
5
|
+
[![code-style-prettier][code-style-prettier-image]][code-style-prettier-url]
|
|
6
|
+
|
|
7
|
+
[code-style-prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square
|
|
8
|
+
[code-style-prettier-url]: https://github.com/prettier/prettier
|
|
9
|
+
[npm-downloads-image]: https://img.shields.io/npm/dm/@solana/instructions/experimental.svg?style=flat
|
|
10
|
+
[npm-image]: https://img.shields.io/npm/v/@solana/instructions/experimental.svg?style=flat
|
|
11
|
+
[npm-url]: https://www.npmjs.com/package/@solana/instructions/v/experimental
|
|
12
|
+
[semantic-release-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
|
|
13
|
+
[semantic-release-url]: https://github.com/semantic-release/semantic-release
|
|
14
|
+
|
|
15
|
+
# @solana/instructions
|
|
16
|
+
|
|
17
|
+
This package contains types for creating transaction instructions. It can be used standalone, but it is also exported as part of the Solana JavaScript SDK [`@solana/web3.js@experimental`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/library).
|
|
18
|
+
|
|
19
|
+
## Types
|
|
20
|
+
|
|
21
|
+
### `AccountRole`
|
|
22
|
+
|
|
23
|
+
The purpose for which an account participates in a transaction is described by the `AccountRole` type. Every account that participates in a transaction can be read from, but only ones that you mark as writable may be written to, and only ones that you indicate must sign the transaction will gain the privileges associated with signers at runtime.
|
|
24
|
+
|
|
25
|
+
| | `isSigner` | `isWritable` |
|
|
26
|
+
| ----------------------------- | ---------- | ------------ |
|
|
27
|
+
| `AccountRole.READONLY` | ❌ | ❌ |
|
|
28
|
+
| `AccountRole.WRITABLE` | ❌ | ✅ |
|
|
29
|
+
| `AccountRole.READONLY_SIGNER` | ✅ | ❌ |
|
|
30
|
+
| `AccountRole.WRITABLE_SIGNER` | ✅ | ✅ |
|
|
31
|
+
|
|
32
|
+
### `IAccountMeta<TAddress>`
|
|
33
|
+
|
|
34
|
+
This type represents an account's address and metadata about its mutability and whether it must be a signer of the transaction.
|
|
35
|
+
|
|
36
|
+
Typically, you will use one of its subtypes.
|
|
37
|
+
|
|
38
|
+
| | `role` | `isSigner` | `isWritable` |
|
|
39
|
+
| --------------------------------- | ----------------------------- | ---------- | ------------ |
|
|
40
|
+
| `ReadonlyAccount<TAddress>` | `AccountRole.READONLY` | ❌ | ❌ |
|
|
41
|
+
| `WritableAccount<TAddress>` | `AccountRole.WRITABLE` | ❌ | ✅ |
|
|
42
|
+
| `ReadonlySignerAccount<TAddress>` | `AccountRole.READONLY_SIGNER` | ✅ | ❌ |
|
|
43
|
+
| `WritableSignerAccount<TAddress>` | `AccountRole.WRITABLE_SIGNER` | ✅ | ✅ |
|
|
44
|
+
|
|
45
|
+
For example, you could type the rent sysvar account like this:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
type RentSysvar = ReadonlyAccount<'SysvarRent111111111111111111111111111111111'>;
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### `IAccountLookupMeta<TAddress, TLookupTableAddress>`
|
|
52
|
+
|
|
53
|
+
This type represents a lookup of the account's address in an address lookup table. It specifies which lookup table account in which to perform the lookup, the index of the desired account address in that table, and metadata about its mutability. Notably, account addresses obtained via lookups 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` | ❌ | ❌ |
|
|
60
|
+
| `WritableLookupAccount<TAddress, TLookupTableAddress>` | `AccountRole.WRITABLE` | ❌ | ✅ |
|
|
61
|
+
|
|
62
|
+
For example, you could type the rent sysvar account that you looked up in a lookup table like this:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
type RentSysvar = ReadonlyLookupAccount<
|
|
66
|
+
'SysvarRent111111111111111111111111111111111',
|
|
67
|
+
'MyLookupTable111111111111111111111111111111'
|
|
68
|
+
>;
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### `IInstruction<TProgramAddress>`
|
|
72
|
+
|
|
73
|
+
Use this to specify an instruction destined for a given program.
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
type StakeProgramInstruction = IInstruction<'StakeConfig11111111111111111111111111111111'>;
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### `IInstructionWithAccounts<TAccounts>`
|
|
80
|
+
|
|
81
|
+
Use this type to specify an instruction that contains certain accounts.
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
type InstructionWithTwoAccounts = IInstructionWithAccounts<
|
|
85
|
+
[
|
|
86
|
+
WritableAccount, // First account
|
|
87
|
+
RentSysvar // Second account
|
|
88
|
+
]
|
|
89
|
+
>;
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### `IInstructionWithData<TData>`
|
|
93
|
+
|
|
94
|
+
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.
|
|
95
|
+
|
|
96
|
+
For example, here is how the `AdvanceNonce` instruction is typed.
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
type AdvanceNonceAccountInstruction<
|
|
100
|
+
TNonceAccountAddress extends string = string,
|
|
101
|
+
TNonceAuthorityAddress extends string = string
|
|
102
|
+
> = IInstruction<'11111111111111111111111111111111'> &
|
|
103
|
+
IInstructionWithAccounts<
|
|
104
|
+
[
|
|
105
|
+
WritableAccount<TNonceAccountAddress>,
|
|
106
|
+
ReadonlyAccount<'SysvarRecentB1ockHashes11111111111111111111'>,
|
|
107
|
+
ReadonlySignerAccount<TNonceAuthorityAddress>
|
|
108
|
+
]
|
|
109
|
+
> &
|
|
110
|
+
IInstructionWithData<AdvanceNonceAccountInstructionData>;
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Functions
|
|
114
|
+
|
|
115
|
+
### `isSignerRole(role: AccountRole)`
|
|
116
|
+
|
|
117
|
+
Returns `true` if the `AccountRole` given represents that of a signer. Also refines the TypeScript type of the supplied role.
|
|
118
|
+
|
|
119
|
+
### `isWritable(role: AccountRole)`
|
|
120
|
+
|
|
121
|
+
Returns `true` if the `AccountRole` given represents that of a writable account. Also refines the TypeScript type of the supplied role.
|
|
122
|
+
|
|
123
|
+
### `mergeRoles(roleA: AccountRole, roleB: AccountRole)`
|
|
124
|
+
|
|
125
|
+
Given two `AccountRoles`, will return the `AccountRole` that grants the highest privileges of both.
|
|
126
|
+
|
|
127
|
+
Example:
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
// Returns `AccountRole.WRITABLE_SIGNER`
|
|
131
|
+
mergeRoles(AccountRole.READONLY_SIGNER, AccountRole.WRITABLE);
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### `downgradeRoleToNonSigner(role: AccountRole)`
|
|
135
|
+
|
|
136
|
+
Returns an `AccountRole` representing the non-signer variant of the supplied role.
|
|
137
|
+
|
|
138
|
+
### `downgradeRoleToReadonly(role: AccountRole)`
|
|
139
|
+
|
|
140
|
+
Returns an `AccountRole` representing the non-writable variant of the supplied role.
|
|
141
|
+
|
|
142
|
+
### `upgradeRoleToSigner(role: AccountRole)`
|
|
143
|
+
|
|
144
|
+
Returns an `AccountRole` representing the signer variant of the supplied role.
|
|
145
|
+
|
|
146
|
+
### `upgradeRoleToWritable(role: AccountRole)`
|
|
147
|
+
|
|
148
|
+
Returns an `AccountRole` representing the writable variant of the supplied role.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/roles.ts
|
|
4
|
+
var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
|
|
5
|
+
AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
|
|
6
|
+
3] = "WRITABLE_SIGNER";
|
|
7
|
+
AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */
|
|
8
|
+
2] = "READONLY_SIGNER";
|
|
9
|
+
AccountRole2[AccountRole2["WRITABLE"] = /* 1 */
|
|
10
|
+
1] = "WRITABLE";
|
|
11
|
+
AccountRole2[AccountRole2["READONLY"] = /* 0 */
|
|
12
|
+
0] = "READONLY";
|
|
13
|
+
return AccountRole2;
|
|
14
|
+
})(AccountRole || {});
|
|
15
|
+
var IS_SIGNER_BITMASK = 2;
|
|
16
|
+
var IS_WRITABLE_BITMASK = 1;
|
|
17
|
+
function downgradeRoleToNonSigner(role) {
|
|
18
|
+
return role & ~IS_SIGNER_BITMASK;
|
|
19
|
+
}
|
|
20
|
+
function downgradeRoleToReadonly(role) {
|
|
21
|
+
return role & ~IS_WRITABLE_BITMASK;
|
|
22
|
+
}
|
|
23
|
+
function isSignerRole(role) {
|
|
24
|
+
return role >= 2 /* READONLY_SIGNER */;
|
|
25
|
+
}
|
|
26
|
+
function isWritableRole(role) {
|
|
27
|
+
return (role & IS_WRITABLE_BITMASK) !== 0;
|
|
28
|
+
}
|
|
29
|
+
function mergeRoles(roleA, roleB) {
|
|
30
|
+
return roleA | roleB;
|
|
31
|
+
}
|
|
32
|
+
function upgradeRoleToSigner(role) {
|
|
33
|
+
return role | IS_SIGNER_BITMASK;
|
|
34
|
+
}
|
|
35
|
+
function upgradeRoleToWritable(role) {
|
|
36
|
+
return role | IS_WRITABLE_BITMASK;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
exports.AccountRole = AccountRole;
|
|
40
|
+
exports.downgradeRoleToNonSigner = downgradeRoleToNonSigner;
|
|
41
|
+
exports.downgradeRoleToReadonly = downgradeRoleToReadonly;
|
|
42
|
+
exports.isSignerRole = isSignerRole;
|
|
43
|
+
exports.isWritableRole = isWritableRole;
|
|
44
|
+
exports.mergeRoles = mergeRoles;
|
|
45
|
+
exports.upgradeRoleToSigner = upgradeRoleToSigner;
|
|
46
|
+
exports.upgradeRoleToWritable = upgradeRoleToWritable;
|
|
47
|
+
//# sourceMappingURL=out.js.map
|
|
48
|
+
//# sourceMappingURL=index.browser.cjs.map
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/roles.ts
|
|
2
|
+
var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
|
|
3
|
+
AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
|
|
4
|
+
3] = "WRITABLE_SIGNER";
|
|
5
|
+
AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */
|
|
6
|
+
2] = "READONLY_SIGNER";
|
|
7
|
+
AccountRole2[AccountRole2["WRITABLE"] = /* 1 */
|
|
8
|
+
1] = "WRITABLE";
|
|
9
|
+
AccountRole2[AccountRole2["READONLY"] = /* 0 */
|
|
10
|
+
0] = "READONLY";
|
|
11
|
+
return AccountRole2;
|
|
12
|
+
})(AccountRole || {});
|
|
13
|
+
var IS_SIGNER_BITMASK = 2;
|
|
14
|
+
var IS_WRITABLE_BITMASK = 1;
|
|
15
|
+
function downgradeRoleToNonSigner(role) {
|
|
16
|
+
return role & ~IS_SIGNER_BITMASK;
|
|
17
|
+
}
|
|
18
|
+
function downgradeRoleToReadonly(role) {
|
|
19
|
+
return role & ~IS_WRITABLE_BITMASK;
|
|
20
|
+
}
|
|
21
|
+
function isSignerRole(role) {
|
|
22
|
+
return role >= 2 /* READONLY_SIGNER */;
|
|
23
|
+
}
|
|
24
|
+
function isWritableRole(role) {
|
|
25
|
+
return (role & IS_WRITABLE_BITMASK) !== 0;
|
|
26
|
+
}
|
|
27
|
+
function mergeRoles(roleA, roleB) {
|
|
28
|
+
return roleA | roleB;
|
|
29
|
+
}
|
|
30
|
+
function upgradeRoleToSigner(role) {
|
|
31
|
+
return role | IS_SIGNER_BITMASK;
|
|
32
|
+
}
|
|
33
|
+
function upgradeRoleToWritable(role) {
|
|
34
|
+
return role | IS_WRITABLE_BITMASK;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { AccountRole, downgradeRoleToNonSigner, downgradeRoleToReadonly, isSignerRole, isWritableRole, mergeRoles, upgradeRoleToSigner, upgradeRoleToWritable };
|
|
38
|
+
//# sourceMappingURL=out.js.map
|
|
39
|
+
//# sourceMappingURL=index.browser.js.map
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/roles.ts
|
|
2
|
+
var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
|
|
3
|
+
AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
|
|
4
|
+
3] = "WRITABLE_SIGNER";
|
|
5
|
+
AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */
|
|
6
|
+
2] = "READONLY_SIGNER";
|
|
7
|
+
AccountRole2[AccountRole2["WRITABLE"] = /* 1 */
|
|
8
|
+
1] = "WRITABLE";
|
|
9
|
+
AccountRole2[AccountRole2["READONLY"] = /* 0 */
|
|
10
|
+
0] = "READONLY";
|
|
11
|
+
return AccountRole2;
|
|
12
|
+
})(AccountRole || {});
|
|
13
|
+
var IS_SIGNER_BITMASK = 2;
|
|
14
|
+
var IS_WRITABLE_BITMASK = 1;
|
|
15
|
+
function downgradeRoleToNonSigner(role) {
|
|
16
|
+
return role & ~IS_SIGNER_BITMASK;
|
|
17
|
+
}
|
|
18
|
+
function downgradeRoleToReadonly(role) {
|
|
19
|
+
return role & ~IS_WRITABLE_BITMASK;
|
|
20
|
+
}
|
|
21
|
+
function isSignerRole(role) {
|
|
22
|
+
return role >= 2 /* READONLY_SIGNER */;
|
|
23
|
+
}
|
|
24
|
+
function isWritableRole(role) {
|
|
25
|
+
return (role & IS_WRITABLE_BITMASK) !== 0;
|
|
26
|
+
}
|
|
27
|
+
function mergeRoles(roleA, roleB) {
|
|
28
|
+
return roleA | roleB;
|
|
29
|
+
}
|
|
30
|
+
function upgradeRoleToSigner(role) {
|
|
31
|
+
return role | IS_SIGNER_BITMASK;
|
|
32
|
+
}
|
|
33
|
+
function upgradeRoleToWritable(role) {
|
|
34
|
+
return role | IS_WRITABLE_BITMASK;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { AccountRole, downgradeRoleToNonSigner, downgradeRoleToReadonly, isSignerRole, isWritableRole, mergeRoles, upgradeRoleToSigner, upgradeRoleToWritable };
|
|
38
|
+
//# sourceMappingURL=out.js.map
|
|
39
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/roles.ts
|
|
4
|
+
var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
|
|
5
|
+
AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
|
|
6
|
+
3] = "WRITABLE_SIGNER";
|
|
7
|
+
AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */
|
|
8
|
+
2] = "READONLY_SIGNER";
|
|
9
|
+
AccountRole2[AccountRole2["WRITABLE"] = /* 1 */
|
|
10
|
+
1] = "WRITABLE";
|
|
11
|
+
AccountRole2[AccountRole2["READONLY"] = /* 0 */
|
|
12
|
+
0] = "READONLY";
|
|
13
|
+
return AccountRole2;
|
|
14
|
+
})(AccountRole || {});
|
|
15
|
+
var IS_SIGNER_BITMASK = 2;
|
|
16
|
+
var IS_WRITABLE_BITMASK = 1;
|
|
17
|
+
function downgradeRoleToNonSigner(role) {
|
|
18
|
+
return role & ~IS_SIGNER_BITMASK;
|
|
19
|
+
}
|
|
20
|
+
function downgradeRoleToReadonly(role) {
|
|
21
|
+
return role & ~IS_WRITABLE_BITMASK;
|
|
22
|
+
}
|
|
23
|
+
function isSignerRole(role) {
|
|
24
|
+
return role >= 2 /* READONLY_SIGNER */;
|
|
25
|
+
}
|
|
26
|
+
function isWritableRole(role) {
|
|
27
|
+
return (role & IS_WRITABLE_BITMASK) !== 0;
|
|
28
|
+
}
|
|
29
|
+
function mergeRoles(roleA, roleB) {
|
|
30
|
+
return roleA | roleB;
|
|
31
|
+
}
|
|
32
|
+
function upgradeRoleToSigner(role) {
|
|
33
|
+
return role | IS_SIGNER_BITMASK;
|
|
34
|
+
}
|
|
35
|
+
function upgradeRoleToWritable(role) {
|
|
36
|
+
return role | IS_WRITABLE_BITMASK;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
exports.AccountRole = AccountRole;
|
|
40
|
+
exports.downgradeRoleToNonSigner = downgradeRoleToNonSigner;
|
|
41
|
+
exports.downgradeRoleToReadonly = downgradeRoleToReadonly;
|
|
42
|
+
exports.isSignerRole = isSignerRole;
|
|
43
|
+
exports.isWritableRole = isWritableRole;
|
|
44
|
+
exports.mergeRoles = mergeRoles;
|
|
45
|
+
exports.upgradeRoleToSigner = upgradeRoleToSigner;
|
|
46
|
+
exports.upgradeRoleToWritable = upgradeRoleToWritable;
|
|
47
|
+
//# sourceMappingURL=out.js.map
|
|
48
|
+
//# sourceMappingURL=index.node.cjs.map
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/roles.ts
|
|
2
|
+
var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
|
|
3
|
+
AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
|
|
4
|
+
3] = "WRITABLE_SIGNER";
|
|
5
|
+
AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */
|
|
6
|
+
2] = "READONLY_SIGNER";
|
|
7
|
+
AccountRole2[AccountRole2["WRITABLE"] = /* 1 */
|
|
8
|
+
1] = "WRITABLE";
|
|
9
|
+
AccountRole2[AccountRole2["READONLY"] = /* 0 */
|
|
10
|
+
0] = "READONLY";
|
|
11
|
+
return AccountRole2;
|
|
12
|
+
})(AccountRole || {});
|
|
13
|
+
var IS_SIGNER_BITMASK = 2;
|
|
14
|
+
var IS_WRITABLE_BITMASK = 1;
|
|
15
|
+
function downgradeRoleToNonSigner(role) {
|
|
16
|
+
return role & ~IS_SIGNER_BITMASK;
|
|
17
|
+
}
|
|
18
|
+
function downgradeRoleToReadonly(role) {
|
|
19
|
+
return role & ~IS_WRITABLE_BITMASK;
|
|
20
|
+
}
|
|
21
|
+
function isSignerRole(role) {
|
|
22
|
+
return role >= 2 /* READONLY_SIGNER */;
|
|
23
|
+
}
|
|
24
|
+
function isWritableRole(role) {
|
|
25
|
+
return (role & IS_WRITABLE_BITMASK) !== 0;
|
|
26
|
+
}
|
|
27
|
+
function mergeRoles(roleA, roleB) {
|
|
28
|
+
return roleA | roleB;
|
|
29
|
+
}
|
|
30
|
+
function upgradeRoleToSigner(role) {
|
|
31
|
+
return role | IS_SIGNER_BITMASK;
|
|
32
|
+
}
|
|
33
|
+
function upgradeRoleToWritable(role) {
|
|
34
|
+
return role | IS_WRITABLE_BITMASK;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { AccountRole, downgradeRoleToNonSigner, downgradeRoleToReadonly, isSignerRole, isWritableRole, mergeRoles, upgradeRoleToSigner, upgradeRoleToWritable };
|
|
38
|
+
//# sourceMappingURL=out.js.map
|
|
39
|
+
//# sourceMappingURL=index.node.js.map
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
})({});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Base58EncodedAddress } from '@solana/addresses';
|
|
2
|
+
import { AccountRole } from './roles';
|
|
3
|
+
export interface IAccountMeta<TAddress extends string = string> {
|
|
4
|
+
readonly address: Base58EncodedAddress<TAddress>;
|
|
5
|
+
readonly role: AccountRole;
|
|
6
|
+
}
|
|
7
|
+
export type ReadonlyAccount<TAddress extends string = string> = IAccountMeta<TAddress> & {
|
|
8
|
+
readonly role: AccountRole.READONLY;
|
|
9
|
+
};
|
|
10
|
+
export type WritableAccount<TAddress extends string = string> = IAccountMeta<TAddress> & {
|
|
11
|
+
role: AccountRole.WRITABLE;
|
|
12
|
+
};
|
|
13
|
+
export type ReadonlySignerAccount<TAddress extends string = string> = IAccountMeta<TAddress> & {
|
|
14
|
+
role: AccountRole.READONLY_SIGNER;
|
|
15
|
+
};
|
|
16
|
+
export type WritableSignerAccount<TAddress extends string = string> = IAccountMeta<TAddress> & {
|
|
17
|
+
role: AccountRole.WRITABLE_SIGNER;
|
|
18
|
+
};
|
|
19
|
+
export interface IAccountLookupMeta<TAddress extends string = string, TLookupTableAddress extends string = string> {
|
|
20
|
+
readonly address: Base58EncodedAddress<TAddress>;
|
|
21
|
+
readonly addressIndex: number;
|
|
22
|
+
readonly lookupTableAddress: Base58EncodedAddress<TLookupTableAddress>;
|
|
23
|
+
readonly role: AccountRole.READONLY | AccountRole.WRITABLE;
|
|
24
|
+
}
|
|
25
|
+
export type ReadonlyAccountLookup<TAddress extends string = string, TLookupTableAddress extends string = string> = IAccountLookupMeta<TAddress, TLookupTableAddress> & {
|
|
26
|
+
readonly role: AccountRole.READONLY;
|
|
27
|
+
};
|
|
28
|
+
export type WritableAccountLookup<TAddress extends string = string, TLookupTableAddress extends string = string> = IAccountLookupMeta<TAddress, TLookupTableAddress> & {
|
|
29
|
+
readonly role: AccountRole.WRITABLE;
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=accounts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../../src/accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,MAAM,WAAW,YAAY,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM;IAC1D,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IACjD,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,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IACjD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,kBAAkB,EAAE,oBAAoB,CAAC,mBAAmB,CAAC,CAAC;IACvE,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"}
|
|
@@ -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"}
|
|
@@ -0,0 +1,14 @@
|
|
|
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)[];
|
|
5
|
+
readonly data?: Uint8Array;
|
|
6
|
+
readonly programAddress: Base58EncodedAddress<TProgramAddress>;
|
|
7
|
+
}
|
|
8
|
+
export interface IInstructionWithAccounts<TAccounts extends readonly (IAccountMeta | IAccountLookupMeta)[]> extends IInstruction {
|
|
9
|
+
readonly accounts: TAccounts;
|
|
10
|
+
}
|
|
11
|
+
export interface IInstructionWithData<TData extends Uint8Array> extends IInstruction {
|
|
12
|
+
readonly data: TData;
|
|
13
|
+
}
|
|
14
|
+
//# 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,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE9D,MAAM,WAAW,YAAY,CAAC,eAAe,SAAS,MAAM,GAAG,MAAM;IACjE,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC,YAAY,GAAG,kBAAkB,CAAC,EAAE,CAAC;IACnE,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,cAAc,EAAE,oBAAoB,CAAC,eAAe,CAAC,CAAC;CAClE;AAED,MAAM,WAAW,wBAAwB,CAAC,SAAS,SAAS,SAAS,CAAC,YAAY,GAAG,kBAAkB,CAAC,EAAE,CACtG,SAAQ,YAAY;IACpB,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;CAChC;AAED,MAAM,WAAW,oBAAoB,CAAC,KAAK,SAAS,UAAU,CAAE,SAAQ,YAAY;IAChF,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;CACxB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quick primer on bitwise operations: https://stackoverflow.com/a/1436448/802047
|
|
3
|
+
*/
|
|
4
|
+
export declare enum AccountRole {
|
|
5
|
+
WRITABLE_SIGNER = 3,
|
|
6
|
+
READONLY_SIGNER = 2,
|
|
7
|
+
WRITABLE = 1,
|
|
8
|
+
READONLY = 0
|
|
9
|
+
}
|
|
10
|
+
export declare function downgradeRoleToNonSigner(role: AccountRole.READONLY_SIGNER): AccountRole.READONLY;
|
|
11
|
+
export declare function downgradeRoleToNonSigner(role: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE;
|
|
12
|
+
export declare function downgradeRoleToNonSigner(role: AccountRole): AccountRole;
|
|
13
|
+
export declare function downgradeRoleToReadonly(role: AccountRole.WRITABLE): AccountRole.READONLY;
|
|
14
|
+
export declare function downgradeRoleToReadonly(role: AccountRole.WRITABLE_SIGNER): AccountRole.READONLY_SIGNER;
|
|
15
|
+
export declare function downgradeRoleToReadonly(role: AccountRole): AccountRole;
|
|
16
|
+
export declare function isSignerRole(role: AccountRole): role is AccountRole.READONLY_SIGNER | AccountRole.WRITABLE_SIGNER;
|
|
17
|
+
export declare function isWritableRole(role: AccountRole): role is AccountRole.WRITABLE | AccountRole.WRITABLE_SIGNER;
|
|
18
|
+
export declare function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER;
|
|
19
|
+
export declare function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER;
|
|
20
|
+
export declare function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE_SIGNER): AccountRole.WRITABLE_SIGNER;
|
|
21
|
+
export declare function mergeRoles(roleA: AccountRole.WRITABLE_SIGNER, roleB: AccountRole): AccountRole.WRITABLE_SIGNER;
|
|
22
|
+
export declare function mergeRoles(roleA: AccountRole, roleB: AccountRole.READONLY_SIGNER): AccountRole.READONLY_SIGNER;
|
|
23
|
+
export declare function mergeRoles(roleA: AccountRole.READONLY_SIGNER, roleB: AccountRole): AccountRole.READONLY_SIGNER;
|
|
24
|
+
export declare function mergeRoles(roleA: AccountRole, roleB: AccountRole.WRITABLE): AccountRole.WRITABLE;
|
|
25
|
+
export declare function mergeRoles(roleA: AccountRole.WRITABLE, roleB: AccountRole): AccountRole.WRITABLE;
|
|
26
|
+
export declare function mergeRoles(roleA: AccountRole.READONLY, roleB: AccountRole.READONLY): AccountRole.READONLY;
|
|
27
|
+
export declare function mergeRoles(roleA: AccountRole, roleB: AccountRole): AccountRole;
|
|
28
|
+
export declare function upgradeRoleToSigner(role: AccountRole.READONLY): AccountRole.READONLY_SIGNER;
|
|
29
|
+
export declare function upgradeRoleToSigner(role: AccountRole.WRITABLE): AccountRole.WRITABLE_SIGNER;
|
|
30
|
+
export declare function upgradeRoleToSigner(role: AccountRole): AccountRole;
|
|
31
|
+
export declare function upgradeRoleToWritable(role: AccountRole.READONLY): AccountRole.WRITABLE;
|
|
32
|
+
export declare function upgradeRoleToWritable(role: AccountRole.READONLY_SIGNER): AccountRole.WRITABLE_SIGNER;
|
|
33
|
+
export declare function upgradeRoleToWritable(role: AccountRole): AccountRole;
|
|
34
|
+
//# sourceMappingURL=roles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roles.d.ts","sourceRoot":"","sources":["../../src/roles.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,oBAAY,WAAW;IAEnB,eAAe,IAAe;IAC9B,eAAe,IAAe;IAC9B,QAAQ,IAAsB;IAC9B,QAAQ,IAAsB;CACjC;AAKD,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,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC;AAC1F,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,WAAW,CAAC,eAAe,GAAG,WAAW,CAAC,eAAe,CAAC;AACxG,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,WAAW,GAAG,WAAW,CAAC;AAKxE,wBAAgB,YAAY,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,IAAI,WAAW,CAAC,eAAe,GAAG,WAAW,CAAC,eAAe,CAEjH;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,IAAI,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC,eAAe,CAE5G;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC,QAAQ,EAAE,KAAK,EAAE,WAAW,CAAC,eAAe,GAAG,WAAW,CAAC,eAAe,CAAC;AACzH,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC,eAAe,EAAE,KAAK,EAAE,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC,eAAe,CAAC;AACzH,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,CAAC,eAAe,GAAG,WAAW,CAAC,eAAe,CAAC;AAChH,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC,eAAe,EAAE,KAAK,EAAE,WAAW,GAAG,WAAW,CAAC,eAAe,CAAC;AAChH,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,CAAC,eAAe,GAAG,WAAW,CAAC,eAAe,CAAC;AAChH,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC,eAAe,EAAE,KAAK,EAAE,WAAW,GAAG,WAAW,CAAC,eAAe,CAAC;AAChH,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC;AAClG,wBAAgB,UAAU,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,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,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
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@solana/instructions",
|
|
3
|
+
"version": "2.0.0-experimental.0099b2a",
|
|
4
|
+
"description": "Helpers for creating transaction instructions",
|
|
5
|
+
"exports": {
|
|
6
|
+
"browser": {
|
|
7
|
+
"import": "./dist/index.browser.js",
|
|
8
|
+
"require": "./dist/index.browser.cjs"
|
|
9
|
+
},
|
|
10
|
+
"node": {
|
|
11
|
+
"import": "./dist/index.node.js",
|
|
12
|
+
"require": "./dist/index.node.cjs"
|
|
13
|
+
},
|
|
14
|
+
"react-native": "./dist/index.native.js",
|
|
15
|
+
"types": "./dist/types/index.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"browser": {
|
|
18
|
+
"./dist/index.node.cjs": "./dist/index.browser.cjs",
|
|
19
|
+
"./dist/index.node.js": "./dist/index.browser.js"
|
|
20
|
+
},
|
|
21
|
+
"main": "./dist/index.node.cjs",
|
|
22
|
+
"module": "./dist/index.node.js",
|
|
23
|
+
"react-native": "./dist/index.native.js",
|
|
24
|
+
"types": "./dist/types/index.d.ts",
|
|
25
|
+
"type": "module",
|
|
26
|
+
"files": [
|
|
27
|
+
"./dist/"
|
|
28
|
+
],
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"keywords": [
|
|
31
|
+
"blockchain",
|
|
32
|
+
"solana",
|
|
33
|
+
"web3"
|
|
34
|
+
],
|
|
35
|
+
"author": "Solana Labs Maintainers <maintainers@solanalabs.com>",
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "https://github.com/solana-labs/solana-web3.js"
|
|
40
|
+
},
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "http://github.com/solana-labs/solana-web3.js/issues"
|
|
43
|
+
},
|
|
44
|
+
"browserslist": [
|
|
45
|
+
"supports bigint and not dead",
|
|
46
|
+
"maintained node versions"
|
|
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.0099b2a",
|
|
65
|
+
"build-scripts": "0.0.0",
|
|
66
|
+
"test-config": "0.0.0",
|
|
67
|
+
"tsconfig": "0.0.0"
|
|
68
|
+
},
|
|
69
|
+
"bundlewatch": {
|
|
70
|
+
"defaultCompression": "gzip",
|
|
71
|
+
"files": [
|
|
72
|
+
{
|
|
73
|
+
"path": "./dist/index*.js"
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
"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",
|
|
82
|
+
"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",
|
|
85
|
+
"test:treeshakability:browser": "agadoo dist/index.browser.js",
|
|
86
|
+
"test:treeshakability:native": "agadoo dist/index.native.js",
|
|
87
|
+
"test:treeshakability:node": "agadoo dist/index.node.js",
|
|
88
|
+
"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"
|
|
91
|
+
}
|
|
92
|
+
}
|