@alephium/web3 0.2.0-rc.2 → 0.2.0-rc.21

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 (121) hide show
  1. package/.eslintignore +2 -2
  2. package/README.md +2 -135
  3. package/dist/alephium-web3.min.js +1 -1
  4. package/dist/alephium-web3.min.js.LICENSE.txt +0 -17
  5. package/dist/alephium-web3.min.js.map +1 -1
  6. package/dist/src/api/api-alephium.d.ts +126 -22
  7. package/dist/src/api/api-alephium.js +145 -79
  8. package/dist/src/api/api-explorer.d.ts +163 -48
  9. package/dist/src/api/api-explorer.js +157 -34
  10. package/dist/src/api/index.d.ts +3 -2
  11. package/dist/src/api/index.js +22 -3
  12. package/dist/src/api/types.d.ts +23 -0
  13. package/dist/src/api/types.js +240 -0
  14. package/dist/src/api/utils.d.ts +6 -0
  15. package/dist/{scripts/rename-gitignore.js → src/api/utils.js} +11 -6
  16. package/dist/src/contract/contract.d.ts +117 -69
  17. package/dist/src/contract/contract.js +401 -435
  18. package/dist/src/contract/events.d.ts +4 -4
  19. package/dist/src/contract/index.js +5 -1
  20. package/dist/src/contract/ralph.d.ts +5 -4
  21. package/dist/src/contract/ralph.js +27 -1
  22. package/dist/src/global.d.ts +4 -0
  23. package/dist/{scripts/stop-devnet.js → src/global.js} +17 -11
  24. package/dist/src/index.d.ts +2 -0
  25. package/dist/src/index.js +23 -1
  26. package/dist/src/signer/index.d.ts +0 -1
  27. package/dist/src/signer/index.js +5 -2
  28. package/dist/src/signer/signer.d.ts +21 -11
  29. package/dist/src/signer/signer.js +46 -9
  30. package/dist/src/transaction/index.d.ts +0 -1
  31. package/dist/src/transaction/index.js +5 -2
  32. package/dist/src/transaction/status.d.ts +2 -1
  33. package/dist/src/utils/bs58.d.ts +1 -0
  34. package/dist/src/utils/bs58.js +13 -1
  35. package/dist/src/utils/index.d.ts +0 -1
  36. package/dist/src/utils/index.js +5 -2
  37. package/dist/src/utils/subscription.d.ts +0 -1
  38. package/dist/src/utils/subscription.js +2 -1
  39. package/dist/src/utils/utils.d.ts +6 -11
  40. package/dist/src/utils/utils.js +21 -25
  41. package/jest-config.json +11 -0
  42. package/package.json +11 -47
  43. package/src/api/api-alephium.ts +178 -30
  44. package/src/api/api-explorer.ts +234 -51
  45. package/src/api/index.ts +14 -3
  46. package/src/api/types.ts +233 -0
  47. package/{scripts/rename-gitignore.js → src/api/utils.ts} +7 -6
  48. package/src/contract/contract.ts +602 -527
  49. package/src/contract/events.ts +6 -6
  50. package/src/contract/ralph.ts +29 -4
  51. package/src/{transaction/sign-verify.ts → global.ts} +14 -15
  52. package/src/index.ts +7 -0
  53. package/src/signer/index.ts +0 -1
  54. package/src/signer/signer.ts +70 -19
  55. package/src/transaction/index.ts +0 -1
  56. package/src/transaction/status.ts +4 -2
  57. package/src/utils/bs58.ts +11 -0
  58. package/src/utils/index.ts +0 -1
  59. package/src/utils/subscription.ts +3 -3
  60. package/src/utils/utils.ts +14 -22
  61. package/.eslintrc.json +0 -21
  62. package/LICENSE +0 -165
  63. package/contracts/add/add.ral +0 -16
  64. package/contracts/greeter/greeter.ral +0 -7
  65. package/contracts/greeter/greeter_interface.ral +0 -3
  66. package/contracts/greeter_main.ral +0 -9
  67. package/contracts/main.ral +0 -6
  68. package/contracts/sub/sub.ral +0 -9
  69. package/dev/user.conf +0 -29
  70. package/dist/scripts/create-project.d.ts +0 -2
  71. package/dist/scripts/create-project.js +0 -125
  72. package/dist/scripts/rename-gitignore.d.ts +0 -1
  73. package/dist/scripts/start-devnet.d.ts +0 -1
  74. package/dist/scripts/start-devnet.js +0 -131
  75. package/dist/scripts/stop-devnet.d.ts +0 -1
  76. package/dist/src/signer/node-wallet.d.ts +0 -13
  77. package/dist/src/signer/node-wallet.js +0 -60
  78. package/dist/src/test/index.d.ts +0 -7
  79. package/dist/src/test/index.js +0 -41
  80. package/dist/src/test/privatekey-wallet.d.ts +0 -12
  81. package/dist/src/test/privatekey-wallet.js +0 -68
  82. package/dist/src/transaction/sign-verify.d.ts +0 -2
  83. package/dist/src/transaction/sign-verify.js +0 -58
  84. package/dist/src/utils/password-crypto.d.ts +0 -2
  85. package/dist/src/utils/password-crypto.js +0 -69
  86. package/gitignore +0 -10
  87. package/scripts/create-project.ts +0 -137
  88. package/scripts/start-devnet.js +0 -141
  89. package/scripts/stop-devnet.js +0 -32
  90. package/src/contract/ralph.test.ts +0 -178
  91. package/src/fixtures/address.json +0 -36
  92. package/src/fixtures/balance.json +0 -9
  93. package/src/fixtures/self-clique.json +0 -19
  94. package/src/fixtures/transaction.json +0 -13
  95. package/src/fixtures/transactions.json +0 -179
  96. package/src/signer/fixtures/genesis.json +0 -26
  97. package/src/signer/fixtures/wallets.json +0 -26
  98. package/src/signer/node-wallet.ts +0 -74
  99. package/src/test/index.ts +0 -32
  100. package/src/test/privatekey-wallet.ts +0 -58
  101. package/src/transaction/sign-verify.test.ts +0 -50
  102. package/src/utils/address.test.ts +0 -47
  103. package/src/utils/djb2.test.ts +0 -35
  104. package/src/utils/password-crypto.test.ts +0 -27
  105. package/src/utils/password-crypto.ts +0 -77
  106. package/src/utils/utils.test.ts +0 -161
  107. package/templates/base/README.md +0 -34
  108. package/templates/base/package.json +0 -35
  109. package/templates/base/src/greeter.ts +0 -41
  110. package/templates/base/tsconfig.json +0 -19
  111. package/templates/react/README.md +0 -34
  112. package/templates/react/config-overrides.js +0 -18
  113. package/templates/react/package.json +0 -66
  114. package/templates/react/src/App.tsx +0 -42
  115. package/templates/react/src/artifacts/greeter.ral.json +0 -26
  116. package/templates/react/src/artifacts/greeter_main.ral.json +0 -22
  117. package/templates/shared/.eslintrc.json +0 -12
  118. package/templates/shared/scripts/header.js +0 -0
  119. package/test/contract.test.ts +0 -178
  120. package/test/events.test.ts +0 -138
  121. package/test/transaction.test.ts +0 -72
