@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
@@ -0,0 +1,252 @@
1
+ import { createHash } from "node:crypto";
2
+ import { bytesToBase64, encodeUInt32LE } from "../internal/bytes.js";
3
+ import { H160, H256 } from "./hash.js";
4
+ import { PublicKey } from "./keypair.js";
5
+ import { BinaryWriter, serialize } from "./serializing.js";
6
+ import { Witness, WitnessScope, witnessScopeName } from "./witness.js";
7
+ import { WitnessRule } from "./witness-rule.js";
8
+ function sha256(data) {
9
+ return createHash("sha256").update(data).digest();
10
+ }
11
+ export class Signer {
12
+ account;
13
+ scopes;
14
+ allowedContracts;
15
+ allowedGroups;
16
+ rules;
17
+ constructor({ account, scopes, allowedContracts = [], allowedGroups = [], rules = [], }) {
18
+ this.account = typeof account === "string" ? new H160(account) : account;
19
+ this.scopes = scopes;
20
+ this.allowedContracts = allowedContracts.map((contract) => typeof contract === "string" ? new H160(contract) : contract);
21
+ this.allowedGroups = allowedGroups.map((group) => (typeof group === "string" ? new PublicKey(group) : group));
22
+ this.rules = rules;
23
+ }
24
+ toJSON() {
25
+ return {
26
+ account: this.account.toString(),
27
+ scopes: witnessScopeName(this.scopes),
28
+ allowedcontracts: this.allowedContracts.map((contract) => contract.toString()),
29
+ allowedgroups: this.allowedGroups.map((group) => group.toString()),
30
+ rules: this.rules.map((rule) => rule.toJSON()),
31
+ };
32
+ }
33
+ marshalTo(writer) {
34
+ this.account.marshalTo(writer);
35
+ writer.writeUInt8(this.scopes);
36
+ if (this.scopes & WitnessScope.CustomContracts) {
37
+ writer.writeMultiple(this.allowedContracts);
38
+ }
39
+ if (this.scopes & WitnessScope.CustomGroups) {
40
+ writer.writeMultiple(this.allowedGroups);
41
+ }
42
+ if (this.scopes & WitnessScope.WitnessRules) {
43
+ writer.writeMultiple(this.rules);
44
+ }
45
+ }
46
+ static unmarshalFrom(reader) {
47
+ const account = H160.unmarshalFrom(reader);
48
+ const scopes = reader.readUInt8();
49
+ const allowedContracts = scopes & WitnessScope.CustomContracts ? reader.readMultiple(H160) : [];
50
+ const allowedGroups = scopes & WitnessScope.CustomGroups ? reader.readMultiple(PublicKey) : [];
51
+ const rules = scopes & WitnessScope.WitnessRules ? reader.readMultiple(WitnessRule) : [];
52
+ return new Signer({ account, scopes, allowedContracts, allowedGroups, rules });
53
+ }
54
+ }
55
+ export var TxAttributeType;
56
+ (function (TxAttributeType) {
57
+ TxAttributeType[TxAttributeType["HighPriority"] = 1] = "HighPriority";
58
+ TxAttributeType[TxAttributeType["OracleResponse"] = 17] = "OracleResponse";
59
+ TxAttributeType[TxAttributeType["NotValidBefore"] = 32] = "NotValidBefore";
60
+ TxAttributeType[TxAttributeType["Conflicts"] = 33] = "Conflicts";
61
+ TxAttributeType[TxAttributeType["NotaryAssisted"] = 34] = "NotaryAssisted";
62
+ })(TxAttributeType || (TxAttributeType = {}));
63
+ export var OracleResponseCode;
64
+ (function (OracleResponseCode) {
65
+ OracleResponseCode[OracleResponseCode["Success"] = 0] = "Success";
66
+ OracleResponseCode[OracleResponseCode["ProtocolNotSupported"] = 16] = "ProtocolNotSupported";
67
+ OracleResponseCode[OracleResponseCode["ConsensusUnreachable"] = 18] = "ConsensusUnreachable";
68
+ OracleResponseCode[OracleResponseCode["NotFound"] = 20] = "NotFound";
69
+ OracleResponseCode[OracleResponseCode["Timeout"] = 22] = "Timeout";
70
+ OracleResponseCode[OracleResponseCode["Forbidden"] = 24] = "Forbidden";
71
+ OracleResponseCode[OracleResponseCode["ResponseTooLarge"] = 26] = "ResponseTooLarge";
72
+ OracleResponseCode[OracleResponseCode["InsufficientFunds"] = 28] = "InsufficientFunds";
73
+ OracleResponseCode[OracleResponseCode["ContentTypeNotSupported"] = 31] = "ContentTypeNotSupported";
74
+ OracleResponseCode[OracleResponseCode["Error"] = 255] = "Error";
75
+ })(OracleResponseCode || (OracleResponseCode = {}));
76
+ export class TxAttribute {
77
+ type;
78
+ constructor(type) {
79
+ this.type = type;
80
+ }
81
+ marshalTo(writer) {
82
+ writer.writeUInt8(this.type);
83
+ }
84
+ static unmarshalFrom(reader) {
85
+ const type = reader.readUInt8();
86
+ switch (type) {
87
+ case TxAttributeType.HighPriority:
88
+ return new HighPriorityAttribute();
89
+ case TxAttributeType.OracleResponse:
90
+ return new OracleResponseAttribute(reader.readUInt64LE(), reader.readUInt8(), reader.readVarBytes());
91
+ case TxAttributeType.NotValidBefore:
92
+ return new NotValidBeforeAttribute(reader.readUInt32LE());
93
+ case TxAttributeType.Conflicts:
94
+ return new ConflictsAttribute(H256.unmarshalFrom(reader));
95
+ case TxAttributeType.NotaryAssisted:
96
+ return new NotaryAssistedAttribute(reader.readUInt8());
97
+ default:
98
+ throw new Error(`unexpected TxAttributeType: ${type}`);
99
+ }
100
+ }
101
+ toJSON() {
102
+ return { type: TxAttributeType[this.type] };
103
+ }
104
+ }
105
+ export class HighPriorityAttribute extends TxAttribute {
106
+ constructor() {
107
+ super(TxAttributeType.HighPriority);
108
+ }
109
+ toJSON() {
110
+ return { type: "HighPriority" };
111
+ }
112
+ }
113
+ export class OracleResponseAttribute extends TxAttribute {
114
+ id;
115
+ code;
116
+ result;
117
+ constructor(id, code, result) {
118
+ super(TxAttributeType.OracleResponse);
119
+ this.id = id;
120
+ this.code = code;
121
+ this.result = result;
122
+ }
123
+ marshalTo(writer) {
124
+ super.marshalTo(writer);
125
+ writer.writeUInt64LE(this.id);
126
+ writer.writeUInt8(this.code);
127
+ writer.writeVarBytes(this.result);
128
+ }
129
+ toJSON() {
130
+ return {
131
+ type: "OracleResponse",
132
+ id: this.id.toString(),
133
+ code: OracleResponseCode[this.code],
134
+ result: bytesToBase64(this.result),
135
+ };
136
+ }
137
+ }
138
+ export class NotValidBeforeAttribute extends TxAttribute {
139
+ height;
140
+ constructor(height) {
141
+ super(TxAttributeType.NotValidBefore);
142
+ this.height = height;
143
+ }
144
+ marshalTo(writer) {
145
+ super.marshalTo(writer);
146
+ writer.writeUInt32LE(this.height);
147
+ }
148
+ toJSON() {
149
+ return { type: "NotValidBefore", height: this.height };
150
+ }
151
+ }
152
+ export class ConflictsAttribute extends TxAttribute {
153
+ hash;
154
+ constructor(hash) {
155
+ super(TxAttributeType.Conflicts);
156
+ this.hash = hash;
157
+ }
158
+ marshalTo(writer) {
159
+ super.marshalTo(writer);
160
+ this.hash.marshalTo(writer);
161
+ }
162
+ toJSON() {
163
+ return { type: "Conflicts", hash: this.hash.toString() };
164
+ }
165
+ }
166
+ export class NotaryAssistedAttribute extends TxAttribute {
167
+ nKeys;
168
+ constructor(nKeys) {
169
+ super(TxAttributeType.NotaryAssisted);
170
+ this.nKeys = nKeys;
171
+ }
172
+ marshalTo(writer) {
173
+ super.marshalTo(writer);
174
+ writer.writeUInt8(this.nKeys);
175
+ }
176
+ toJSON() {
177
+ return { type: "NotaryAssisted", nkeys: this.nKeys };
178
+ }
179
+ }
180
+ export class Tx {
181
+ version = 0;
182
+ nonce;
183
+ systemFee;
184
+ networkFee;
185
+ validUntilBlock;
186
+ script;
187
+ signers;
188
+ attributes;
189
+ witnesses;
190
+ constructor({ nonce, systemFee, networkFee, validUntilBlock, script, signers = [], witnesses = [], attributes = [], }) {
191
+ this.nonce = nonce;
192
+ this.systemFee = BigInt(systemFee);
193
+ this.networkFee = BigInt(networkFee);
194
+ this.validUntilBlock = validUntilBlock;
195
+ this.script = script;
196
+ this.signers = signers;
197
+ this.attributes = attributes;
198
+ this.witnesses = witnesses;
199
+ }
200
+ getSignData(networkId) {
201
+ const writer = new BinaryWriter();
202
+ this.marshalUnsignedTo(writer);
203
+ const digest = sha256(writer.toBytes());
204
+ return new Uint8Array([...encodeUInt32LE(networkId), ...digest]);
205
+ }
206
+ marshalUnsignedTo(writer) {
207
+ writer.writeUInt8(this.version);
208
+ writer.writeUInt32LE(this.nonce);
209
+ writer.writeUInt64LE(this.systemFee);
210
+ writer.writeUInt64LE(this.networkFee);
211
+ writer.writeUInt32LE(this.validUntilBlock);
212
+ writer.writeMultiple(this.signers);
213
+ writer.writeMultiple(this.attributes);
214
+ writer.writeVarBytes(this.script);
215
+ }
216
+ marshalTo(writer) {
217
+ this.marshalUnsignedTo(writer);
218
+ writer.writeMultiple(this.witnesses);
219
+ }
220
+ static unmarshalFrom(reader) {
221
+ const version = reader.readUInt8();
222
+ if (version !== 0) {
223
+ throw new Error(`unexpected tx version: ${version}`);
224
+ }
225
+ return new Tx({
226
+ nonce: reader.readUInt32LE(),
227
+ systemFee: reader.readUInt64LE(),
228
+ networkFee: reader.readUInt64LE(),
229
+ validUntilBlock: reader.readUInt32LE(),
230
+ signers: reader.readMultiple(Signer),
231
+ attributes: reader.readMultiple(TxAttribute),
232
+ script: reader.readVarBytes(),
233
+ witnesses: reader.readMultiple(Witness),
234
+ });
235
+ }
236
+ toBytes() {
237
+ return serialize(this);
238
+ }
239
+ toJSON() {
240
+ return {
241
+ version: this.version,
242
+ nonce: this.nonce,
243
+ sysfee: this.systemFee.toString(),
244
+ netfee: this.networkFee.toString(),
245
+ validuntilblock: this.validUntilBlock,
246
+ script: bytesToBase64(this.script),
247
+ signers: this.signers.map((signer) => signer.toJSON()),
248
+ attributes: this.attributes.map((attribute) => attribute.toJSON()),
249
+ witnesses: this.witnesses.map((witness) => witness.toJSON()),
250
+ };
251
+ }
252
+ }
@@ -0,0 +1,128 @@
1
+ import { H160 } from "./hash.js";
2
+ import { PublicKey } from "./keypair.js";
3
+ import { BinaryReader, BinaryWriter } from "./serializing.js";
4
+ export interface BaseWitnessConditionJson {
5
+ type: string;
6
+ }
7
+ export interface BooleanConditionJson {
8
+ type: "Boolean";
9
+ expression: boolean;
10
+ }
11
+ export interface NotConditionJson {
12
+ type: "Not";
13
+ expression: WitnessConditionJson;
14
+ }
15
+ export interface AndConditionJson {
16
+ type: "And";
17
+ expressions: WitnessConditionJson[];
18
+ }
19
+ export interface OrConditionJson {
20
+ type: "Or";
21
+ expressions: WitnessConditionJson[];
22
+ }
23
+ export interface ScriptHashConditionJson {
24
+ type: "ScriptHash";
25
+ hash: string;
26
+ }
27
+ export interface GroupConditionJson {
28
+ type: "Group";
29
+ group: string;
30
+ }
31
+ export interface CalledByEntryConditionJson {
32
+ type: "CalledByEntry";
33
+ }
34
+ export interface CalledByContractConditionJson {
35
+ type: "CalledByContract";
36
+ hash: string;
37
+ }
38
+ export interface CalledByGroupConditionJson {
39
+ type: "CalledByGroup";
40
+ group: string;
41
+ }
42
+ export type WitnessConditionJson = BooleanConditionJson | NotConditionJson | AndConditionJson | OrConditionJson | ScriptHashConditionJson | GroupConditionJson | CalledByEntryConditionJson | CalledByContractConditionJson | CalledByGroupConditionJson;
43
+ export interface WitnessRuleJson {
44
+ action: "Deny" | "Allow";
45
+ conditions: WitnessConditionJson[];
46
+ }
47
+ export declare enum WitnessRuleAction {
48
+ Deny = 0,
49
+ Allow = 1
50
+ }
51
+ export declare enum WitnessConditionType {
52
+ Boolean = 0,
53
+ Not = 1,
54
+ And = 2,
55
+ Or = 3,
56
+ ScriptHash = 24,
57
+ Group = 25,
58
+ CalledByEntry = 32,
59
+ CalledByContract = 40,
60
+ CalledByGroup = 41
61
+ }
62
+ export declare abstract class WitnessCondition {
63
+ readonly type: WitnessConditionType;
64
+ protected constructor(type: WitnessConditionType);
65
+ marshalTo(writer: BinaryWriter): void;
66
+ static unmarshalFrom(reader: BinaryReader): WitnessCondition;
67
+ toJSON(): WitnessConditionJson;
68
+ }
69
+ export declare class BooleanCondition extends WitnessCondition {
70
+ readonly expression: boolean;
71
+ constructor(expression: boolean);
72
+ marshalTo(writer: BinaryWriter): void;
73
+ toJSON(): BooleanConditionJson;
74
+ }
75
+ export declare class NotCondition extends WitnessCondition {
76
+ readonly expression: WitnessCondition;
77
+ constructor(expression: WitnessCondition);
78
+ marshalTo(writer: BinaryWriter): void;
79
+ toJSON(): NotConditionJson;
80
+ }
81
+ export declare class AndCondition extends WitnessCondition {
82
+ readonly expressions: WitnessCondition[];
83
+ constructor(expressions: WitnessCondition[]);
84
+ marshalTo(writer: BinaryWriter): void;
85
+ toJSON(): AndConditionJson;
86
+ }
87
+ export declare class OrCondition extends WitnessCondition {
88
+ readonly expressions: WitnessCondition[];
89
+ constructor(expressions: WitnessCondition[]);
90
+ marshalTo(writer: BinaryWriter): void;
91
+ toJSON(): OrConditionJson;
92
+ }
93
+ export declare class ScriptHashCondition extends WitnessCondition {
94
+ readonly hash: H160;
95
+ constructor(hash: H160);
96
+ marshalTo(writer: BinaryWriter): void;
97
+ toJSON(): ScriptHashConditionJson;
98
+ }
99
+ export declare class GroupCondition extends WitnessCondition {
100
+ readonly group: PublicKey;
101
+ constructor(group: PublicKey);
102
+ marshalTo(writer: BinaryWriter): void;
103
+ toJSON(): GroupConditionJson;
104
+ }
105
+ export declare class CalledByEntryCondition extends WitnessCondition {
106
+ constructor();
107
+ toJSON(): CalledByEntryConditionJson;
108
+ }
109
+ export declare class CalledByContractCondition extends WitnessCondition {
110
+ readonly hash: H160;
111
+ constructor(hash: H160);
112
+ marshalTo(writer: BinaryWriter): void;
113
+ toJSON(): CalledByContractConditionJson;
114
+ }
115
+ export declare class CalledByGroupCondition extends WitnessCondition {
116
+ readonly group: PublicKey;
117
+ constructor(group: PublicKey);
118
+ marshalTo(writer: BinaryWriter): void;
119
+ toJSON(): CalledByGroupConditionJson;
120
+ }
121
+ export declare class WitnessRule {
122
+ readonly action: WitnessRuleAction;
123
+ readonly conditions: WitnessCondition[];
124
+ constructor(action: WitnessRuleAction, conditions: WitnessCondition[]);
125
+ marshalTo(writer: BinaryWriter): void;
126
+ static unmarshalFrom(reader: BinaryReader): WitnessRule;
127
+ toJSON(): WitnessRuleJson;
128
+ }
@@ -0,0 +1,201 @@
1
+ import { H160 } from "./hash.js";
2
+ import { PublicKey } from "./keypair.js";
3
+ export var WitnessRuleAction;
4
+ (function (WitnessRuleAction) {
5
+ WitnessRuleAction[WitnessRuleAction["Deny"] = 0] = "Deny";
6
+ WitnessRuleAction[WitnessRuleAction["Allow"] = 1] = "Allow";
7
+ })(WitnessRuleAction || (WitnessRuleAction = {}));
8
+ export var WitnessConditionType;
9
+ (function (WitnessConditionType) {
10
+ WitnessConditionType[WitnessConditionType["Boolean"] = 0] = "Boolean";
11
+ WitnessConditionType[WitnessConditionType["Not"] = 1] = "Not";
12
+ WitnessConditionType[WitnessConditionType["And"] = 2] = "And";
13
+ WitnessConditionType[WitnessConditionType["Or"] = 3] = "Or";
14
+ WitnessConditionType[WitnessConditionType["ScriptHash"] = 24] = "ScriptHash";
15
+ WitnessConditionType[WitnessConditionType["Group"] = 25] = "Group";
16
+ WitnessConditionType[WitnessConditionType["CalledByEntry"] = 32] = "CalledByEntry";
17
+ WitnessConditionType[WitnessConditionType["CalledByContract"] = 40] = "CalledByContract";
18
+ WitnessConditionType[WitnessConditionType["CalledByGroup"] = 41] = "CalledByGroup";
19
+ })(WitnessConditionType || (WitnessConditionType = {}));
20
+ export class WitnessCondition {
21
+ type;
22
+ constructor(type) {
23
+ this.type = type;
24
+ }
25
+ marshalTo(writer) {
26
+ writer.writeUInt8(this.type);
27
+ }
28
+ static unmarshalFrom(reader) {
29
+ const type = reader.readUInt8();
30
+ switch (type) {
31
+ case WitnessConditionType.Boolean:
32
+ return new BooleanCondition(reader.readBool());
33
+ case WitnessConditionType.Not:
34
+ return new NotCondition(WitnessCondition.unmarshalFrom(reader));
35
+ case WitnessConditionType.And:
36
+ return new AndCondition(reader.readMultiple(WitnessCondition));
37
+ case WitnessConditionType.Or:
38
+ return new OrCondition(reader.readMultiple(WitnessCondition));
39
+ case WitnessConditionType.ScriptHash:
40
+ return new ScriptHashCondition(H160.unmarshalFrom(reader));
41
+ case WitnessConditionType.Group:
42
+ return new GroupCondition(PublicKey.unmarshalFrom(reader));
43
+ case WitnessConditionType.CalledByEntry:
44
+ return new CalledByEntryCondition();
45
+ case WitnessConditionType.CalledByContract:
46
+ return new CalledByContractCondition(H160.unmarshalFrom(reader));
47
+ case WitnessConditionType.CalledByGroup:
48
+ return new CalledByGroupCondition(PublicKey.unmarshalFrom(reader));
49
+ default:
50
+ throw new Error(`unexpected WitnessConditionType: ${type}`);
51
+ }
52
+ }
53
+ toJSON() {
54
+ return { type: WitnessConditionType[this.type] };
55
+ }
56
+ }
57
+ export class BooleanCondition extends WitnessCondition {
58
+ expression;
59
+ constructor(expression) {
60
+ super(WitnessConditionType.Boolean);
61
+ this.expression = expression;
62
+ }
63
+ marshalTo(writer) {
64
+ super.marshalTo(writer);
65
+ writer.writeBool(this.expression);
66
+ }
67
+ toJSON() {
68
+ return { type: "Boolean", expression: this.expression };
69
+ }
70
+ }
71
+ export class NotCondition extends WitnessCondition {
72
+ expression;
73
+ constructor(expression) {
74
+ super(WitnessConditionType.Not);
75
+ this.expression = expression;
76
+ }
77
+ marshalTo(writer) {
78
+ super.marshalTo(writer);
79
+ this.expression.marshalTo(writer);
80
+ }
81
+ toJSON() {
82
+ return { type: "Not", expression: this.expression.toJSON() };
83
+ }
84
+ }
85
+ export class AndCondition extends WitnessCondition {
86
+ expressions;
87
+ constructor(expressions) {
88
+ super(WitnessConditionType.And);
89
+ this.expressions = expressions;
90
+ }
91
+ marshalTo(writer) {
92
+ super.marshalTo(writer);
93
+ writer.writeMultiple(this.expressions);
94
+ }
95
+ toJSON() {
96
+ return { type: "And", expressions: this.expressions.map((expression) => expression.toJSON()) };
97
+ }
98
+ }
99
+ export class OrCondition extends WitnessCondition {
100
+ expressions;
101
+ constructor(expressions) {
102
+ super(WitnessConditionType.Or);
103
+ this.expressions = expressions;
104
+ }
105
+ marshalTo(writer) {
106
+ super.marshalTo(writer);
107
+ writer.writeMultiple(this.expressions);
108
+ }
109
+ toJSON() {
110
+ return { type: "Or", expressions: this.expressions.map((expression) => expression.toJSON()) };
111
+ }
112
+ }
113
+ export class ScriptHashCondition extends WitnessCondition {
114
+ hash;
115
+ constructor(hash) {
116
+ super(WitnessConditionType.ScriptHash);
117
+ this.hash = hash;
118
+ }
119
+ marshalTo(writer) {
120
+ super.marshalTo(writer);
121
+ this.hash.marshalTo(writer);
122
+ }
123
+ toJSON() {
124
+ return { type: "ScriptHash", hash: this.hash.toString() };
125
+ }
126
+ }
127
+ export class GroupCondition extends WitnessCondition {
128
+ group;
129
+ constructor(group) {
130
+ super(WitnessConditionType.Group);
131
+ this.group = group;
132
+ }
133
+ marshalTo(writer) {
134
+ super.marshalTo(writer);
135
+ this.group.marshalTo(writer);
136
+ }
137
+ toJSON() {
138
+ return { type: "Group", group: this.group.toString() };
139
+ }
140
+ }
141
+ export class CalledByEntryCondition extends WitnessCondition {
142
+ constructor() {
143
+ super(WitnessConditionType.CalledByEntry);
144
+ }
145
+ toJSON() {
146
+ return { type: "CalledByEntry" };
147
+ }
148
+ }
149
+ export class CalledByContractCondition extends WitnessCondition {
150
+ hash;
151
+ constructor(hash) {
152
+ super(WitnessConditionType.CalledByContract);
153
+ this.hash = hash;
154
+ }
155
+ marshalTo(writer) {
156
+ super.marshalTo(writer);
157
+ this.hash.marshalTo(writer);
158
+ }
159
+ toJSON() {
160
+ return { type: "CalledByContract", hash: this.hash.toString() };
161
+ }
162
+ }
163
+ export class CalledByGroupCondition extends WitnessCondition {
164
+ group;
165
+ constructor(group) {
166
+ super(WitnessConditionType.CalledByGroup);
167
+ this.group = group;
168
+ }
169
+ marshalTo(writer) {
170
+ super.marshalTo(writer);
171
+ this.group.marshalTo(writer);
172
+ }
173
+ toJSON() {
174
+ return { type: "CalledByGroup", group: this.group.toString() };
175
+ }
176
+ }
177
+ export class WitnessRule {
178
+ action;
179
+ conditions;
180
+ constructor(action, conditions) {
181
+ this.action = action;
182
+ this.conditions = conditions;
183
+ }
184
+ marshalTo(writer) {
185
+ writer.writeUInt8(this.action);
186
+ writer.writeMultiple(this.conditions);
187
+ }
188
+ static unmarshalFrom(reader) {
189
+ const action = reader.readUInt8();
190
+ if (!Object.values(WitnessRuleAction).includes(action)) {
191
+ throw new Error(`unexpected WitnessRuleAction: ${action}`);
192
+ }
193
+ return new WitnessRule(action, reader.readMultiple(WitnessCondition));
194
+ }
195
+ toJSON() {
196
+ return {
197
+ action: this.action === WitnessRuleAction.Allow ? "Allow" : "Deny",
198
+ conditions: this.conditions.map((condition) => condition.toJSON())
199
+ };
200
+ }
201
+ }
@@ -0,0 +1,24 @@
1
+ import { BinaryReader, BinaryWriter } from "./serializing.js";
2
+ export declare enum WitnessScope {
3
+ None = 0,
4
+ CalledByEntry = 1,
5
+ CustomContracts = 16,
6
+ CustomGroups = 32,
7
+ WitnessRules = 64,
8
+ Global = 128
9
+ }
10
+ export declare function witnessScopeName(scope: WitnessScope): string;
11
+ export declare class Witness {
12
+ invocation: Uint8Array;
13
+ verification: Uint8Array;
14
+ constructor(invocation: Uint8Array, verification: Uint8Array);
15
+ get invocationScript(): Uint8Array;
16
+ get verificationScript(): Uint8Array;
17
+ marshalTo(writer: BinaryWriter): void;
18
+ static unmarshalFrom(reader: BinaryReader): Witness;
19
+ toJSON(): {
20
+ invocation: string;
21
+ verification: string;
22
+ };
23
+ equals(other: Witness): boolean;
24
+ }
@@ -0,0 +1,62 @@
1
+ import { bytesToBase64, equalBytes } from "../internal/bytes.js";
2
+ export var WitnessScope;
3
+ (function (WitnessScope) {
4
+ WitnessScope[WitnessScope["None"] = 0] = "None";
5
+ WitnessScope[WitnessScope["CalledByEntry"] = 1] = "CalledByEntry";
6
+ WitnessScope[WitnessScope["CustomContracts"] = 16] = "CustomContracts";
7
+ WitnessScope[WitnessScope["CustomGroups"] = 32] = "CustomGroups";
8
+ WitnessScope[WitnessScope["WitnessRules"] = 64] = "WitnessRules";
9
+ WitnessScope[WitnessScope["Global"] = 128] = "Global";
10
+ })(WitnessScope || (WitnessScope = {}));
11
+ export function witnessScopeName(scope) {
12
+ if (scope === WitnessScope.None) {
13
+ return "None";
14
+ }
15
+ const flags = [];
16
+ if (scope & WitnessScope.CalledByEntry) {
17
+ flags.push("CalledByEntry");
18
+ }
19
+ if (scope & WitnessScope.CustomContracts) {
20
+ flags.push("CustomContracts");
21
+ }
22
+ if (scope & WitnessScope.CustomGroups) {
23
+ flags.push("CustomGroups");
24
+ }
25
+ if (scope & WitnessScope.WitnessRules) {
26
+ flags.push("WitnessRules");
27
+ }
28
+ if (scope & WitnessScope.Global) {
29
+ flags.push("Global");
30
+ }
31
+ return flags.join(",");
32
+ }
33
+ export class Witness {
34
+ invocation;
35
+ verification;
36
+ constructor(invocation, verification) {
37
+ this.invocation = invocation;
38
+ this.verification = verification;
39
+ }
40
+ get invocationScript() {
41
+ return this.invocation;
42
+ }
43
+ get verificationScript() {
44
+ return this.verification;
45
+ }
46
+ marshalTo(writer) {
47
+ writer.writeVarBytes(this.invocation);
48
+ writer.writeVarBytes(this.verification);
49
+ }
50
+ static unmarshalFrom(reader) {
51
+ return new Witness(reader.readVarBytes(), reader.readVarBytes());
52
+ }
53
+ toJSON() {
54
+ return {
55
+ invocation: bytesToBase64(this.invocation),
56
+ verification: bytesToBase64(this.verification),
57
+ };
58
+ }
59
+ equals(other) {
60
+ return equalBytes(this.invocation, other.invocation) && equalBytes(this.verification, other.verification);
61
+ }
62
+ }
@@ -0,0 +1,16 @@
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, type AndConditionJson, type BaseWitnessConditionJson, type BooleanConditionJson, BooleanCondition, CalledByContractCondition, type CalledByContractConditionJson, CalledByEntryCondition, type CalledByEntryConditionJson, CalledByGroupCondition, type CalledByGroupConditionJson, GroupCondition, type GroupConditionJson, NotCondition, type NotConditionJson, OrCondition, type OrConditionJson, ScriptHashCondition, type ScriptHashConditionJson, WitnessCondition, type WitnessConditionJson, WitnessConditionType, WitnessRule, type WitnessRuleJson, WitnessRuleAction } from "./core/witness-rule.js";
11
+ export { type BaseTxAttributeJson, type ConflictsAttributeJson, ConflictsAttribute, type HighPriorityAttributeJson, HighPriorityAttribute, type NotaryAssistedAttributeJson, NotValidBeforeAttribute, type NotValidBeforeAttributeJson, NotaryAssistedAttribute, type OracleResponseAttributeJson, OracleResponseAttribute, OracleResponseCode, Signer, type SignerJson, Tx, TxAttribute, type TxAttributeJson, 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 type { ApplicationLogExecution, ApplicationLogInvocation, CalculateNetworkFeeInput, CancelTransactionResult, CancelTransactionInput, CloseWalletResult, DumpPrivKeyInput, DumpPrivKeyResult, FindStatesInput, FindStatesResult, FindStorageEntry, FindStorageInput, FindStorageResult, GetApplicationLogInput, GetApplicationLogResult, GetBlockHashInput, GetBlockHeaderInput, GetBlockHeaderCountResult, GetBlockHeaderVerboseResult, GetBlockInput, GetBlockVerboseResult, GetCandidatesResult, GetConnectionCountResult, GetContractStateInput, GetContractStateManifestAbiResult, GetContractStateManifestEventResult, GetContractStateManifestGroupResult, GetContractStateManifestMethodResult, GetContractStateManifestParameterResult, GetContractStateManifestPermissionResult, GetContractStateManifestResult, GetContractStateNefMethodTokenResult, GetContractStateNefResult, GetContractStateResult, GetNativeContractsResult, GetNep11BalancesInput, GetNep11BalancesResult, GetNep11PropertiesInput, GetNep11PropertiesResult, GetNep11PropertyValueResult, GetNep11TransfersInput, GetNep11TransfersResult, GetNep17BalancesResult, GetNep17BalancesInput, GetNep17TransfersInput, GetNep17TransfersResult, GetNewAddressResult, GetPeersResult, GetProofInput, GetProofResult, GetRawMemPoolResult, GetRawMemPoolVerboseResult, GetRawTransactionInput, GetRawTransactionResult, GetStateInput, GetStateHeightResult, GetStateResult, GetStateRootInput, GetStateRootResult, GetStorageInput, GetStorageResult, GetTransactionHeightInput, GetUnclaimedGasInput, GetUnclaimedGasResult, GetUnspentsInput, GetUnspentsResult, GetVersionHardforkResult, GetVersionProtocolResult, GetVersionResult, GetVersionRpcSettingsResult, GetWalletBalanceInput, GetWalletUnclaimedGasResult, ImportPrivKeyInput, ImportPrivKeyResult, InvokeContractVerifyResult, InvokeContractVerifyInput, InvokeDiagnosticsInvocationTree, InvokeDiagnosticsResult, InvokeDiagnosticsStorageChange, InvokeFunctionInput, InvokeParametersLike, InvokeResult, InvokeScriptInput, ListAddressResult, ListPluginsResult, Nep11Balance, Nep11TokenBalance, Nep11TransferEvent, Nep17Balance, Nep17TransferEvent, NetworkFeeResult, NodePeer, OpenWalletResult, OpenWalletInput, PendingSignatureContextItem, PendingSignatureResult, RelayTransactionResult, RpcBinaryPayload, RpcAccountResult, RpcAnyStackItemJson, RpcArrayStackItemJson, RpcBaseStackItemJson, RpcBooleanStackItemJson, RpcBufferStackItemJson, RpcByteStringStackItemJson, RpcIntegerStackItemJson, RpcInteropInterfaceStackItemJson, RpcMapStackEntryJson, RpcMapStackItemJson, RpcNotification, RpcPlugin, RpcPointerStackItemJson, RpcSignerJson, RpcSignerInput, RpcStackItemJson, RpcStructStackItemJson, RpcValidatorResult, RpcWitnessJson, SendFromInput, SendManyInput, SendManyTransferInput, SendRawTransactionResult, SendRawTransactionInput, SendToAddressInput, SubmitBlockResult, SubmitBlockInput, TerminateSessionResult, TraverseIteratorInput, TransactionJsonResult, TraverseIteratorResult, UnspentBalance, UnspentTransaction, ValidateAddressInput, ValidateAddressResult, VerifyProofInput, WalletBalanceResult } from "./rpcclient/types.js";
15
+ export { Account, Contract, Parameter, ScryptParams, Wallet, decryptSecp256r1Key, encryptSecp256r1Key } from "./wallet/index.js";
16
+ export { hash160, hexstring2str, num2hexstring, reverseHex, str2hexstring } from "./utils.js";