Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@solana/accounts

Package Overview
Dependencies
Maintainers
14
Versions
956
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solana/accounts - npm Package Compare versions

Comparing version 2.0.0-experimental.ef2569b to 2.0.0-experimental.f5d64e6

17

dist/index.browser.js

@@ -19,2 +19,17 @@ import { getBase64Encoder, getBase58Encoder } from '@solana/codecs-strings';

}
function accountExists(account) {
return !("exists" in account) || "exists" in account && account.exists;
}
function assertAccountDecoded(account) {
if (accountExists(account) && account.data instanceof Uint8Array) {
throw new Error(`Expected account [${account.address}] to be decoded.`);
}
}
function assertAccountsDecoded(accounts) {
const encoded = accounts.filter((a) => accountExists(a) && a.data instanceof Uint8Array);
if (encoded.length > 0) {
const encodedAddresses = encoded.map((a) => a.address).join(", ");
throw new Error(`Expected accounts [${encodedAddresses}] to be decoded.`);
}
}
function parseBase64RpcAccount(address, rpcAccount) {

@@ -84,4 +99,4 @@ if (!rpcAccount)

export { BASE_ACCOUNT_SIZE, assertAccountExists, assertAccountsExist, decodeAccount, fetchEncodedAccount, fetchEncodedAccounts, fetchJsonParsedAccount, fetchJsonParsedAccounts, parseBase58RpcAccount, parseBase64RpcAccount, parseJsonRpcAccount };
export { BASE_ACCOUNT_SIZE, assertAccountDecoded, assertAccountExists, assertAccountsDecoded, assertAccountsExist, decodeAccount, fetchEncodedAccount, fetchEncodedAccounts, fetchJsonParsedAccount, fetchJsonParsedAccounts, parseBase58RpcAccount, parseBase64RpcAccount, parseJsonRpcAccount };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.browser.js.map

@@ -19,2 +19,17 @@ import { getBase64Encoder, getBase58Encoder } from '@solana/codecs-strings';

}
function accountExists(account) {
return !("exists" in account) || "exists" in account && account.exists;
}
function assertAccountDecoded(account) {
if (accountExists(account) && account.data instanceof Uint8Array) {
throw new Error(`Expected account [${account.address}] to be decoded.`);
}
}
function assertAccountsDecoded(accounts) {
const encoded = accounts.filter((a) => accountExists(a) && a.data instanceof Uint8Array);
if (encoded.length > 0) {
const encodedAddresses = encoded.map((a) => a.address).join(", ");
throw new Error(`Expected accounts [${encodedAddresses}] to be decoded.`);
}
}
function parseBase64RpcAccount(address, rpcAccount) {

@@ -84,4 +99,4 @@ if (!rpcAccount)

export { BASE_ACCOUNT_SIZE, assertAccountExists, assertAccountsExist, decodeAccount, fetchEncodedAccount, fetchEncodedAccounts, fetchJsonParsedAccount, fetchJsonParsedAccounts, parseBase58RpcAccount, parseBase64RpcAccount, parseJsonRpcAccount };
export { BASE_ACCOUNT_SIZE, assertAccountDecoded, assertAccountExists, assertAccountsDecoded, assertAccountsExist, decodeAccount, fetchEncodedAccount, fetchEncodedAccounts, fetchJsonParsedAccount, fetchJsonParsedAccounts, parseBase58RpcAccount, parseBase64RpcAccount, parseJsonRpcAccount };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.native.js.map

@@ -19,2 +19,17 @@ import { getBase64Encoder, getBase58Encoder } from '@solana/codecs-strings';

}
function accountExists(account) {
return !("exists" in account) || "exists" in account && account.exists;
}
function assertAccountDecoded(account) {
if (accountExists(account) && account.data instanceof Uint8Array) {
throw new Error(`Expected account [${account.address}] to be decoded.`);
}
}
function assertAccountsDecoded(accounts) {
const encoded = accounts.filter((a) => accountExists(a) && a.data instanceof Uint8Array);
if (encoded.length > 0) {
const encodedAddresses = encoded.map((a) => a.address).join(", ");
throw new Error(`Expected accounts [${encodedAddresses}] to be decoded.`);
}
}
function parseBase64RpcAccount(address, rpcAccount) {

@@ -84,4 +99,4 @@ if (!rpcAccount)

export { BASE_ACCOUNT_SIZE, assertAccountExists, assertAccountsExist, decodeAccount, fetchEncodedAccount, fetchEncodedAccounts, fetchJsonParsedAccount, fetchJsonParsedAccounts, parseBase58RpcAccount, parseBase64RpcAccount, parseJsonRpcAccount };
export { BASE_ACCOUNT_SIZE, assertAccountDecoded, assertAccountExists, assertAccountsDecoded, assertAccountsExist, decodeAccount, fetchEncodedAccount, fetchEncodedAccounts, fetchJsonParsedAccount, fetchJsonParsedAccounts, parseBase58RpcAccount, parseBase64RpcAccount, parseJsonRpcAccount };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.node.js.map

@@ -7,2 +7,8 @@ import type { Decoder } from '@solana/codecs-core';

export declare function decodeAccount<TData extends object, TAddress extends string = string>(encodedAccount: MaybeEncodedAccount<TAddress>, decoder: Decoder<TData>): MaybeAccount<TData, TAddress>;
/** Asserts that an account has been decoded. */
export declare function assertAccountDecoded<TData extends object, TAddress extends string = string>(account: Account<TData | Uint8Array, TAddress>): asserts account is Account<TData, TAddress>;
export declare function assertAccountDecoded<TData extends object, TAddress extends string = string>(account: MaybeAccount<TData | Uint8Array, TAddress>): asserts account is MaybeAccount<TData, TAddress>;
/** Asserts that all accounts have been decoded. */
export declare function assertAccountsDecoded<TData extends object, TAddress extends string = string>(accounts: Account<TData | Uint8Array, TAddress>[]): asserts accounts is Account<TData, TAddress>[];
export declare function assertAccountsDecoded<TData extends object, TAddress extends string = string>(accounts: MaybeAccount<TData | Uint8Array, TAddress>[]): asserts accounts is MaybeAccount<TData, TAddress>[];
//# sourceMappingURL=decode-account.d.ts.map

14

package.json
{
"name": "@solana/accounts",
"version": "2.0.0-experimental.ef2569b",
"version": "2.0.0-experimental.f5d64e6",
"description": "Helpers for representing, fetching and decoding Solana accounts",

@@ -49,8 +49,8 @@ "exports": {

"dependencies": {
"@solana/codecs-core": "2.0.0-experimental.ef2569b",
"@solana/addresses": "2.0.0-experimental.ef2569b",
"@solana/codecs-strings": "2.0.0-experimental.ef2569b",
"@solana/rpc-core": "2.0.0-experimental.ef2569b",
"@solana/rpc-transport": "2.0.0-experimental.ef2569b",
"@solana/rpc-types": "2.0.0-experimental.ef2569b"
"@solana/addresses": "2.0.0-experimental.f5d64e6",
"@solana/codecs-core": "2.0.0-experimental.f5d64e6",
"@solana/codecs-strings": "2.0.0-experimental.f5d64e6",
"@solana/rpc-core": "2.0.0-experimental.f5d64e6",
"@solana/rpc-transport": "2.0.0-experimental.f5d64e6",
"@solana/rpc-types": "2.0.0-experimental.f5d64e6"
},

@@ -57,0 +57,0 @@ "devDependencies": {

@@ -270,1 +270,45 @@ [![npm][npm-image]][npm-url]

```
### `assertAccountDecoded()`
This function asserts that an account stores decoded data, ie not a Uint8Array. Note that it does not check the shape of the data matches the decoded type, only that it is not a Uint8Array.
```ts
type MyAccountData = { name: string; age: number };
const myAccount: Account<MyAccountData | Uint8Array, '1234..5678'>;
assertAccountDecoded(myAccount);
// now the account data can be used as MyAccountData
account.data satisfies MyAccountData;
```
This is particularly useful for narrowing the result of fetching a JSON parsed account.
```ts
const account: MaybeAccount<MockData | Uint8Array> = await fetchJsonParsedAccount<MockData>(
rpc,
'1234..5678' as Address,
)
assertAccountDecoded(account);
// now we have a MaybeAccount<MockData>
account satisfies MaybeAccount<MockData>
```
### `assertAccountsDecoded`
This function asserts that all input accounts store decoded data, ie not a Uint8Array. As with `assertAccountDecoded` it does not check the shape of the data matches the decoded type, only that it is not a Uint8Array.
```ts
type MyAccountData = { name: string; age: number };
const myAccounts: Account<MyAccountData | Uint8Array, Address>[];
assertAccountsDecoded(myAccounts);
// now the account data can be used as MyAccountData
for(const a of account) {
account.data satisfies MyAccountData;
}
```

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