@@ -1,10 +1,11 @@
1
1
  import { Api as NodeApi } from './api-alephium';
2
2
  import { Api as ExplorerApi } from './api-explorer';
3
- export declare class NodeProvider extends NodeApi<null> {
4
- constructor(baseUrl: string);
3
+ export declare class NodeProvider extends NodeApi<string> {
4
+ constructor(baseUrl: string, apiKey?: string);
5
5
  }
6
6
  export declare class ExplorerProvider extends ExplorerApi<null> {
7
7
  constructor(baseUrl: string);
8
8
  }
9
9
  export * as node from './api-alephium';
10
10
  export * as explorer from './api-explorer';
11
+ export * from './types';
@@ -18,7 +18,11 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
18
  */
19
19
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
20
20
  if (k2 === undefined) k2 = k;
21
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
21
+ var desc = Object.getOwnPropertyDescriptor(m, k);
22
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
23
+ desc = { enumerable: true, get: function() { return m[k]; } };
24
+ }
25
+ Object.defineProperty(o, k2, desc);
22
26
  }) : (function(o, m, k, k2) {
23
27
  if (k2 === undefined) k2 = k;
24
28
  o[k2] = m[k];
@@ -35,13 +39,27 @@ var __importStar = (this && this.__importStar) || function (mod) {
35
39
  __setModuleDefault(result, mod);
36
40
  return result;
37
41
  };
42
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
43
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
44
+ };
38
45
  Object.defineProperty(exports, "__esModule", { value: true });
39
46
  exports.explorer = exports.node = exports.ExplorerProvider = exports.NodeProvider = void 0;
40
47
  const api_alephium_1 = require("./api-alephium");
41
48
  const api_explorer_1 = require("./api-explorer");
42
49
  class NodeProvider extends api_alephium_1.Api {
43
- constructor(baseUrl) {
44
- super({ baseUrl: baseUrl });
50
+ constructor(baseUrl, apiKey) {
51
+ // eslint-disable-next-line security/detect-possible-timing-attacks
52
+ if (apiKey === undefined) {
53
+ super({ baseUrl: baseUrl });
54
+ }
55
+ else {
56
+ super({
57
+ baseUrl: baseUrl,
58
+ baseApiParams: { secure: true },
59
+ securityWorker: (accessToken) => (accessToken !== null ? { headers: { 'X-API-KEY': `${accessToken}` } } : {})
60
+ });
61
+ this.setSecurityData(apiKey);
62
+ }
45
63
  }
46
64
  }
47
65
  exports.NodeProvider = NodeProvider;
@@ -53,3 +71,4 @@ class ExplorerProvider extends api_explorer_1.Api {
53
71
  exports.ExplorerProvider = ExplorerProvider;
54
72
  exports.node = __importStar(require("./api-alephium"));
55
73
  exports.explorer = __importStar(require("./api-explorer"));
74
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,23 @@
1
+ import * as node from './api-alephium';
2
+ export declare type Number256 = number | bigint | string;
3
+ export declare type Val = Number256 | boolean | string | Val[];
4
+ export declare type NamedVals = Record<string, Val>;
5
+ export interface Token {
6
+ id: string;
7
+ amount: Number256;
8
+ }
9
+ export declare function toApiToken(token: Token): node.Token;
10
+ export declare function toApiTokens(tokens?: Token[]): node.Token[] | undefined;
11
+ export declare function fromApiToken(token: node.Token): Token;
12
+ export declare function fromApiTokens(tokens?: node.Token[]): Token[] | undefined;
13
+ export declare function toApiBoolean(v: Val): boolean;
14
+ export declare function toApiNumber256(v: Val): string;
15
+ export declare function toApiNumber256Optional(v?: Val): string | undefined;
16
+ export declare function fromApiNumber256(n: string): Number256;
17
+ export declare function toApiByteVec(v: Val): string;
18
+ export declare function toApiAddress(v: Val): string;
19
+ export declare function toApiArray(tpe: string, v: Val): node.Val;
20
+ export declare function toApiVal(v: Val, tpe: string): node.Val;
21
+ export declare function fromApiVals(vals: node.Val[], names: string[], types: string[]): NamedVals;
22
+ export declare function fromApiArray(vals: node.Val[], types: string[]): Val[];
23
+ export declare function fromApiVal(v: node.Val, tpe: string): Val;
@@ -0,0 +1,240 @@
1
+ "use strict";
2
+ /*
3
+ Copyright 2018 - 2022 The Alephium Authors
4
+ This file is part of the alephium project.
5
+
6
+ The library is free software: you can redistribute it and/or modify
7
+ it under the terms of the GNU Lesser General Public License as published by
8
+ the Free Software Foundation, either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ The library is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public License
17
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.fromApiVal = exports.fromApiArray = exports.fromApiVals = exports.toApiVal = exports.toApiArray = exports.toApiAddress = exports.toApiByteVec = exports.fromApiNumber256 = exports.toApiNumber256Optional = exports.toApiNumber256 = exports.toApiBoolean = exports.fromApiTokens = exports.fromApiToken = exports.toApiTokens = exports.toApiToken = void 0;
21
+ const utils_1 = require("../utils");
22
+ utils_1.assertType;
23
+ function toApiToken(token) {
24
+ return { id: token.id, amount: toApiNumber256(token.amount) };
25
+ }
26
+ exports.toApiToken = toApiToken;
27
+ function toApiTokens(tokens) {
28
+ return tokens?.map(toApiToken);
29
+ }
30
+ exports.toApiTokens = toApiTokens;
31
+ function fromApiToken(token) {
32
+ return { id: token.id, amount: fromApiNumber256(token.amount) };
33
+ }
34
+ exports.fromApiToken = fromApiToken;
35
+ function fromApiTokens(tokens) {
36
+ return tokens?.map(fromApiToken);
37
+ }
38
+ exports.fromApiTokens = fromApiTokens;
39
+ function toApiBoolean(v) {
40
+ if (typeof v === 'boolean') {
41
+ return v;
42
+ }
43
+ else {
44
+ throw new Error(`Invalid boolean value: ${v}`);
45
+ }
46
+ }
47
+ exports.toApiBoolean = toApiBoolean;
48
+ // TODO: check integer bounds
49
+ function toApiNumber256(v) {
50
+ if ((typeof v === 'number' && Number.isInteger(v)) || typeof v === 'bigint') {
51
+ return v.toString();
52
+ }
53
+ else if (typeof v === 'string') {
54
+ return v;
55
+ }
56
+ else {
57
+ throw new Error(`Invalid 256 bit number: ${v}`);
58
+ }
59
+ }
60
+ exports.toApiNumber256 = toApiNumber256;
61
+ function toApiNumber256Optional(v) {
62
+ return v === undefined ? undefined : toApiNumber256(v);
63
+ }
64
+ exports.toApiNumber256Optional = toApiNumber256Optional;
65
+ function fromApiNumber256(n) {
66
+ if (Number.isSafeInteger(Number.parseInt(n))) {
67
+ return Number(n);
68
+ }
69
+ else {
70
+ return BigInt(n);
71
+ }
72
+ }
73
+ exports.fromApiNumber256 = fromApiNumber256;
74
+ // TODO: check hex string
75
+ function toApiByteVec(v) {
76
+ if (typeof v === 'string') {
77
+ // try to convert from address to contract id
78
+ try {
79
+ const address = utils_1.bs58.decode(v);
80
+ if (address.length == 33 && address[0] == 3) {
81
+ return Buffer.from(address.slice(1)).toString('hex');
82
+ }
83
+ }
84
+ catch (_) {
85
+ return v;
86
+ }
87
+ return v;
88
+ }
89
+ else {
90
+ throw new Error(`Invalid string: ${v}`);
91
+ }
92
+ }
93
+ exports.toApiByteVec = toApiByteVec;
94
+ function toApiAddress(v) {
95
+ if (typeof v === 'string') {
96
+ try {
97
+ utils_1.bs58.decode(v);
98
+ return v;
99
+ }
100
+ catch (error) {
101
+ throw new Error(`Invalid base58 string: ${v}`);
102
+ }
103
+ }
104
+ else {
105
+ throw new Error(`Invalid string: ${v}`);
106
+ }
107
+ }
108
+ exports.toApiAddress = toApiAddress;
109
+ function toApiArray(tpe, v) {
110
+ if (!Array.isArray(v)) {
111
+ throw new Error(`Expected array, got ${v}`);
112
+ }
113
+ const semiColonIndex = tpe.lastIndexOf(';');
114
+ if (semiColonIndex == -1) {
115
+ throw new Error(`Invalid Val type: ${tpe}`);
116
+ }
117
+ const subType = tpe.slice(1, semiColonIndex);
118
+ const dim = parseInt(tpe.slice(semiColonIndex + 1, -1));
119
+ if (v.length != dim) {
120
+ throw new Error(`Invalid val dimension: ${v}`);
121
+ }
122
+ else {
123
+ return { value: v.map((v) => toApiVal(v, subType)), type: 'Array' };
124
+ }
125
+ }
126
+ exports.toApiArray = toApiArray;
127
+ function toApiVal(v, tpe) {
128
+ if (tpe === 'Bool') {
129
+ return { value: toApiBoolean(v), type: tpe };
130
+ }
131
+ else if (tpe === 'U256' || tpe === 'I256') {
132
+ return { value: toApiNumber256(v), type: tpe };
133
+ }
134
+ else if (tpe === 'ByteVec') {
135
+ return { value: toApiByteVec(v), type: tpe };
136
+ }
137
+ else if (tpe === 'Address') {
138
+ return { value: toApiAddress(v), type: tpe };
139
+ }
140
+ else {
141
+ return toApiArray(tpe, v);
142
+ }
143
+ }
144
+ exports.toApiVal = toApiVal;
145
+ function _fromApiVal(vals, valIndex, tpe) {
146
+ if (vals.length === 0) {
147
+ throw new Error('Not enough Vals');
148
+ }
149
+ const firstVal = vals[`${valIndex}`];
150
+ if (tpe === 'Bool' && firstVal.type === tpe) {
151
+ return [firstVal.value, valIndex + 1];
152
+ }
153
+ else if ((tpe === 'U256' || tpe === 'I256') && firstVal.type === tpe) {
154
+ return [fromApiNumber256(firstVal.value), valIndex + 1];
155
+ }
156
+ else if ((tpe === 'ByteVec' || tpe === 'Address') && firstVal.type === tpe) {
157
+ return [firstVal.value, valIndex + 1];
158
+ }
159
+ else {
160
+ const [baseType, dims] = decodeArrayType(tpe);
161
+ const arraySize = dims.reduce((a, b) => a * b);
162
+ const nextIndex = valIndex + arraySize;
163
+ const valsToUse = vals.slice(valIndex, nextIndex);
164
+ if (valsToUse.length == arraySize && valsToUse.every((val) => val.type === baseType)) {
165
+ const localVals = valsToUse.map((val) => fromApiVal(val, baseType));
166
+ return [foldVals(localVals, dims), nextIndex];
167
+ }
168
+ else {
169
+ throw new Error(`Invalid array Val type: ${valsToUse}, ${tpe}`);
170
+ }
171
+ }
172
+ }
173
+ function fromApiVals(vals, names, types) {
174
+ let valIndex = 0;
175
+ const result = {};
176
+ types.forEach((currentType, index) => {
177
+ const currentName = names[`${index}`];
178
+ const [val, nextIndex] = _fromApiVal(vals, valIndex, currentType);
179
+ valIndex = nextIndex;
180
+ result[`${currentName}`] = val;
181
+ });
182
+ return result;
183
+ }
184
+ exports.fromApiVals = fromApiVals;
185
+ function fromApiArray(vals, types) {
186
+ let valIndex = 0;
187
+ const result = [];
188
+ for (const currentType of types) {
189
+ const [val, nextIndex] = _fromApiVal(vals, valIndex, currentType);
190
+ result.push(val);
191
+ valIndex = nextIndex;
192
+ }
193
+ return result;
194
+ }
195
+ exports.fromApiArray = fromApiArray;
196
+ function fromApiVal(v, tpe) {
197
+ if (v.type === 'Bool' && v.type === tpe) {
198
+ return v.value;
199
+ }
200
+ else if ((v.type === 'U256' || v.type === 'I256') && v.type === tpe) {
201
+ return fromApiNumber256(v.value);
202
+ }
203
+ else if ((v.type === 'ByteVec' || v.type === 'Address') && v.type === tpe) {
204
+ return v.value;
205
+ }
206
+ else {
207
+ throw new Error(`Invalid node.Val type: ${v}`);
208
+ }
209
+ }
210
+ exports.fromApiVal = fromApiVal;
211
+ function decodeArrayType(tpe) {
212
+ const semiColonIndex = tpe.lastIndexOf(';');
213
+ if (semiColonIndex === -1) {
214
+ throw new Error(`Invalid Val type: ${tpe}`);
215
+ }
216
+ const subType = tpe.slice(1, semiColonIndex);
217
+ const dim = parseInt(tpe.slice(semiColonIndex + 1, -1));
218
+ if (subType[0] == '[') {
219
+ const [baseType, subDim] = decodeArrayType(subType);
220
+ return [baseType, (subDim.unshift(dim), subDim)];
221
+ }
222
+ else {
223
+ return [subType, [dim]];
224
+ }
225
+ }
226
+ function foldVals(vals, dims) {
227
+ if (dims.length == 1) {
228
+ return vals;
229
+ }
230
+ else {
231
+ const result = [];
232
+ const chunkSize = vals.length / dims[0];
233
+ const chunkDims = dims.slice(1);
234
+ for (let i = 0; i < vals.length; i += chunkSize) {
235
+ const chunk = vals.slice(i, i + chunkSize);
236
+ result.push(foldVals(chunk, chunkDims));
237
+ }
238
+ return result;
239
+ }
240
+ }
@@ -0,0 +1,6 @@
1
+ export declare function convertHttpResponse<T>(response: {
2
+ data: T;
3
+ error?: {
4
+ detail: string;
5
+ };
6
+ }): T;
@@ -16,9 +16,14 @@ GNU Lesser General Public License for more details.
16
16
  You should have received a copy of the GNU Lesser General Public License
17
17
  along with the library. If not, see <http://www.gnu.org/licenses/>.
18
18
  */
19
- const { rename } = require('fs');
20
- rename(process.argv[2], process.argv[3], function (error) {
21
- if (error)
22
- console.log(error);
23
- console.log(`Renamed ${process.argv[2]} to ${process.argv[3]}.`);
24
- });
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.convertHttpResponse = void 0;
21
+ function convertHttpResponse(response) {
22
+ if (response.error) {
23
+ throw new Error(`[Node API Error] - ${response.error.detail}`);
24
+ }
25
+ else {
26
+ return response.data;
27
+ }
28
+ }
29
+ exports.convertHttpResponse = convertHttpResponse;
@@ -1,101 +1,147 @@
1
- import { NodeProvider } from '../api';
2
- import { node } from '../api';
1
+ import { NamedVals, node, Number256, Token, Val } from '../api';
3
2
  import { SignDeployContractTxParams, SignExecuteScriptTxParams, SignerWithNodeProvider } from '../signer';
3
+ export declare type FieldsSig = node.FieldsSig;
4
+ export declare type EventSig = node.EventSig;
5
+ export declare type FunctionSig = node.FunctionSig;
6
+ export declare type Fields = NamedVals;
7
+ export declare type Arguments = NamedVals;
8
+ declare enum SourceType {
9
+ Contract = 0,
10
+ Script = 1,
11
+ AbstractContract = 2,
12
+ Interface = 3
13
+ }
14
+ export declare type CompilerOptions = node.CompilerOptions & {
15
+ errorOnWarnings: boolean;
16
+ };
17
+ export declare const DEFAULT_NODE_COMPILER_OPTIONS: node.CompilerOptions;
18
+ export declare const DEFAULT_COMPILER_OPTIONS: CompilerOptions;
19
+ declare class TypedMatcher<T extends SourceType> {
20
+ matcher: RegExp;
21
+ type: T;
22
+ constructor(pattern: string, type: T);
23
+ match(str: string): number;
24
+ }
4
25
  declare class SourceFile {
5
- readonly dirs: string[];
6
- readonly dirPath: string;
7
- readonly contractPath: string;
8
- readonly artifactPath: string;
9
- constructor(dirs: string[], fileName: string);
10
- }
11
- export declare abstract class Common {
12
- readonly sourceCodeSha256: string;
13
- readonly functions: node.FunctionSig[];
14
- static readonly importRegex: RegExp;
15
- static readonly contractRegex: RegExp;
16
- static readonly interfaceRegex: RegExp;
17
- static readonly scriptRegex: RegExp;
18
- private static _artifactCache;
19
- static artifactCacheCapacity: number;
20
- protected static _getArtifactFromCache(codeHash: string): Contract | Script | undefined;
21
- protected static _putArtifactToCache(contract: Contract): void;
22
- constructor(sourceCodeSha256: string, functions: node.FunctionSig[]);
23
- protected static _artifactsFolder(): string;
24
- static getSourceFile(path: string, _dirs: string[]): SourceFile;
25
- protected static _handleImports(pathes: string[], contractStr: string, importsCache: string[]): Promise<string>;
26
- protected static _loadContractStr(sourceFile: SourceFile, importsCache: string[], validate: (code: string) => void): Promise<string>;
27
- static checkFileNameExtension(fileName: string): void;
28
- protected static _from<T extends {
29
- sourceCodeSha256: string;
30
- }>(provider: NodeProvider, sourceFile: SourceFile, loadContractStr: (sourceFile: SourceFile, importsCache: string[]) => Promise<string>, compile: (provider: NodeProvider, sourceFile: SourceFile, contractStr: string, contractHash: string) => Promise<T>): Promise<T>;
31
- protected _saveToFile(sourceFile: SourceFile): Promise<void>;
26
+ type: SourceType;
27
+ contractPath: string;
28
+ sourceCode: string;
29
+ sourceCodeHash: string;
30
+ getArtifactPath(artifactsRootDir: string): string;
31
+ constructor(type: SourceType, sourceCode: string, sourceCodeHash: string, contractPath: string);
32
+ static from(type: SourceType, sourceCode: string, contractPath: string): Promise<SourceFile>;
33
+ }
34
+ declare class Compiled<T extends Artifact> {
35
+ sourceFile: SourceFile;
36
+ artifact: T;
37
+ warnings: string[];
38
+ constructor(sourceFile: SourceFile, artifact: T, warnings: string[]);
39
+ }
40
+ declare type CodeInfo = {
41
+ sourceCodeHash: string;
42
+ bytecodeDebugPatch: string;
43
+ codeHashDebug: string;
44
+ warnings: string[];
45
+ };
46
+ declare class ProjectArtifact {
47
+ static readonly artifactFileName = ".project.json";
48
+ compilerOptionsUsed: node.CompilerOptions;
49
+ infos: Map<string, CodeInfo>;
50
+ static checkCompilerOptionsParameter(compilerOptions: node.CompilerOptions): void;
51
+ constructor(compilerOptionsUsed: node.CompilerOptions, infos: Map<string, CodeInfo>);
52
+ saveToFile(rootPath: string): Promise<void>;
53
+ needToReCompile(compilerOptions: node.CompilerOptions, files: SourceFile[]): boolean;
54
+ static from(rootPath: string): Promise<ProjectArtifact | undefined>;
55
+ }
56
+ export declare class Project {
57
+ sourceFiles: SourceFile[];
58
+ contracts: Compiled<Contract>[];
59
+ scripts: Compiled<Script>[];
60
+ projectArtifact: ProjectArtifact;
61
+ readonly contractsRootDir: string;
62
+ readonly artifactsRootDir: string;
63
+ static currentProject: Project;
64
+ static readonly abstractContractMatcher: TypedMatcher<SourceType>;
65
+ static readonly contractMatcher: TypedMatcher<SourceType.Contract>;
66
+ static readonly interfaceMatcher: TypedMatcher<SourceType.Interface>;
67
+ static readonly scriptMatcher: TypedMatcher<SourceType.Script>;
68
+ static readonly matchers: TypedMatcher<SourceType>[];
69
+ static buildProjectArtifact(sourceFiles: SourceFile[], contracts: Compiled<Contract>[], scripts: Compiled<Script>[], compilerOptions: node.CompilerOptions): ProjectArtifact;
70
+ private constructor();
71
+ private getContractPath;
72
+ static checkCompilerWarnings(warnings: string[], errorOnWarnings: boolean): void;
73
+ static contract(name: string): Contract;
74
+ static script(name: string): Script;
75
+ private saveArtifactsToFile;
76
+ contractByCodeHash(codeHash: string): Contract;
77
+ private static compile;
78
+ private static loadArtifacts;
79
+ private static loadSourceFile;
80
+ private static loadSourceFiles;
81
+ static readonly DEFAULT_CONTRACTS_DIR = "contracts";
82
+ static readonly DEFAULT_ARTIFACTS_DIR = "artifacts";
83
+ static build(compilerOptionsPartial?: Partial<CompilerOptions>, contractsRootDir?: string, artifactsRootDir?: string): Promise<void>;
84
+ }
85
+ export declare abstract class Artifact {
86
+ readonly name: string;
87
+ readonly functions: FunctionSig[];
88
+ constructor(name: string, functions: FunctionSig[]);
32
89
  abstract buildByteCodeToDeploy(initialFields?: Fields): string;
90
+ publicFunctions(): string[];
91
+ usingPreapprovedAssetsFunctions(): string[];
92
+ usingAssetsInContractFunctions(): string[];
33
93
  }
34
- export declare class Contract extends Common {
94
+ export declare class Contract extends Artifact {
35
95
  readonly bytecode: string;
96
+ readonly bytecodeDebugPatch: string;
36
97
  readonly codeHash: string;
37
- readonly fieldsSig: node.FieldsSig;
38
- readonly eventsSig: node.EventSig[];
39
- constructor(sourceCodeSha256: string, bytecode: string, codeHash: string, fieldsSig: node.FieldsSig, eventsSig: node.EventSig[], functions: node.FunctionSig[]);
40
- static checkCodeType(fileName: string, contractStr: string): void;
41
- private static loadContractStr;
42
- static fromSource(provider: NodeProvider, path: string): Promise<Contract>;
43
- private static compile;
44
- static fromJson(artifact: any): Contract;
45
- static fromArtifactFile(path: string): Promise<Contract>;
46
- fetchState(provider: NodeProvider, address: string, group: number): Promise<ContractState>;
98
+ readonly fieldsSig: FieldsSig;
99
+ readonly eventsSig: EventSig[];
100
+ readonly bytecodeDebug: string;
101
+ readonly codeHashDebug: string;
102
+ constructor(name: string, bytecode: string, bytecodeDebugPatch: string, codeHash: string, codeHashDebug: string, fieldsSig: FieldsSig, eventsSig: EventSig[], functions: FunctionSig[]);
103
+ static fromJson(artifact: any, bytecodeDebugPatch?: string, codeHashDebug?: string): Contract;
104
+ static fromCompileResult(result: node.CompileContractResult): Contract;
105
+ static fromArtifactFile(path: string, bytecodeDebugPatch: string, codeHashDebug: string): Promise<Contract>;
106
+ fetchState(address: string, group: number): Promise<ContractState>;
47
107
  toString(): string;
48
108
  toState(fields: Fields, asset: Asset, address?: string): ContractState;
49
109
  static randomAddress(): string;
110
+ private _printDebugMessages;
50
111
  private _test;
51
- testPublicMethod(provider: NodeProvider, funcName: string, params: TestContractParams): Promise<TestContractResult>;
52
- testPrivateMethod(provider: NodeProvider, funcName: string, params: TestContractParams): Promise<TestContractResult>;
112
+ testPublicMethod(funcName: string, params: TestContractParams, printDebugMessages?: boolean): Promise<TestContractResult>;
113
+ testPrivateMethod(funcName: string, params: TestContractParams, printDebugMessages?: boolean): Promise<TestContractResult>;
53
114
  toApiFields(fields?: Fields): node.Val[];
54
115
  toApiArgs(funcName: string, args?: Arguments): node.Val[];
55
116
  getMethodIndex(funcName: string): number;
56
117
  toApiContractStates(states?: ContractState[]): node.ContractState[] | undefined;
57
118
  toTestContract(funcName: string, params: TestContractParams): node.TestContract;
58
- static fromCodeHash(codeHash: string): Promise<Contract>;
59
- static getFieldsSig(state: node.ContractState): Promise<node.FieldsSig>;
60
119
  fromApiContractState(state: node.ContractState): Promise<ContractState>;
61
- static ContractCreatedEvent: node.EventSig;
62
- static ContractDestroyedEvent: node.EventSig;
120
+ static ContractCreatedEvent: EventSig;
121
+ static ContractDestroyedEvent: EventSig;
63
122
  static fromApiEvent(event: node.ContractEventByTxId, codeHash: string | undefined): Promise<ContractEventByTxId>;
64
123
  fromTestContractResult(methodIndex: number, result: node.TestContractResult): Promise<TestContractResult>;
65
124
  paramsForDeployment(params: BuildDeployContractTx): Promise<SignDeployContractTxParams>;
66
125
  transactionForDeployment(signer: SignerWithNodeProvider, params: Omit<BuildDeployContractTx, 'signerAddress'>): Promise<DeployContractTransaction>;
67
126
  buildByteCodeToDeploy(initialFields: Fields): string;
68
127
  }
69
- export declare class Script extends Common {
128
+ export declare class Script extends Artifact {
70
129
  readonly bytecodeTemplate: string;
71
- readonly fieldsSig: node.FieldsSig;
72
- constructor(sourceCodeSha256: string, bytecodeTemplate: string, fieldsSig: node.FieldsSig, functions: node.FunctionSig[]);
73
- static checkCodeType(fileName: string, contractStr: string): void;
74
- private static loadContractStr;
75
- static fromSource(provider: NodeProvider, path: string): Promise<Script>;
76
- private static compile;
77
- static fromJson(artifact: any): Script;
78
- static fromArtifactFile(path: string): Promise<Script>;
130
+ readonly bytecodeDebugPatch: string;
131
+ readonly fieldsSig: FieldsSig;
132
+ constructor(name: string, bytecodeTemplate: string, bytecodeDebugPatch: string, fieldsSig: FieldsSig, functions: FunctionSig[]);
133
+ static fromCompileResult(result: node.CompileScriptResult): Script;
134
+ static fromJson(artifact: any, bytecodeDebugPatch?: string): Script;
135
+ static fromArtifactFile(path: string, bytecodeDebugPatch: string): Promise<Script>;
79
136
  toString(): string;
80
137
  paramsForDeployment(params: BuildExecuteScriptTx): Promise<SignExecuteScriptTxParams>;
81
138
  transactionForDeployment(signer: SignerWithNodeProvider, params: Omit<BuildExecuteScriptTx, 'signerAddress'>): Promise<BuildScriptTxResult>;
82
139
  buildByteCodeToDeploy(initialFields: Fields): string;
83
140
  }
84
- export declare type Number256 = number | bigint | string;
85
- export declare type Val = Number256 | boolean | string | Val[];
86
- export declare type NamedVals = Record<string, Val>;
87
- export declare type Fields = NamedVals;
88
- export declare type Arguments = NamedVals;
89
- export declare function extractArray(tpe: string, v: Val): node.Val;
90
- export declare function toApiVal(v: Val, tpe: string): node.Val;
91
141
  export interface Asset {
92
142
  alphAmount: Number256;
93
143
  tokens?: Token[];
94
144
  }
95
- export interface Token {
96
- id: string;
97
- amount: Number256;
98
- }
99
145
  export interface InputAsset {
100
146
  address: string;
101
147
  asset: Asset;
@@ -107,7 +153,7 @@ export interface ContractState {
107
153
  initialStateHash?: string;
108
154
  codeHash: string;
109
155
  fields: Fields;
110
- fieldsSig: node.FieldsSig;
156
+ fieldsSig: FieldsSig;
111
157
  asset: Asset;
112
158
  }
113
159
  export interface TestContractParams {
@@ -132,14 +178,16 @@ export interface ContractEventByTxId {
132
178
  name: string;
133
179
  fields: Fields;
134
180
  }
181
+ export declare type DebugMessage = node.DebugMessage;
135
182
  export interface TestContractResult {
136
- address: string;
137
183
  contractId: string;
184
+ contractAddress: string;
138
185
  returns: Val[];
139
186
  gasUsed: number;
140
187
  contracts: ContractState[];
141
188
  txOutputs: Output[];
142
189
  events: ContractEventByTxId[];
190
+ debugMessages: DebugMessage[];
143
191
  }
144
192
  export declare type Output = AssetOutput | ContractOutput;
145
193
  export interface AssetOutput extends Asset {
@@ -152,7 +200,7 @@ export interface ContractOutput {
152
200
  type: string;
153
201
  address: string;
154
202
  alphAmount: Number256;
155
- tokens: Token[];
203
+ tokens?: Token[];
156
204
  }
157
205
  export interface DeployContractTransaction {
158
206
  fromGroup: number;