@solana/codecs 2.0.0-experimental.f2a2e5b
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 +92 -0
- package/dist/index.browser.cjs +42 -0
- package/dist/index.browser.cjs.map +1 -0
- package/dist/index.browser.js +7 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/index.native.js +7 -0
- package/dist/index.native.js.map +1 -0
- package/dist/index.node.cjs +42 -0
- package/dist/index.node.cjs.map +1 -0
- package/dist/index.node.js +7 -0
- package/dist/index.node.js.map +1 -0
- package/dist/types/accounts.d.ts +31 -0
- package/dist/types/accounts.d.ts.map +1 -0
- package/dist/types/index.d.ts +6 -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 +93 -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,92 @@
|
|
|
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/codecs/experimental.svg?style=flat
|
|
10
|
+
[npm-image]: https://img.shields.io/npm/v/@solana/codecs/experimental.svg?style=flat
|
|
11
|
+
[npm-url]: https://www.npmjs.com/package/@solana/codecs/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/codecs
|
|
16
|
+
|
|
17
|
+
This package contains all types and helpers for encoding and decoding anything to and from a `Uint8Array`. 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
|
+
No matter which serialization strategy we use, Codecs abstract away its implementation and offers a simple `encode` and `decode` interface. Codecs are also highly composable, allowing us to build complex data structures from simple building blocks.
|
|
20
|
+
|
|
21
|
+
Here's a quick example that encodes and decodes a simple `Person` object.
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
// Use composable codecs to build complex data structures.
|
|
25
|
+
type Person = { name: string; age: number };
|
|
26
|
+
const getPersonCodec = (): Codec<Person> =>
|
|
27
|
+
getStructCodec([
|
|
28
|
+
['name', getStringCodec()],
|
|
29
|
+
['age', getU32Codec()],
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
// Use your own codecs to encode and decode data.
|
|
33
|
+
const person = { name: 'John', age: 42 };
|
|
34
|
+
const personCodec = getPersonCodec();
|
|
35
|
+
const encodedPerson: Uint8Array = personCodec.encode(person);
|
|
36
|
+
const decodedPerson: Person = personCodec.decode(encodedPerson);
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Whilst Codecs can both encode and decode, it is possible to only focus on encoding or decoding data, enabling the unused logic to be tree-shaken. For instance, here’s our previous example using Decoders only to decode a `Person` type.
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
const getPersonDecoder = (): Decoder<Person> =>
|
|
43
|
+
getStructDecoder([
|
|
44
|
+
['name', getStringDecoder()],
|
|
45
|
+
['age', getU32Decoder()],
|
|
46
|
+
]);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The `@solana/codecs` package is composed of several smaller packages, each with its own set of responsibilities. You can learn more about codecs and how to create your own by reading their respective documentation.
|
|
50
|
+
|
|
51
|
+
- [`@solana/codecs-core`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-core) This package lays the foundation of codecs by providing core type and helper functions to create and compose them.
|
|
52
|
+
- [Composing codecs](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-core#composing-codecs).
|
|
53
|
+
- [Composing encoders and decoders](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-core#composing-encoders-and-decoders).
|
|
54
|
+
- [Combining encoders and decoders](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-core#combining-encoders-and-decoders).
|
|
55
|
+
- [Different From and To types](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-core#different-from-and-to-types).
|
|
56
|
+
- [Fixed-size and variable-size codecs](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-core#fixed-size-and-variable-size-codecs).
|
|
57
|
+
- [Creating custom codecs](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-core#creating-custom-codecs).
|
|
58
|
+
- [Mapping codecs](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-core#mapping-codecs).
|
|
59
|
+
- [Fixing the size of codecs](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-core#fixing-the-size-of-codecs).
|
|
60
|
+
- [Reversing codecs](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-core#reversing-codecs).
|
|
61
|
+
- [Byte helpers](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-core#byte-helpers).
|
|
62
|
+
- [`@solana/codecs-numbers`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-numbers) This package offers codecs for numbers of various sizes and characteristics.
|
|
63
|
+
- [Integer codecs](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-numbers#integer-codecs).
|
|
64
|
+
- [Decimal number codecs](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-numbers#decimal-number-codecs).
|
|
65
|
+
- [Short u16 codec](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-numbers#short-u16-codec).
|
|
66
|
+
- [`@solana/codecs-strings`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-strings) This package provides codecs for strings of various encodings and size strategies.
|
|
67
|
+
- [String helper codec](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-strings#string-helper-codec).
|
|
68
|
+
- [Utf8 codec](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-strings#utf8-codec).
|
|
69
|
+
- [Base 64 codec](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-strings#base-64-codec).
|
|
70
|
+
- [Base 58 codec](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-strings#base-58-codec).
|
|
71
|
+
- [Base 16 codec](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-strings#base-16-codec).
|
|
72
|
+
- [Base 10 codec](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-strings#base-10-codec).
|
|
73
|
+
- [Base X codec](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-strings#base-x-codec).
|
|
74
|
+
- [Re-slicing base X codec](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-strings#re-slicing-base-x-codec).
|
|
75
|
+
- [`@solana/codecs-data-structures`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-data-structures) This package offers a set of helpers for a variety of data structures such as objects, enums, arrays, maps, etc.
|
|
76
|
+
- [Array codec](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-data-structures#array-codec).
|
|
77
|
+
- [Set codec](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-data-structures#set-codec).
|
|
78
|
+
- [Map codec](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-data-structures#map-codec).
|
|
79
|
+
- [Tuple codec](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-data-structures#tuple-codec).
|
|
80
|
+
- [Struct codec](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-data-structures#struct-codec).
|
|
81
|
+
- [Scalar enum codec](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-data-structures#scalar-enum-codec).
|
|
82
|
+
- [Data enum codec](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-data-structures#data-enum-codec).
|
|
83
|
+
- [Boolean codec](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-data-structures#boolean-codec).
|
|
84
|
+
- [Nullable codec](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-data-structures#nullable-codec).
|
|
85
|
+
- [Bytes codec](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-data-structures#bytes-codec).
|
|
86
|
+
- [Bit array codec](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-data-structures#bit-array-codec).
|
|
87
|
+
- [Unit codec](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-data-structures#unit-codec).
|
|
88
|
+
- [`@solana/options`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/options) This package adds Rust-like `Options` to JavaScript and offers codecs and helpers to manage them.
|
|
89
|
+
- [Creating options](https://github.com/solana-labs/solana-web3.js/tree/master/packages/options#creating-options).
|
|
90
|
+
- [Option helpers](https://github.com/solana-labs/solana-web3.js/tree/master/packages/options#option-helpers).
|
|
91
|
+
- [Unwrapping options](https://github.com/solana-labs/solana-web3.js/tree/master/packages/options#unwrapping-options).
|
|
92
|
+
- [Option codec](https://github.com/solana-labs/solana-web3.js/tree/master/packages/options#option-codec).
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var codecsCore = require('@solana/codecs-core');
|
|
4
|
+
var codecsDataStructures = require('@solana/codecs-data-structures');
|
|
5
|
+
var codecsNumbers = require('@solana/codecs-numbers');
|
|
6
|
+
var codecsStrings = require('@solana/codecs-strings');
|
|
7
|
+
var options = require('@solana/options');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
Object.keys(codecsCore).forEach(function (k) {
|
|
12
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return codecsCore[k]; }
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
Object.keys(codecsDataStructures).forEach(function (k) {
|
|
18
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () { return codecsDataStructures[k]; }
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
Object.keys(codecsNumbers).forEach(function (k) {
|
|
24
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () { return codecsNumbers[k]; }
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
Object.keys(codecsStrings).forEach(function (k) {
|
|
30
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () { return codecsStrings[k]; }
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
Object.keys(options).forEach(function (k) {
|
|
36
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () { return options[k]; }
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=out.js.map
|
|
42
|
+
//# sourceMappingURL=index.browser.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc","sourcesContent":["export * from '@solana/codecs-core';\nexport * from '@solana/codecs-data-structures';\nexport * from '@solana/codecs-numbers';\nexport * from '@solana/codecs-strings';\nexport * from '@solana/options';\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from '@solana/codecs-core';
|
|
2
|
+
export * from '@solana/codecs-data-structures';
|
|
3
|
+
export * from '@solana/codecs-numbers';
|
|
4
|
+
export * from '@solana/codecs-strings';
|
|
5
|
+
export * from '@solana/options';
|
|
6
|
+
//# sourceMappingURL=out.js.map
|
|
7
|
+
//# sourceMappingURL=index.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc","sourcesContent":["export * from '@solana/codecs-core';\nexport * from '@solana/codecs-data-structures';\nexport * from '@solana/codecs-numbers';\nexport * from '@solana/codecs-strings';\nexport * from '@solana/options';\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from '@solana/codecs-core';
|
|
2
|
+
export * from '@solana/codecs-data-structures';
|
|
3
|
+
export * from '@solana/codecs-numbers';
|
|
4
|
+
export * from '@solana/codecs-strings';
|
|
5
|
+
export * from '@solana/options';
|
|
6
|
+
//# sourceMappingURL=out.js.map
|
|
7
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc","sourcesContent":["export * from '@solana/codecs-core';\nexport * from '@solana/codecs-data-structures';\nexport * from '@solana/codecs-numbers';\nexport * from '@solana/codecs-strings';\nexport * from '@solana/options';\n"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var codecsCore = require('@solana/codecs-core');
|
|
4
|
+
var codecsDataStructures = require('@solana/codecs-data-structures');
|
|
5
|
+
var codecsNumbers = require('@solana/codecs-numbers');
|
|
6
|
+
var codecsStrings = require('@solana/codecs-strings');
|
|
7
|
+
var options = require('@solana/options');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
Object.keys(codecsCore).forEach(function (k) {
|
|
12
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return codecsCore[k]; }
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
Object.keys(codecsDataStructures).forEach(function (k) {
|
|
18
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () { return codecsDataStructures[k]; }
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
Object.keys(codecsNumbers).forEach(function (k) {
|
|
24
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () { return codecsNumbers[k]; }
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
Object.keys(codecsStrings).forEach(function (k) {
|
|
30
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () { return codecsStrings[k]; }
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
Object.keys(options).forEach(function (k) {
|
|
36
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () { return options[k]; }
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=out.js.map
|
|
42
|
+
//# sourceMappingURL=index.node.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc","sourcesContent":["export * from '@solana/codecs-core';\nexport * from '@solana/codecs-data-structures';\nexport * from '@solana/codecs-numbers';\nexport * from '@solana/codecs-strings';\nexport * from '@solana/options';\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from '@solana/codecs-core';
|
|
2
|
+
export * from '@solana/codecs-data-structures';
|
|
3
|
+
export * from '@solana/codecs-numbers';
|
|
4
|
+
export * from '@solana/codecs-strings';
|
|
5
|
+
export * from '@solana/options';
|
|
6
|
+
//# sourceMappingURL=out.js.map
|
|
7
|
+
//# sourceMappingURL=index.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc","sourcesContent":["export * from '@solana/codecs-core';\nexport * from '@solana/codecs-data-structures';\nexport * from '@solana/codecs-numbers';\nexport * from '@solana/codecs-strings';\nexport * from '@solana/options';\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Address } from '@solana/addresses';
|
|
2
|
+
import { AccountRole } from './roles.js.js.js.js';
|
|
3
|
+
export interface IAccountMeta<TAddress extends string = string> {
|
|
4
|
+
readonly address: Address<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: Address<TAddress>;
|
|
21
|
+
readonly addressIndex: number;
|
|
22
|
+
readonly lookupTableAddress: Address<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,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,MAAM,WAAW,YAAY,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM;IAC1D,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;CAC9B;AAED,MAAM,MAAM,eAAe,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG;IACrF,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,QAAQ,CAAC;CACvC,CAAC;AACF,MAAM,MAAM,eAAe,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG;IAAE,IAAI,EAAE,WAAW,CAAC,QAAQ,CAAA;CAAE,CAAC;AACxH,MAAM,MAAM,qBAAqB,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG;IAC3F,IAAI,EAAE,WAAW,CAAC,eAAe,CAAC;CACrC,CAAC;AACF,MAAM,MAAM,qBAAqB,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG;IAC3F,IAAI,EAAE,WAAW,CAAC,eAAe,CAAC;CACrC,CAAC;AAEF,MAAM,WAAW,kBAAkB,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,EAAE,mBAAmB,SAAS,MAAM,GAAG,MAAM;IAC7G,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,kBAAkB,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC1D,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC;CAC9D;AAED,MAAM,MAAM,qBAAqB,CAC7B,QAAQ,SAAS,MAAM,GAAG,MAAM,EAChC,mBAAmB,SAAS,MAAM,GAAG,MAAM,IAC3C,kBAAkB,CAAC,QAAQ,EAAE,mBAAmB,CAAC,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,QAAQ,CAAA;CAAE,CAAC;AAChG,MAAM,MAAM,qBAAqB,CAC7B,QAAQ,SAAS,MAAM,GAAG,MAAM,EAChC,mBAAmB,SAAS,MAAM,GAAG,MAAM,IAC3C,kBAAkB,CAAC,QAAQ,EAAE,mBAAmB,CAAC,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,QAAQ,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Address } from '@solana/addresses';
|
|
2
|
+
import { IAccountLookupMeta, IAccountMeta } from './accounts.js.js.js.js';
|
|
3
|
+
export interface IInstruction<TProgramAddress extends string = string, TAccounts extends readonly (IAccountMeta | IAccountLookupMeta)[] = readonly (IAccountMeta | IAccountLookupMeta)[]> {
|
|
4
|
+
readonly accounts?: TAccounts;
|
|
5
|
+
readonly data?: Uint8Array;
|
|
6
|
+
readonly programAddress: Address<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,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE9D,MAAM,WAAW,YAAY,CACzB,eAAe,SAAS,MAAM,GAAG,MAAM,EACvC,SAAS,SAAS,SAAS,CAAC,YAAY,GAAG,kBAAkB,CAAC,EAAE,GAAG,SAAS,CAAC,YAAY,GAAG,kBAAkB,CAAC,EAAE;IAEjH,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;CACrD;AAED,MAAM,WAAW,wBAAwB,CAAC,SAAS,SAAS,SAAS,CAAC,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":"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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@solana/codecs",
|
|
3
|
+
"version": "2.0.0-experimental.f2a2e5b",
|
|
4
|
+
"description": "A library for encoding and decoding any data structure",
|
|
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
|
+
"dependencies": {
|
|
49
|
+
"@solana/codecs-core": "2.0.0-development",
|
|
50
|
+
"@solana/codecs-data-structures": "2.0.0-development",
|
|
51
|
+
"@solana/codecs-numbers": "2.0.0-development",
|
|
52
|
+
"@solana/codecs-strings": "2.0.0-development",
|
|
53
|
+
"@solana/options": "2.0.0-development"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@solana/eslint-config-solana": "^1.0.2",
|
|
57
|
+
"@typescript-eslint/eslint-plugin": "^6.13.2",
|
|
58
|
+
"@typescript-eslint/parser": "^6.3.0",
|
|
59
|
+
"agadoo": "^3.0.0",
|
|
60
|
+
"eslint": "^8.45.0",
|
|
61
|
+
"eslint-plugin-jest": "^27.4.2",
|
|
62
|
+
"eslint-plugin-sort-keys-fix": "^1.1.2",
|
|
63
|
+
"jest": "^29.7.0",
|
|
64
|
+
"prettier": "^3.1",
|
|
65
|
+
"tsup": "^8.0.1",
|
|
66
|
+
"typescript": "^5.2.2",
|
|
67
|
+
"version-from-git": "^1.1.1",
|
|
68
|
+
"build-scripts": "0.0.0",
|
|
69
|
+
"test-config": "0.0.0",
|
|
70
|
+
"tsconfig": "0.0.0"
|
|
71
|
+
},
|
|
72
|
+
"bundlewatch": {
|
|
73
|
+
"defaultCompression": "gzip",
|
|
74
|
+
"files": [
|
|
75
|
+
{
|
|
76
|
+
"path": "./dist/index*.js"
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
},
|
|
80
|
+
"scripts": {
|
|
81
|
+
"compile:js": "tsup --config build-scripts/tsup.config.package.ts",
|
|
82
|
+
"compile:typedefs": "tsc -p ./tsconfig.declarations.json && node node_modules/build-scripts/add-js-extension-to-types.mjs",
|
|
83
|
+
"dev": "jest -c node_modules/test-config/jest-dev.config.ts --rootDir . --watch",
|
|
84
|
+
"publish-packages": "pnpm publish --tag experimental --access public --no-git-checks",
|
|
85
|
+
"style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/* package.json",
|
|
86
|
+
"test:lint": "jest -c node_modules/test-config/jest-lint.config.ts --rootDir . --silent",
|
|
87
|
+
"test:prettier": "jest -c node_modules/test-config/jest-prettier.config.ts --rootDir . --silent",
|
|
88
|
+
"test:treeshakability:browser": "agadoo dist/index.browser.js",
|
|
89
|
+
"test:treeshakability:native": "agadoo dist/index.native.js",
|
|
90
|
+
"test:treeshakability:node": "agadoo dist/index.node.js",
|
|
91
|
+
"test:typecheck": "tsc --noEmit"
|
|
92
|
+
}
|
|
93
|
+
}
|