Socket
Socket
Sign inDemoInstall

@solana/instructions

Package Overview
Dependencies
Maintainers
13
Versions
1146
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solana/instructions - npm Package Compare versions

Comparing version 2.0.0-experimental.b8df7b4 to 2.0.0-experimental.c727961

dist/types/roles.d.ts

36

dist/index.browser.js

@@ -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

52

dist/index.development.js

@@ -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;
})({});

46

dist/types/accounts.d.ts
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.c727961",
"description": "Helpers for creating transaction instructions",

@@ -52,3 +52,3 @@ "exports": {

"@swc/jest": "^0.2.23",
"@types/jest": "^29.5.0",
"@types/jest": "^29.5.2",
"@typescript-eslint/eslint-plugin": "^5.57.1",

@@ -59,3 +59,3 @@ "@typescript-eslint/parser": "^5.57.1",

"eslint-plugin-sort-keys-fix": "^1.1.2",
"jest": "^29.5.0",
"jest": "^29.6.1",
"jest-runner-eslint": "^2.0.0",

@@ -69,3 +69,3 @@ "jest-runner-prettier": "^1.0.0",

"version-from-git": "^1.1.1",
"@solana/keys": "2.0.0-development",
"@solana/keys": "2.0.0-experimental.c727961",
"build-scripts": "0.0.0",

@@ -93,4 +93,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"
}
}

@@ -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` | &#x274c; | &#x274c; |
| `AccountRole.WRITABLE` | &#x274c; | &#x2705; |
| `AccountRole.READONLY_SIGNER` | &#x2705; | &#x274c; |
| `AccountRole.WRITABLE_SIGNER` | &#x2705; | &#x2705; |
### `IAccountMeta<TAddress>`

@@ -28,8 +39,8 @@

| | `isSigner` | `isWritable` |
| --------------------------------- | ---------- | ------------ |
| `ReadonlyAccount<TAddress>` | &#x274c; | &#x274c; |
| `WritableAccount<TAddress>` | &#x274c; | &#x2705; |
| `ReadonlySignerAccount<TAddress>` | &#x2705; | &#x274c; |
| `WritableSignerAccount<TAddress>` | &#x2705; | &#x2705; |
| | `role` | `isSigner` | `isWritable` |
| --------------------------------- | ----------------------------- | ---------- | ------------ |
| `ReadonlyAccount<TAddress>` | `AccountRole.READONLY` | &#x274c; | &#x274c; |
| `WritableAccount<TAddress>` | `AccountRole.WRITABLE` | &#x274c; | &#x2705; |
| `ReadonlySignerAccount<TAddress>` | `AccountRole.READONLY_SIGNER` | &#x2705; | &#x274c; |
| `WritableSignerAccount<TAddress>` | `AccountRole.WRITABLE_SIGNER` | &#x2705; | &#x2705; |

@@ -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` | &#x274c; | &#x274c; |
| `WritableLookupAccount<TAddress, TLookupTableAddress>` | `AccountRole.WRITABLE` | &#x274c; | &#x2705; |
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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc