@alephium/web3 0.2.0-rc.3 → 0.2.0-rc.30

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 (125) 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 +117 -17
  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 +107 -68
  17. package/dist/src/contract/contract.js +395 -451
  18. package/dist/src/contract/events.d.ts +4 -4
  19. package/dist/src/contract/events.js +2 -1
  20. package/dist/src/contract/index.js +5 -1
  21. package/dist/src/contract/ralph.d.ts +5 -4
  22. package/dist/src/contract/ralph.js +27 -1
  23. package/dist/src/global.d.ts +4 -0
  24. package/dist/{scripts/stop-devnet.js → src/global.js} +17 -11
  25. package/dist/src/index.d.ts +2 -0
  26. package/dist/src/index.js +23 -1
  27. package/dist/src/signer/index.d.ts +0 -1
  28. package/dist/src/signer/index.js +5 -2
  29. package/dist/src/signer/signer.d.ts +25 -13
  30. package/dist/src/signer/signer.js +51 -16
  31. package/dist/src/transaction/index.d.ts +0 -1
  32. package/dist/src/transaction/index.js +5 -2
  33. package/dist/src/transaction/status.d.ts +2 -1
  34. package/dist/src/transaction/status.js +2 -1
  35. package/dist/src/utils/bs58.d.ts +1 -0
  36. package/dist/src/utils/bs58.js +13 -1
  37. package/dist/src/utils/index.d.ts +0 -1
  38. package/dist/src/utils/index.js +5 -2
  39. package/dist/src/utils/subscription.d.ts +0 -3
  40. package/dist/src/utils/subscription.js +0 -1
  41. package/dist/src/utils/utils.d.ts +4 -9
  42. package/dist/src/utils/utils.js +20 -24
  43. package/jest-config.json +11 -0
  44. package/package.json +11 -47
  45. package/src/api/api-alephium.ts +169 -25
  46. package/src/api/api-explorer.ts +234 -51
  47. package/src/api/index.ts +14 -3
  48. package/src/api/types.ts +233 -0
  49. package/{scripts/rename-gitignore.js → src/api/utils.ts} +7 -6
  50. package/src/contract/contract.ts +579 -545
  51. package/src/contract/events.ts +6 -5
  52. package/src/contract/ralph.ts +29 -4
  53. package/src/{transaction/sign-verify.ts → global.ts} +14 -15
  54. package/src/index.ts +7 -0
  55. package/src/signer/index.ts +0 -1
  56. package/src/signer/signer.ts +79 -27
  57. package/src/transaction/index.ts +0 -1
  58. package/src/transaction/status.ts +5 -2
  59. package/src/utils/bs58.ts +11 -0
  60. package/src/utils/index.ts +0 -1
  61. package/src/utils/subscription.ts +1 -3
  62. package/src/utils/utils.ts +11 -19
  63. package/.eslintrc.json +0 -21
  64. package/LICENSE +0 -165
  65. package/contracts/add/add.ral +0 -16
  66. package/contracts/greeter/greeter.ral +0 -7
  67. package/contracts/greeter/greeter_interface.ral +0 -3
  68. package/contracts/greeter_main.ral +0 -9
  69. package/contracts/main.ral +0 -6
  70. package/contracts/sub/sub.ral +0 -9
  71. package/contracts/test/metadata.ral +0 -17
  72. package/contracts/test/warnings.ral +0 -5
  73. package/dev/user.conf +0 -29
  74. package/dist/scripts/create-project.d.ts +0 -2
  75. package/dist/scripts/create-project.js +0 -125
  76. package/dist/scripts/rename-gitignore.d.ts +0 -1
  77. package/dist/scripts/start-devnet.d.ts +0 -1
  78. package/dist/scripts/start-devnet.js +0 -131
  79. package/dist/scripts/stop-devnet.d.ts +0 -1
  80. package/dist/src/signer/node-wallet.d.ts +0 -13
  81. package/dist/src/signer/node-wallet.js +0 -60
  82. package/dist/src/test/index.d.ts +0 -7
  83. package/dist/src/test/index.js +0 -41
  84. package/dist/src/test/privatekey-wallet.d.ts +0 -12
  85. package/dist/src/test/privatekey-wallet.js +0 -68
  86. package/dist/src/transaction/sign-verify.d.ts +0 -2
  87. package/dist/src/transaction/sign-verify.js +0 -58
  88. package/dist/src/utils/password-crypto.d.ts +0 -2
  89. package/dist/src/utils/password-crypto.js +0 -69
  90. package/gitignore +0 -10
  91. package/scripts/create-project.ts +0 -137
  92. package/scripts/start-devnet.js +0 -141
  93. package/scripts/stop-devnet.js +0 -32
  94. package/src/contract/ralph.test.ts +0 -178
  95. package/src/fixtures/address.json +0 -36
  96. package/src/fixtures/balance.json +0 -9
  97. package/src/fixtures/self-clique.json +0 -19
  98. package/src/fixtures/transaction.json +0 -13
  99. package/src/fixtures/transactions.json +0 -179
  100. package/src/signer/fixtures/genesis.json +0 -26
  101. package/src/signer/fixtures/wallets.json +0 -26
  102. package/src/signer/node-wallet.ts +0 -74
  103. package/src/test/index.ts +0 -32
  104. package/src/test/privatekey-wallet.ts +0 -58
  105. package/src/transaction/sign-verify.test.ts +0 -50
  106. package/src/utils/address.test.ts +0 -47
  107. package/src/utils/djb2.test.ts +0 -35
  108. package/src/utils/password-crypto.test.ts +0 -27
  109. package/src/utils/password-crypto.ts +0 -77
  110. package/src/utils/utils.test.ts +0 -161
  111. package/templates/base/README.md +0 -34
  112. package/templates/base/package.json +0 -35
  113. package/templates/base/src/greeter.ts +0 -41
  114. package/templates/base/tsconfig.json +0 -19
  115. package/templates/react/README.md +0 -34
  116. package/templates/react/config-overrides.js +0 -18
  117. package/templates/react/package.json +0 -66
  118. package/templates/react/src/App.tsx +0 -42
  119. package/templates/react/src/artifacts/greeter.ral.json +0 -26
  120. package/templates/react/src/artifacts/greeter_main.ral.json +0 -22
  121. package/templates/shared/.eslintrc.json +0 -12
  122. package/templates/shared/scripts/header.js +0 -0
  123. package/test/contract.test.ts +0 -197
  124. package/test/events.test.ts +0 -138
  125. 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,71 +1,121 @@
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
- declare type FieldsSig = node.FieldsSig;
12
- declare type EventSig = node.EventSig;
13
- declare type FunctionSig = node.FunctionSig;
14
- export declare abstract class Common {
15
- readonly sourceCodeSha256: string;
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;
16
87
  readonly functions: FunctionSig[];
17
- static readonly importRegex: RegExp;
18
- static readonly contractRegex: RegExp;
19
- static readonly interfaceRegex: RegExp;
20
- static readonly scriptRegex: RegExp;
21
- private static _artifactCache;
22
- static artifactCacheCapacity: number;
23
- protected static _getArtifactFromCache(codeHash: string): Contract | Script | undefined;
24
- protected static _putArtifactToCache(contract: Contract): void;
25
- constructor(sourceCodeSha256: string, functions: FunctionSig[]);
26
- protected static _artifactsFolder(): string;
27
- static getSourceFile(path: string, _dirs: string[]): SourceFile;
28
- protected static _handleImports(pathes: string[], contractStr: string, importsCache: string[]): Promise<string>;
29
- protected static _loadContractStr(sourceFile: SourceFile, importsCache: string[], validate: (code: string) => void): Promise<string>;
30
- static checkFileNameExtension(fileName: string): void;
31
- protected static _from<T extends {
32
- sourceCodeSha256: string;
33
- }>(provider: NodeProvider, sourceFile: SourceFile, loadContractStr: (sourceFile: SourceFile, importsCache: string[]) => Promise<string>, compile: (provider: NodeProvider, sourceFile: SourceFile, contractStr: string, contractHash: string, errorOnWarnings: boolean) => Promise<T>, errorOnWarnings: boolean): Promise<T>;
34
- protected _saveToFile(sourceFile: SourceFile): Promise<void>;
88
+ constructor(name: string, functions: FunctionSig[]);
35
89
  abstract buildByteCodeToDeploy(initialFields?: Fields): string;
36
90
  publicFunctions(): string[];
37
91
  usingPreapprovedAssetsFunctions(): string[];
38
92
  usingAssetsInContractFunctions(): string[];
39
- protected static checkCompilerWarnings(compiled: {
40
- warnings: string[];
41
- }, errorOnWarnings: boolean): void;
42
93
  }
43
- export declare class Contract extends Common {
94
+ export declare class Contract extends Artifact {
44
95
  readonly bytecode: string;
96
+ readonly bytecodeDebugPatch: string;
45
97
  readonly codeHash: string;
46
98
  readonly fieldsSig: FieldsSig;
47
99
  readonly eventsSig: EventSig[];
48
- constructor(sourceCodeSha256: string, bytecode: string, codeHash: string, fieldsSig: FieldsSig, eventsSig: EventSig[], functions: FunctionSig[]);
49
- static checkCodeType(fileName: string, contractStr: string): void;
50
- private static loadContractStr;
51
- static fromSource(provider: NodeProvider, path: string, errorOnWarnings?: boolean): Promise<Contract>;
52
- private static compile;
53
- static fromJson(artifact: any): Contract;
54
- static fromArtifactFile(path: string): Promise<Contract>;
55
- fetchState(provider: NodeProvider, address: string, group: number): Promise<ContractState>;
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>;
56
107
  toString(): string;
57
108
  toState(fields: Fields, asset: Asset, address?: string): ContractState;
58
109
  static randomAddress(): string;
110
+ private _printDebugMessages;
59
111
  private _test;
60
- testPublicMethod(provider: NodeProvider, funcName: string, params: TestContractParams): Promise<TestContractResult>;
61
- 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>;
62
114
  toApiFields(fields?: Fields): node.Val[];
63
115
  toApiArgs(funcName: string, args?: Arguments): node.Val[];
64
116
  getMethodIndex(funcName: string): number;
65
117
  toApiContractStates(states?: ContractState[]): node.ContractState[] | undefined;
66
118
  toTestContract(funcName: string, params: TestContractParams): node.TestContract;
67
- static fromCodeHash(codeHash: string): Promise<Contract>;
68
- static getFieldsSig(state: node.ContractState): Promise<FieldsSig>;
69
119
  fromApiContractState(state: node.ContractState): Promise<ContractState>;
70
120
  static ContractCreatedEvent: EventSig;
71
121
  static ContractDestroyedEvent: EventSig;
@@ -75,36 +125,23 @@ export declare class Contract extends Common {
75
125
  transactionForDeployment(signer: SignerWithNodeProvider, params: Omit<BuildDeployContractTx, 'signerAddress'>): Promise<DeployContractTransaction>;
76
126
  buildByteCodeToDeploy(initialFields: Fields): string;
77
127
  }
78
- export declare class Script extends Common {
128
+ export declare class Script extends Artifact {
79
129
  readonly bytecodeTemplate: string;
130
+ readonly bytecodeDebugPatch: string;
80
131
  readonly fieldsSig: FieldsSig;
81
- constructor(sourceCodeSha256: string, bytecodeTemplate: string, fieldsSig: FieldsSig, functions: FunctionSig[]);
82
- static checkCodeType(fileName: string, contractStr: string): void;
83
- private static loadContractStr;
84
- static fromSource(provider: NodeProvider, path: string, errorOnWarnings?: boolean): Promise<Script>;
85
- private static compile;
86
- static fromJson(artifact: any): Script;
87
- static fromArtifactFile(path: string): Promise<Script>;
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>;
88
136
  toString(): string;
89
137
  paramsForDeployment(params: BuildExecuteScriptTx): Promise<SignExecuteScriptTxParams>;
90
138
  transactionForDeployment(signer: SignerWithNodeProvider, params: Omit<BuildExecuteScriptTx, 'signerAddress'>): Promise<BuildScriptTxResult>;
91
139
  buildByteCodeToDeploy(initialFields: Fields): string;
92
140
  }
93
- export declare type Number256 = number | bigint | string;
94
- export declare type Val = Number256 | boolean | string | Val[];
95
- export declare type NamedVals = Record<string, Val>;
96
- export declare type Fields = NamedVals;
97
- export declare type Arguments = NamedVals;
98
- export declare function extractArray(tpe: string, v: Val): node.Val;
99
- export declare function toApiVal(v: Val, tpe: string): node.Val;
100
141
  export interface Asset {
101
142
  alphAmount: Number256;
102
143
  tokens?: Token[];
103
144
  }
104
- export interface Token {
105
- id: string;
106
- amount: Number256;
107
- }
108
145
  export interface InputAsset {
109
146
  address: string;
110
147
  asset: Asset;
@@ -141,14 +178,16 @@ export interface ContractEventByTxId {
141
178
  name: string;
142
179
  fields: Fields;
143
180
  }
181
+ export declare type DebugMessage = node.DebugMessage;
144
182
  export interface TestContractResult {
145
- address: string;
146
183
  contractId: string;
184
+ contractAddress: string;
147
185
  returns: Val[];
148
186
  gasUsed: number;
149
187
  contracts: ContractState[];
150
188
  txOutputs: Output[];
151
189
  events: ContractEventByTxId[];
190
+ debugMessages: DebugMessage[];
152
191
  }
153
192
  export declare type Output = AssetOutput | ContractOutput;
154
193
  export interface AssetOutput extends Asset {
@@ -161,7 +200,7 @@ export interface ContractOutput {
161
200
  type: string;
162
201
  address: string;
163
202
  alphAmount: Number256;
164
- tokens: Token[];
203
+ tokens?: Token[];
165
204
  }
166
205
  export interface DeployContractTransaction {
167
206
  fromGroup: number;