@r3e/neo-js-sdk 0.3.0

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.
Files changed (42) hide show
  1. package/README.md +117 -0
  2. package/dist/constants.d.ts +25 -0
  3. package/dist/constants.js +34 -0
  4. package/dist/core/block.d.ts +65 -0
  5. package/dist/core/block.js +128 -0
  6. package/dist/core/hash.d.ts +20 -0
  7. package/dist/core/hash.js +51 -0
  8. package/dist/core/keypair.d.ts +24 -0
  9. package/dist/core/keypair.js +97 -0
  10. package/dist/core/opcode.d.ts +3 -0
  11. package/dist/core/opcode.js +2 -0
  12. package/dist/core/script.d.ts +25 -0
  13. package/dist/core/script.js +144 -0
  14. package/dist/core/serializing.d.ts +40 -0
  15. package/dist/core/serializing.js +175 -0
  16. package/dist/core/tx.d.ts +147 -0
  17. package/dist/core/tx.js +252 -0
  18. package/dist/core/witness-rule.d.ts +128 -0
  19. package/dist/core/witness-rule.js +201 -0
  20. package/dist/core/witness.d.ts +24 -0
  21. package/dist/core/witness.js +62 -0
  22. package/dist/index.d.ts +16 -0
  23. package/dist/index.js +15 -0
  24. package/dist/internal/bytes.d.ts +11 -0
  25. package/dist/internal/bytes.js +55 -0
  26. package/dist/internal/hex.d.ts +2 -0
  27. package/dist/internal/hex.js +10 -0
  28. package/dist/rpcclient/index.d.ts +166 -0
  29. package/dist/rpcclient/index.js +539 -0
  30. package/dist/rpcclient/parse.d.ts +16 -0
  31. package/dist/rpcclient/parse.js +48 -0
  32. package/dist/rpcclient/types.d.ts +640 -0
  33. package/dist/rpcclient/types.js +1 -0
  34. package/dist/utils.d.ts +20 -0
  35. package/dist/utils.js +40 -0
  36. package/dist/wallet/index.d.ts +2 -0
  37. package/dist/wallet/index.js +2 -0
  38. package/dist/wallet/nep2.d.ts +19 -0
  39. package/dist/wallet/nep2.js +96 -0
  40. package/dist/wallet/nep6.d.ts +136 -0
  41. package/dist/wallet/nep6.js +178 -0
  42. package/package.json +62 -0
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ export { ADDRESS_VERSION, CRYPTOLIB_CONTRACT_HASH, GAS_CONTRACT_HASH, LEDGER_CONTRACT_HASH, MAIN_NETWORK_ID, NEO_CONTRACT_HASH, NOTARY_CONTRACT_HASH, ORACLE_CONTRACT_HASH, POLICY_CONTRACT_HASH, ROLE_MANAGEMENT_CONTRACT_HASH, STDLIB_CONTRACT_HASH, TEST_NETWORK_ID, addressVersion, cryptolibContractHash, gasContractHash, ledgerContractHash, mainNetworkId, neoContractHash, notaryContractHash, oracleContractHash, policyContractHash, roleManagementContractHash, stdlibContractHash, testNetworkId } from "./constants.js";
2
+ export { base64ToBytes, bytesToBase64, bytesToHex, hexToBytes, reverseBytes, utf8ToBytes } from "./internal/bytes.js";
3
+ export { H160, H256 } from "./core/hash.js";
4
+ export { BinaryReader, BinaryWriter, deserialize, serialize } from "./core/serializing.js";
5
+ export { Block, Header, TrimmedBlock } from "./core/block.js";
6
+ export { PrivateKey, PublicKey } from "./core/keypair.js";
7
+ export { CallFlags, ScriptBuilder, syscallCode } from "./core/script.js";
8
+ export { OpCode } from "./core/opcode.js";
9
+ export { Witness, WitnessScope, witnessScopeName } from "./core/witness.js";
10
+ export { AndCondition, BooleanCondition, CalledByContractCondition, CalledByEntryCondition, CalledByGroupCondition, GroupCondition, NotCondition, OrCondition, ScriptHashCondition, WitnessCondition, WitnessConditionType, WitnessRule, WitnessRuleAction } from "./core/witness-rule.js";
11
+ export { ConflictsAttribute, HighPriorityAttribute, NotValidBeforeAttribute, NotaryAssistedAttribute, OracleResponseAttribute, OracleResponseCode, Signer, Tx, TxAttribute, TxAttributeType } from "./core/tx.js";
12
+ export { InvokeParameters, JsonRpc, JsonRpcError, RpcClient, RpcCode, mainnetEndpoints, testnetEndpoints } from "./rpcclient/index.js";
13
+ export { buildStackParser, parseInvokeStack, parseStackItemArray, parseStackItemBoolean, parseStackItemBytes, parseStackItemInteger, parseStackItemMap, parseStackItemStruct, parseStackItemUtf8 } from "./rpcclient/parse.js";
14
+ export { Account, Contract, Parameter, ScryptParams, Wallet, decryptSecp256r1Key, encryptSecp256r1Key } from "./wallet/index.js";
15
+ export { hash160, hexstring2str, num2hexstring, reverseHex, str2hexstring } from "./utils.js";
@@ -0,0 +1,11 @@
1
+ export type BytesLike = Uint8Array | ArrayBuffer | ArrayLike<number>;
2
+ export declare function toUint8Array(value: BytesLike): Uint8Array;
3
+ export declare function bytesToHex(value: BytesLike): string;
4
+ export declare function hexToBytes(value: string): Uint8Array;
5
+ export declare function bytesToBase64(value: BytesLike): string;
6
+ export declare function base64ToBytes(value: string): Uint8Array;
7
+ export declare function concatBytes(...values: BytesLike[]): Uint8Array;
8
+ export declare function reverseBytes(value: BytesLike): Uint8Array;
9
+ export declare function equalBytes(a: BytesLike, b: BytesLike): boolean;
10
+ export declare function utf8ToBytes(value: string): Uint8Array;
11
+ export declare function encodeUInt32LE(value: number): Uint8Array;
@@ -0,0 +1,55 @@
1
+ import { normalizeHex } from "./hex.js";
2
+ export function toUint8Array(value) {
3
+ if (value instanceof Uint8Array) {
4
+ return value.slice();
5
+ }
6
+ if (value instanceof ArrayBuffer) {
7
+ return new Uint8Array(value.slice(0));
8
+ }
9
+ return Uint8Array.from(value);
10
+ }
11
+ export function bytesToHex(value) {
12
+ return Buffer.from(toUint8Array(value)).toString("hex");
13
+ }
14
+ export function hexToBytes(value) {
15
+ return Uint8Array.from(Buffer.from(normalizeHex(value), "hex"));
16
+ }
17
+ export function bytesToBase64(value) {
18
+ return Buffer.from(toUint8Array(value)).toString("base64");
19
+ }
20
+ export function base64ToBytes(value) {
21
+ return Uint8Array.from(Buffer.from(value, "base64"));
22
+ }
23
+ export function concatBytes(...values) {
24
+ const arrays = values.map(toUint8Array);
25
+ const length = arrays.reduce((sum, current) => sum + current.length, 0);
26
+ const out = new Uint8Array(length);
27
+ let offset = 0;
28
+ for (const array of arrays) {
29
+ out.set(array, offset);
30
+ offset += array.length;
31
+ }
32
+ return out;
33
+ }
34
+ export function reverseBytes(value) {
35
+ return toUint8Array(value).reverse();
36
+ }
37
+ export function equalBytes(a, b) {
38
+ const left = toUint8Array(a);
39
+ const right = toUint8Array(b);
40
+ if (left.length !== right.length) {
41
+ return false;
42
+ }
43
+ return left.every((byte, index) => byte === right[index]);
44
+ }
45
+ export function utf8ToBytes(value) {
46
+ return new TextEncoder().encode(value);
47
+ }
48
+ export function encodeUInt32LE(value) {
49
+ const out = new Uint8Array(4);
50
+ out[0] = value & 0xff;
51
+ out[1] = (value >> 8) & 0xff;
52
+ out[2] = (value >> 16) & 0xff;
53
+ out[3] = (value >> 24) & 0xff;
54
+ return out;
55
+ }
@@ -0,0 +1,2 @@
1
+ export declare function strip0x(value: string): string;
2
+ export declare function normalizeHex(value: string): string;
@@ -0,0 +1,10 @@
1
+ export function strip0x(value) {
2
+ return value.startsWith("0x") || value.startsWith("0X") ? value.slice(2) : value;
3
+ }
4
+ export function normalizeHex(value) {
5
+ const normalized = strip0x(value).toLowerCase();
6
+ if (normalized.length % 2 !== 0) {
7
+ throw new Error("Hex strings must have an even length");
8
+ }
9
+ return normalized;
10
+ }
@@ -0,0 +1,166 @@
1
+ import { H160, H256 } from "../core/hash.js";
2
+ import { PublicKey } from "../core/keypair.js";
3
+ import type { CalculateNetworkFeeInput, CancelTransactionInput, CancelTransactionResult, CloseWalletResult, DumpPrivKeyInput, DumpPrivKeyResult, FindStatesInput, FindStatesResult, FindStorageInput, FindStorageResult, GetApplicationLogInput, GetApplicationLogResult, GetBlockHashInput, GetBlockHeaderInput, GetBlockHeaderVerboseResult, GetBlockInput, GetBlockVerboseResult, GetCandidatesResult, GetConnectionCountResult, GetContractStateInput, GetContractStateResult, GetNativeContractsResult, GetNep11BalancesInput, GetNep11BalancesResult, GetNep11PropertiesInput, GetNep11PropertiesResult, GetNep17BalancesInput, GetNep11TransfersInput, GetNep11TransfersResult, GetNep17BalancesResult, GetNep17TransfersInput, GetNep17TransfersResult, GetNewAddressResult, GetPeersResult, GetProofInput, GetProofResult, GetRawMemPoolVerboseResult, GetRawTransactionInput, GetRawTransactionResult, GetStateInput, GetStateHeightResult, GetStateResult, GetStateRootInput, GetStateRootResult, GetStorageInput, GetStorageResult, GetTransactionHeightInput, GetUnclaimedGasInput, GetUnclaimedGasResult, GetUnspentsInput, GetUnspentsResult, GetVersionResult, GetWalletBalanceInput, GetWalletUnclaimedGasResult, ImportPrivKeyInput, ImportPrivKeyResult, InvokeContractVerifyResult, InvokeContractVerifyInput, InvokeFunctionInput, InvokeParameterJson, InvokeScriptInput, InvokeResult, JsonRpcLike, JsonRpcOptions, ListAddressResult, ListPluginsResult, NetworkFeeResult, OpenWalletInput, OpenWalletResult, RelayTransactionResult, RpcClientOptions, SendRawTransactionResult, SendFromInput, SendManyInput, SendRawTransactionInput, SendToAddressInput, SubmitBlockResult, SubmitBlockInput, TerminateSessionResult, TraverseIteratorInput, TraverseIteratorResult, ValidateAddressInput, ValidateAddressResult, VerifyProofInput, WalletBalanceResult } from "./types.js";
4
+ export declare enum RpcCode {
5
+ InvalidRequest = -32600,
6
+ MethodNotFound = -32601,
7
+ InvalidParams = -32602,
8
+ InternalError = -32603,
9
+ BadRequest = -32700,
10
+ UnknownBlock = -101,
11
+ UnknownContract = -102,
12
+ UnknownTransaction = -103,
13
+ UnknownStorageItem = -104,
14
+ UnknownScriptContainer = -105,
15
+ UnknownStateRoot = -106,
16
+ UnknownSession = -107,
17
+ UnknownIterator = -108,
18
+ UnknownHeight = -109,
19
+ InsufficientFundsWallet = -300,
20
+ WalletFeeLimit = -301,
21
+ NoOpenedWallet = -302,
22
+ WalletNotFound = -303,
23
+ WalletNotSupported = -304,
24
+ UnknownAccount = -305,
25
+ VerificationFailed = -500,
26
+ AlreadyExists = -501,
27
+ MempoolCapacityReached = -502,
28
+ AlreadyInPool = -503,
29
+ InsufficientNetworkFee = -504,
30
+ PolicyFailed = -505,
31
+ InvalidScript = -506,
32
+ InvalidAttribute = -507,
33
+ InvalidSignature = -508,
34
+ InvalidSize = -509,
35
+ ExpiredTransaction = -510,
36
+ InsufficientFunds = -511,
37
+ InvalidContractVerification = -512,
38
+ AccessDenied = -600,
39
+ SessionsDisabled = -601,
40
+ OracleDisabled = -602,
41
+ OracleRequestFinished = -603,
42
+ OracleRequestNotFound = -604,
43
+ OracleNotDesignatedNode = -605,
44
+ UnsupportedState = -606,
45
+ InvalidProof = -607,
46
+ ExecutionFailed = -608
47
+ }
48
+ export declare class JsonRpcError extends Error {
49
+ readonly code: number;
50
+ constructor(code: number, message: string);
51
+ toString(): string;
52
+ }
53
+ export declare function mainnetEndpoints(): string[];
54
+ export declare function testnetEndpoints(): string[];
55
+ export declare class InvokeParameters {
56
+ private readonly parameters;
57
+ addAny(): this;
58
+ addBool(value: boolean): this;
59
+ addInteger(value: bigint | number): this;
60
+ addHash160(value: H160 | string): this;
61
+ addHash256(value: H256 | string): this;
62
+ addPublicKey(value: PublicKey): this;
63
+ addString(value: string): this;
64
+ addSignature(value: Uint8Array | string): this;
65
+ addByteArray(value: Uint8Array | string): this;
66
+ toJSON(): InvokeParameterJson[];
67
+ }
68
+ export declare class JsonRpc implements JsonRpcLike {
69
+ private readonly endpoints;
70
+ private readonly timeoutMs;
71
+ private readonly transport;
72
+ private readonly endpointStrategy;
73
+ private readonly retryTransportErrors;
74
+ private nextId;
75
+ private nextEndpointIndex;
76
+ constructor(endpoints: string | string[], options?: JsonRpcOptions);
77
+ send<T = unknown>(method: string, params?: unknown[]): Promise<T>;
78
+ }
79
+ export declare class RpcClient {
80
+ private readonly jsonrpc;
81
+ constructor(endpoints?: string | string[], options?: RpcClientOptions);
82
+ send<T = unknown>(method: string, params?: unknown[]): Promise<T>;
83
+ private callNoParams;
84
+ private callSingleParam;
85
+ private callHashParam;
86
+ private callWithBooleanArg;
87
+ private callEncodedPayload;
88
+ private callAccountTimeRange;
89
+ private callStorageLookup;
90
+ private serializeInvokeInput;
91
+ private serializeSignerInput;
92
+ getBestBlockHash(): Promise<string>;
93
+ getBlock(input: GetBlockInput & {
94
+ verbose: true | 1;
95
+ }): Promise<GetBlockVerboseResult>;
96
+ getBlock(input: GetBlockInput & {
97
+ verbose?: false | 0;
98
+ }): Promise<string>;
99
+ getBlockCount(): Promise<number>;
100
+ getBlockHeaderCount(): Promise<number>;
101
+ getBlockHash(input: GetBlockHashInput): Promise<string>;
102
+ getBlockHeader(input: GetBlockHeaderInput & {
103
+ verbose: true | 1;
104
+ }): Promise<GetBlockHeaderVerboseResult>;
105
+ getBlockHeader(input: GetBlockHeaderInput & {
106
+ verbose?: false | 0;
107
+ }): Promise<string>;
108
+ getApplicationLog(input: GetApplicationLogInput): Promise<GetApplicationLogResult>;
109
+ getCandidates(): Promise<GetCandidatesResult>;
110
+ getCommittee(): Promise<string[]>;
111
+ getConnectionCount(): Promise<GetConnectionCountResult>;
112
+ getContractState(input: GetContractStateInput): Promise<GetContractStateResult>;
113
+ getNativeContracts(): Promise<GetNativeContractsResult>;
114
+ getNep11Balances(input: GetNep11BalancesInput): Promise<GetNep11BalancesResult>;
115
+ getNep11Properties(input: GetNep11PropertiesInput): Promise<GetNep11PropertiesResult>;
116
+ getNep11Transfers(input: GetNep11TransfersInput): Promise<GetNep11TransfersResult>;
117
+ getNep17Balances(input: GetNep17BalancesInput): Promise<GetNep17BalancesResult>;
118
+ getNep17Transfers(input: GetNep17TransfersInput): Promise<GetNep17TransfersResult>;
119
+ getNextBlockValidators(): Promise<GetCandidatesResult>;
120
+ getPeers(): Promise<GetPeersResult>;
121
+ getRawMemPool(includeUnverified: true | 1): Promise<GetRawMemPoolVerboseResult>;
122
+ getRawMemPool(includeUnverified?: false | 0): Promise<string[]>;
123
+ getRawTransaction(input: GetRawTransactionInput & {
124
+ verbose: true | 1;
125
+ }): Promise<GetRawTransactionResult>;
126
+ getRawTransaction(input: GetRawTransactionInput & {
127
+ verbose?: false | 0;
128
+ }): Promise<string>;
129
+ getStateHeight(): Promise<GetStateHeightResult>;
130
+ getStateRoot(input: GetStateRootInput): Promise<GetStateRootResult>;
131
+ getProof(input: GetProofInput): Promise<GetProofResult>;
132
+ verifyProof(input: VerifyProofInput): Promise<GetProofResult>;
133
+ getState(input: GetStateInput): Promise<GetStateResult>;
134
+ getStorage(input: GetStorageInput): Promise<GetStorageResult>;
135
+ findStorage(input: FindStorageInput): Promise<FindStorageResult>;
136
+ findStates(input: FindStatesInput): Promise<FindStatesResult>;
137
+ getTransactionHeight(input: GetTransactionHeightInput): Promise<number>;
138
+ getUnclaimedGas(input: GetUnclaimedGasInput): Promise<GetUnclaimedGasResult>;
139
+ getUnspents(input: GetUnspentsInput): Promise<GetUnspentsResult>;
140
+ getVersion(): Promise<GetVersionResult>;
141
+ openWallet(input: OpenWalletInput): Promise<OpenWalletResult>;
142
+ closeWallet(): Promise<CloseWalletResult>;
143
+ dumpPrivKey(input: DumpPrivKeyInput): Promise<DumpPrivKeyResult>;
144
+ getNewAddress(): Promise<GetNewAddressResult>;
145
+ getWalletBalance(input: GetWalletBalanceInput): Promise<WalletBalanceResult>;
146
+ getWalletUnclaimedGas(): Promise<GetWalletUnclaimedGasResult>;
147
+ importPrivKey(input: ImportPrivKeyInput): Promise<ImportPrivKeyResult>;
148
+ listAddress(): Promise<ListAddressResult>;
149
+ invokeFunction(input: InvokeFunctionInput): Promise<InvokeResult>;
150
+ invokeContractVerify(input: InvokeContractVerifyInput): Promise<InvokeContractVerifyResult>;
151
+ invokeScript(input: InvokeScriptInput): Promise<InvokeResult>;
152
+ traverseIterator(input: TraverseIteratorInput): Promise<TraverseIteratorResult>;
153
+ terminateSession(input: {
154
+ sessionId: string;
155
+ }): Promise<TerminateSessionResult>;
156
+ listPlugins(): Promise<ListPluginsResult>;
157
+ sendRawTransaction(input: SendRawTransactionInput): Promise<SendRawTransactionResult>;
158
+ sendFrom(input: SendFromInput): Promise<RelayTransactionResult>;
159
+ sendMany(input: SendManyInput): Promise<RelayTransactionResult>;
160
+ sendToAddress(input: SendToAddressInput): Promise<RelayTransactionResult>;
161
+ submitBlock(input: SubmitBlockInput): Promise<SubmitBlockResult>;
162
+ validateAddress(input: ValidateAddressInput): Promise<ValidateAddressResult>;
163
+ cancelTransaction(input: CancelTransactionInput): Promise<CancelTransactionResult>;
164
+ calculateNetworkFee(input: CalculateNetworkFeeInput): Promise<NetworkFeeResult>;
165
+ }
166
+ export type { JsonRpcOptions, JsonRpcRequest, JsonRpcResponse, JsonRpcTransport, RpcClientOptions } from "./types.js";