@solana/instructions
Advanced tools
Comparing version 2.0.0-experimental.b8df7b4 to 2.0.0-experimental.d1e0dc6
@@ -0,3 +1,39 @@ | ||
// src/roles.ts | ||
var AccountRole = /* @__PURE__ */ ((AccountRole2) => { | ||
AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */ | ||
3] = "WRITABLE_SIGNER"; | ||
AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */ | ||
2] = "READONLY_SIGNER"; | ||
AccountRole2[AccountRole2["WRITABLE"] = /* 1 */ | ||
1] = "WRITABLE"; | ||
AccountRole2[AccountRole2["READONLY"] = /* 0 */ | ||
0] = "READONLY"; | ||
return AccountRole2; | ||
})(AccountRole || {}); | ||
var IS_SIGNER_BITMASK = 2; | ||
var IS_WRITABLE_BITMASK = 1; | ||
function downgradeRoleToNonSigner(role) { | ||
return role & ~IS_SIGNER_BITMASK; | ||
} | ||
function downgradeRoleToReadonly(role) { | ||
return role & ~IS_WRITABLE_BITMASK; | ||
} | ||
function isSignerRole(role) { | ||
return role >= 2 /* READONLY_SIGNER */; | ||
} | ||
function isWritableRole(role) { | ||
return (role & IS_WRITABLE_BITMASK) !== 0; | ||
} | ||
function mergeRoles(roleA, roleB) { | ||
return roleA | roleB; | ||
} | ||
function upgradeRoleToSigner(role) { | ||
return role | IS_SIGNER_BITMASK; | ||
} | ||
function upgradeRoleToWritable(role) { | ||
return role | IS_WRITABLE_BITMASK; | ||
} | ||
export { AccountRole, downgradeRoleToNonSigner, downgradeRoleToReadonly, isSignerRole, isWritableRole, mergeRoles, upgradeRoleToSigner, upgradeRoleToWritable }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.browser.js.map |
@@ -1,8 +0,54 @@ | ||
(function () { | ||
'use strict'; | ||
this.globalThis = this.globalThis || {}; | ||
this.globalThis.solanaWeb3 = (function (exports) { | ||
'use strict'; | ||
// src/roles.ts | ||
var AccountRole = /* @__PURE__ */ ((AccountRole2) => { | ||
AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */ | ||
3] = "WRITABLE_SIGNER"; | ||
AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */ | ||
2] = "READONLY_SIGNER"; | ||
AccountRole2[AccountRole2["WRITABLE"] = /* 1 */ | ||
1] = "WRITABLE"; | ||
AccountRole2[AccountRole2["READONLY"] = /* 0 */ | ||
0] = "READONLY"; | ||
return AccountRole2; | ||
})(AccountRole || {}); | ||
var IS_SIGNER_BITMASK = 2; | ||
var IS_WRITABLE_BITMASK = 1; | ||
function downgradeRoleToNonSigner(role) { | ||
return role & ~IS_SIGNER_BITMASK; | ||
} | ||
function downgradeRoleToReadonly(role) { | ||
return role & ~IS_WRITABLE_BITMASK; | ||
} | ||
function isSignerRole(role) { | ||
return role >= 2 /* READONLY_SIGNER */; | ||
} | ||
function isWritableRole(role) { | ||
return (role & IS_WRITABLE_BITMASK) !== 0; | ||
} | ||
function mergeRoles(roleA, roleB) { | ||
return roleA | roleB; | ||
} | ||
function upgradeRoleToSigner(role) { | ||
return role | IS_SIGNER_BITMASK; | ||
} | ||
function upgradeRoleToWritable(role) { | ||
return role | IS_WRITABLE_BITMASK; | ||
} | ||
exports.AccountRole = AccountRole; | ||
exports.downgradeRoleToNonSigner = downgradeRoleToNonSigner; | ||
exports.downgradeRoleToReadonly = downgradeRoleToReadonly; | ||
exports.isSignerRole = isSignerRole; | ||
exports.isWritableRole = isWritableRole; | ||
exports.mergeRoles = mergeRoles; | ||
exports.upgradeRoleToSigner = upgradeRoleToSigner; | ||
exports.upgradeRoleToWritable = upgradeRoleToWritable; | ||
})(); | ||
return exports; | ||
})({}); | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.development.js.map |
@@ -0,3 +1,39 @@ | ||
// src/roles.ts | ||
var AccountRole = /* @__PURE__ */ ((AccountRole2) => { | ||
AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */ | ||
3] = "WRITABLE_SIGNER"; | ||
AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */ | ||
2] = "READONLY_SIGNER"; | ||
AccountRole2[AccountRole2["WRITABLE"] = /* 1 */ | ||
1] = "WRITABLE"; | ||
AccountRole2[AccountRole2["READONLY"] = /* 0 */ | ||
0] = "READONLY"; | ||
return AccountRole2; | ||
})(AccountRole || {}); | ||
var IS_SIGNER_BITMASK = 2; | ||
var IS_WRITABLE_BITMASK = 1; | ||
function downgradeRoleToNonSigner(role) { | ||
return role & ~IS_SIGNER_BITMASK; | ||
} | ||
function downgradeRoleToReadonly(role) { | ||
return role & ~IS_WRITABLE_BITMASK; | ||
} | ||
function isSignerRole(role) { | ||
return role >= 2 /* READONLY_SIGNER */; | ||
} | ||
function isWritableRole(role) { | ||
return (role & IS_WRITABLE_BITMASK) !== 0; | ||
} | ||
function mergeRoles(roleA, roleB) { | ||
return roleA | roleB; | ||
} | ||
function upgradeRoleToSigner(role) { | ||
return role | IS_SIGNER_BITMASK; | ||
} | ||
function upgradeRoleToWritable(role) { | ||
return role | IS_WRITABLE_BITMASK; | ||
} | ||
export { AccountRole, downgradeRoleToNonSigner, downgradeRoleToReadonly, isSignerRole, isWritableRole, mergeRoles, upgradeRoleToSigner, upgradeRoleToWritable }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.native.js.map |
@@ -0,3 +1,39 @@ | ||
// src/roles.ts | ||
var AccountRole = /* @__PURE__ */ ((AccountRole2) => { | ||
AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */ | ||
3] = "WRITABLE_SIGNER"; | ||
AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */ | ||
2] = "READONLY_SIGNER"; | ||
AccountRole2[AccountRole2["WRITABLE"] = /* 1 */ | ||
1] = "WRITABLE"; | ||
AccountRole2[AccountRole2["READONLY"] = /* 0 */ | ||
0] = "READONLY"; | ||
return AccountRole2; | ||
})(AccountRole || {}); | ||
var IS_SIGNER_BITMASK = 2; | ||
var IS_WRITABLE_BITMASK = 1; | ||
function downgradeRoleToNonSigner(role) { | ||
return role & ~IS_SIGNER_BITMASK; | ||
} | ||
function downgradeRoleToReadonly(role) { | ||
return role & ~IS_WRITABLE_BITMASK; | ||
} | ||
function isSignerRole(role) { | ||
return role >= 2 /* READONLY_SIGNER */; | ||
} | ||
function isWritableRole(role) { | ||
return (role & IS_WRITABLE_BITMASK) !== 0; | ||
} | ||
function mergeRoles(roleA, roleB) { | ||
return roleA | roleB; | ||
} | ||
function upgradeRoleToSigner(role) { | ||
return role | IS_SIGNER_BITMASK; | ||
} | ||
function upgradeRoleToWritable(role) { | ||
return role | IS_WRITABLE_BITMASK; | ||
} | ||
export { AccountRole, downgradeRoleToNonSigner, downgradeRoleToReadonly, isSignerRole, isWritableRole, mergeRoles, upgradeRoleToSigner, upgradeRoleToWritable }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.node.js.map |
@@ -1,6 +0,18 @@ | ||
(function () { | ||
this.globalThis = this.globalThis || {}; | ||
this.globalThis.solanaWeb3 = (function (exports) { | ||
'use strict'; | ||
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} | ||
exports.AccountRole = n; | ||
exports.downgradeRoleToNonSigner = l; | ||
exports.downgradeRoleToReadonly = A; | ||
exports.isSignerRole = r; | ||
exports.isWritableRole = u; | ||
exports.mergeRoles = E; | ||
exports.upgradeRoleToSigner = I; | ||
exports.upgradeRoleToWritable = N; | ||
})(); | ||
return exports; | ||
})({}); |
import { Base58EncodedAddress } from '@solana/keys'; | ||
import { AccountRole } from './roles'; | ||
export interface IAccountMeta<TAddress extends string = string> { | ||
readonly address: Base58EncodedAddress<TAddress>; | ||
readonly isSigner: boolean; | ||
readonly isWritable: boolean; | ||
readonly role: AccountRole; | ||
} | ||
export type ReadonlyAccount<TAddress extends string = string> = IAccountMeta<TAddress> & Readonly<{ | ||
isSigner: false; | ||
isWritable: false; | ||
}>; | ||
export type WritableAccount<TAddress extends string = string> = IAccountMeta<TAddress> & Readonly<{ | ||
isSigner: false; | ||
isWritable: true; | ||
}>; | ||
export type ReadonlySignerAccount<TAddress extends string = string> = IAccountMeta<TAddress> & Readonly<{ | ||
isSigner: true; | ||
isWritable: false; | ||
}>; | ||
export type WritableSignerAccount<TAddress extends string = string> = IAccountMeta<TAddress> & Readonly<{ | ||
isSigner: true; | ||
isWritable: true; | ||
}>; | ||
export type ReadonlyAccount<TAddress extends string = string> = IAccountMeta<TAddress> & { | ||
readonly role: AccountRole.READONLY; | ||
}; | ||
export type WritableAccount<TAddress extends string = string> = IAccountMeta<TAddress> & { | ||
role: AccountRole.WRITABLE; | ||
}; | ||
export type ReadonlySignerAccount<TAddress extends string = string> = IAccountMeta<TAddress> & { | ||
role: AccountRole.READONLY_SIGNER; | ||
}; | ||
export type WritableSignerAccount<TAddress extends string = string> = IAccountMeta<TAddress> & { | ||
role: AccountRole.WRITABLE_SIGNER; | ||
}; | ||
export interface IAccountLookupMeta<TAddress extends string = string, TLookupTableAddress extends string = string> { | ||
@@ -27,10 +23,10 @@ readonly address: Base58EncodedAddress<TAddress>; | ||
readonly lookupTableAddress: Base58EncodedAddress<TLookupTableAddress>; | ||
readonly isWritable: boolean; | ||
readonly role: AccountRole.READONLY | AccountRole.WRITABLE; | ||
} | ||
export type ReadonlyAccountLookup<TAddress extends string = string, TLookupTableAddress extends string = string> = IAccountLookupMeta<TAddress, TLookupTableAddress> & Readonly<{ | ||
isWritable: false; | ||
}>; | ||
export type WritableAccountLookup<TAddress extends string = string, TLookupTableAddress extends string = string> = IAccountLookupMeta<TAddress, TLookupTableAddress> & Readonly<{ | ||
isWritable: true; | ||
}>; | ||
export type ReadonlyAccountLookup<TAddress extends string = string, TLookupTableAddress extends string = string> = IAccountLookupMeta<TAddress, TLookupTableAddress> & { | ||
readonly role: AccountRole.READONLY; | ||
}; | ||
export type WritableAccountLookup<TAddress extends string = string, TLookupTableAddress extends string = string> = IAccountLookupMeta<TAddress, TLookupTableAddress> & { | ||
readonly role: AccountRole.WRITABLE; | ||
}; | ||
//# sourceMappingURL=accounts.d.ts.map |
export * from './accounts'; | ||
export * from './instruction'; | ||
export * from './roles'; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@solana/instructions", | ||
"version": "2.0.0-experimental.b8df7b4", | ||
"version": "2.0.0-experimental.d1e0dc6", | ||
"description": "Helpers for creating transaction instructions", | ||
@@ -67,3 +67,3 @@ "exports": { | ||
"version-from-git": "^1.1.1", | ||
"@solana/keys": "2.0.0-development", | ||
"@solana/keys": "2.0.0-experimental.d1e0dc6", | ||
"build-scripts": "0.0.0", | ||
@@ -91,4 +91,6 @@ "test-config": "0.0.0", | ||
"test:treeshakability:node": "agadoo dist/index.native.js", | ||
"test:typecheck": "tsc --noEmit" | ||
"test:typecheck": "tsc --noEmit", | ||
"test:unit:browser": "jest -c node_modules/test-config/jest-unit.config.browser.ts --rootDir . --silent", | ||
"test:unit:node": "jest -c node_modules/test-config/jest-unit.config.node.ts --rootDir . --silent" | ||
} | ||
} |
126
README.md
@@ -21,2 +21,13 @@ [![npm][npm-image]][npm-url] | ||
### `AccountRole` | ||
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. | ||
| | `isSigner` | `isWritable` | | ||
| ----------------------------- | ---------- | ------------ | | ||
| `AccountRole.READONLY` | ❌ | ❌ | | ||
| `AccountRole.WRITABLE` | ❌ | ✅ | | ||
| `AccountRole.READONLY_SIGNER` | ✅ | ❌ | | ||
| `AccountRole.WRITABLE_SIGNER` | ✅ | ✅ | | ||
### `IAccountMeta<TAddress>` | ||
@@ -28,8 +39,8 @@ | ||
| | `isSigner` | `isWritable` | | ||
| --------------------------------- | ---------- | ------------ | | ||
| `ReadonlyAccount<TAddress>` | ❌ | ❌ | | ||
| `WritableAccount<TAddress>` | ❌ | ✅ | | ||
| `ReadonlySignerAccount<TAddress>` | ✅ | ❌ | | ||
| `WritableSignerAccount<TAddress>` | ✅ | ✅ | | ||
| | `role` | `isSigner` | `isWritable` | | ||
| --------------------------------- | ----------------------------- | ---------- | ------------ | | ||
| `ReadonlyAccount<TAddress>` | `AccountRole.READONLY` | ❌ | ❌ | | ||
| `WritableAccount<TAddress>` | `AccountRole.WRITABLE` | ❌ | ✅ | | ||
| `ReadonlySignerAccount<TAddress>` | `AccountRole.READONLY_SIGNER` | ✅ | ❌ | | ||
| `WritableSignerAccount<TAddress>` | `AccountRole.WRITABLE_SIGNER` | ✅ | ✅ | | ||
@@ -42,20 +53,99 @@ For example, you could type the rent sysvar account like this: | ||
### `Instruction<TProgramAddress, TAccounts, TData>` | ||
### `IAccountLookupMeta<TAddress, TLookupTableAddress>` | ||
Use this to define the structure of a transaction instruction. | ||
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. | ||
Typically, you will use one of its subtypes. | ||
| | `role` | `isSigner` | `isWritable` | | ||
| ------------------------------------------------------ | ---------------------- | ---------- | ------------ | | ||
| `ReadonlyLookupAccount<TAddress, TLookupTableAddress>` | `AccountRole.READONLY` | ❌ | ❌ | | ||
| `WritableLookupAccount<TAddress, TLookupTableAddress>` | `AccountRole.WRITABLE` | ❌ | ✅ | | ||
For example, you could type the rent sysvar account that you looked up in a lookup table like this: | ||
```ts | ||
type InitializeStakeInstruction = Instruction< | ||
// Program address | ||
'StakeConfig11111111111111111111111111111111', | ||
// Accounts | ||
type RentSysvar = ReadonlyLookupAccount< | ||
'SysvarRent111111111111111111111111111111111', | ||
'MyLookupTable111111111111111111111111111111' | ||
>; | ||
``` | ||
### `IInstruction<TProgramAddress>` | ||
Use this to specify an instruction destined for a given program. | ||
```ts | ||
type StakeProgramInstruction = IInstruction<'StakeConfig11111111111111111111111111111111'>; | ||
``` | ||
### `IInstructionWithAccounts<TAccounts>` | ||
Use this type to specify an instruction that contains certain accounts. | ||
```ts | ||
type InstructionWithTwoAccounts = IInstructionWithAccounts< | ||
[ | ||
WritableAccount, // Stake account | ||
RentSysvar | ||
], | ||
// Data | ||
InitializeStakeInstructionData | ||
WritableAccount, // First account | ||
RentSysvar // Second account | ||
] | ||
>; | ||
``` | ||
Instructions that do not require data may omit the `TData` type parameter. | ||
### `IInstructionWithData<TData>` | ||
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. | ||
For example, here is how the `AdvanceNonce` instruction is typed. | ||
```ts | ||
type AdvanceNonceAccountInstruction< | ||
TNonceAccountAddress extends string = string, | ||
TNonceAuthorityAddress extends string = string | ||
> = IInstruction<'11111111111111111111111111111111'> & | ||
IInstructionWithAccounts< | ||
[ | ||
WritableAccount<TNonceAccountAddress>, | ||
ReadonlyAccount<'SysvarRecentB1ockHashes11111111111111111111'>, | ||
ReadonlySignerAccount<TNonceAuthorityAddress> | ||
] | ||
> & | ||
IInstructionWithData<AdvanceNonceAccountInstructionData>; | ||
``` | ||
## Functions | ||
### `isSignerRole(role: AccountRole)` | ||
Returns `true` if the `AccountRole` given represents that of a signer. Also refines the TypeScript type of the supplied role. | ||
### `isWritable(role: AccountRole)` | ||
Returns `true` if the `AccountRole` given represents that of a writable account. Also refines the TypeScript type of the supplied role. | ||
### `mergeRoles(roleA: AccountRole, roleB: AccountRole)` | ||
Given two `AccountRoles`, will return the `AccountRole` that grants the highest privileges of both. | ||
Example: | ||
```ts | ||
// Returns `AccountRole.WRITABLE_SIGNER` | ||
mergeRoles(AccountRole.READONLY_SIGNER, AccountRole.WRITABLE); | ||
``` | ||
### `downgradeRoleToNonSigner(role: AccountRole)` | ||
Returns an `AccountRole` representing the non-signer variant of the supplied role. | ||
### `downgradeRoleToReadonly(role: AccountRole)` | ||
Returns an `AccountRole` representing the non-writable variant of the supplied role. | ||
### `upgradeRoleToSigner(role: AccountRole)` | ||
Returns an `AccountRole` representing the signer variant of the supplied role. | ||
### `upgradeRoleToWritable(role: AccountRole)` | ||
Returns an `AccountRole` representing the writable variant of the supplied role. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57293
25
389
149
1