@alephium/web3 0.2.0-rc.8 → 0.2.0-test.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +2 -2
- package/.eslintrc.json +21 -0
- package/LICENSE +165 -0
- package/README.md +135 -2
- package/contracts/add/add.ral +13 -0
- package/contracts/greeter_main.ral +1 -1
- package/contracts/main.ral +4 -0
- package/contracts/sub/sub.ral +10 -0
- package/contracts/test/metadata.ral +18 -0
- package/contracts/test/warnings.ral +8 -0
- package/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.LICENSE.txt +17 -0
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/scripts/create-project.js +1 -1
- package/dist/src/api/api-alephium.d.ts +6 -19
- package/dist/src/api/api-explorer.d.ts +16 -16
- package/dist/src/api/index.js +1 -5
- package/dist/src/contract/contract.d.ts +16 -31
- package/dist/src/contract/contract.js +96 -123
- package/dist/src/contract/index.js +1 -5
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.js +1 -19
- package/dist/src/signer/index.d.ts +1 -0
- package/dist/src/signer/index.js +2 -5
- package/dist/src/signer/node-wallet.d.ts +11 -0
- package/dist/src/signer/node-wallet.js +57 -0
- package/dist/src/signer/signer.js +1 -5
- package/dist/src/test/index.d.ts +6 -0
- package/dist/src/test/index.js +41 -0
- package/dist/src/test/privatekey-wallet.d.ts +11 -0
- package/dist/src/test/privatekey-wallet.js +68 -0
- package/dist/src/transaction/index.d.ts +1 -0
- package/dist/src/transaction/index.js +2 -5
- package/dist/src/transaction/sign-verify.d.ts +2 -0
- package/dist/src/transaction/sign-verify.js +58 -0
- package/dist/src/utils/index.d.ts +1 -0
- package/dist/src/utils/index.js +2 -5
- package/dist/src/utils/password-crypto.d.ts +2 -0
- package/dist/src/utils/password-crypto.js +69 -0
- package/dist/src/utils/utils.d.ts +2 -3
- package/dist/src/utils/utils.js +15 -16
- package/gitignore +9 -0
- package/package.json +32 -6
- package/scripts/create-project.ts +1 -1
- package/src/api/api-alephium.ts +0 -14
- package/src/contract/contract.ts +102 -176
- package/src/contract/ralph.test.ts +178 -0
- package/src/fixtures/address.json +36 -0
- package/src/fixtures/balance.json +9 -0
- package/src/fixtures/self-clique.json +19 -0
- package/src/fixtures/transaction.json +13 -0
- package/src/fixtures/transactions.json +179 -0
- package/src/index.ts +0 -2
- package/src/signer/fixtures/genesis.json +26 -0
- package/src/signer/fixtures/wallets.json +26 -0
- package/src/signer/index.ts +1 -0
- package/src/signer/node-wallet.ts +65 -0
- package/src/test/index.ts +31 -0
- package/src/test/privatekey-wallet.ts +57 -0
- package/src/transaction/index.ts +1 -0
- package/src/transaction/sign-verify.test.ts +50 -0
- package/src/transaction/sign-verify.ts +39 -0
- package/src/utils/address.test.ts +47 -0
- package/src/utils/djb2.test.ts +35 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/password-crypto.test.ts +27 -0
- package/src/utils/password-crypto.ts +77 -0
- package/src/utils/utils.test.ts +161 -0
- package/src/utils/utils.ts +7 -7
- package/templates/base/package.json +1 -1
- package/templates/react/package.json +1 -1
- package/test/contract.test.ts +213 -0
- package/test/events.test.ts +141 -0
- package/test/transaction.test.ts +73 -0
- package/jest-config.json +0 -11
|
@@ -73,7 +73,7 @@ function prepareShared(packageRoot, projectRoot) {
|
|
|
73
73
|
console.log(` to ${projectRoot}`);
|
|
74
74
|
console.log('...');
|
|
75
75
|
fs_extra_1.default.copySync(path_1.default.join(packageRoot, 'templates/shared'), projectRoot);
|
|
76
|
-
copy('', ['.editorconfig', '.eslintignore', '.gitattributes']);
|
|
76
|
+
copy('', ['.editorconfig', '.eslintignore', '.gitattributes', 'LICENSE']);
|
|
77
77
|
copy('dev', ['user.conf']);
|
|
78
78
|
copy('scripts', ['start-devnet.js', 'stop-devnet.js']);
|
|
79
79
|
if (fs_extra_1.default.existsSync(path_1.default.join(packageRoot, 'gitignore'))) {
|
|
@@ -305,7 +305,6 @@ export interface ChangeActiveAddress {
|
|
|
305
305
|
address: string;
|
|
306
306
|
}
|
|
307
307
|
export interface CompileContractResult {
|
|
308
|
-
name: string;
|
|
309
308
|
bytecode: string;
|
|
310
309
|
/** @format 32-byte-hash */
|
|
311
310
|
codeHash: string;
|
|
@@ -319,20 +318,11 @@ export interface CompileProjectResult {
|
|
|
319
318
|
scripts: CompileScriptResult[];
|
|
320
319
|
}
|
|
321
320
|
export interface CompileScriptResult {
|
|
322
|
-
name: string;
|
|
323
321
|
bytecodeTemplate: string;
|
|
324
322
|
fields: FieldsSig;
|
|
325
323
|
functions: FunctionSig[];
|
|
326
324
|
warnings: string[];
|
|
327
325
|
}
|
|
328
|
-
export interface CompilerOptions {
|
|
329
|
-
ignoreUnusedConstantsWarnings?: boolean;
|
|
330
|
-
ignoreUnusedVariablesWarnings?: boolean;
|
|
331
|
-
ignoreUnusedFieldsWarnings?: boolean;
|
|
332
|
-
ignoreUnusedPrivateFunctionsWarnings?: boolean;
|
|
333
|
-
ignoreReadonlyCheckWarnings?: boolean;
|
|
334
|
-
ignoreExternalCallCheckWarnings?: boolean;
|
|
335
|
-
}
|
|
336
326
|
export interface Confirmed {
|
|
337
327
|
/** @format block-hash */
|
|
338
328
|
blockHash: string;
|
|
@@ -348,7 +338,6 @@ export interface Confirmed {
|
|
|
348
338
|
}
|
|
349
339
|
export interface Contract {
|
|
350
340
|
code: string;
|
|
351
|
-
compilerOptions?: CompilerOptions;
|
|
352
341
|
}
|
|
353
342
|
export interface ContractEvent {
|
|
354
343
|
/** @format block-hash */
|
|
@@ -543,7 +532,6 @@ export interface Penalty {
|
|
|
543
532
|
}
|
|
544
533
|
export interface Project {
|
|
545
534
|
code: string;
|
|
546
|
-
compilerOptions?: CompilerOptions;
|
|
547
535
|
}
|
|
548
536
|
export interface Reachable {
|
|
549
537
|
peers: string[];
|
|
@@ -565,7 +553,6 @@ export interface RevealMnemonicResult {
|
|
|
565
553
|
}
|
|
566
554
|
export interface Script {
|
|
567
555
|
code: string;
|
|
568
|
-
compilerOptions?: CompilerOptions;
|
|
569
556
|
}
|
|
570
557
|
export interface SelfClique {
|
|
571
558
|
/** @format clique-id */
|
|
@@ -1037,8 +1024,8 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1037
1024
|
* @request POST:/wallets/{wallet_name}/derive-next-address
|
|
1038
1025
|
*/
|
|
1039
1026
|
postWalletsWalletNameDeriveNextAddress: (walletName: string, query?: {
|
|
1040
|
-
group?: number;
|
|
1041
|
-
}, params?: RequestParams) => Promise<AddressInfo>;
|
|
1027
|
+
group?: number | undefined;
|
|
1028
|
+
} | undefined, params?: RequestParams) => Promise<AddressInfo>;
|
|
1042
1029
|
/**
|
|
1043
1030
|
* @description Your wallet need to have been created with the miner flag set to true
|
|
1044
1031
|
*
|
|
@@ -1170,8 +1157,8 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1170
1157
|
* @request GET:/infos/current-hashrate
|
|
1171
1158
|
*/
|
|
1172
1159
|
getInfosCurrentHashrate: (query?: {
|
|
1173
|
-
timespan?: number;
|
|
1174
|
-
}, params?: RequestParams) => Promise<string>;
|
|
1160
|
+
timespan?: number | undefined;
|
|
1161
|
+
} | undefined, params?: RequestParams) => Promise<string>;
|
|
1175
1162
|
};
|
|
1176
1163
|
blockflow: {
|
|
1177
1164
|
/**
|
|
@@ -1518,8 +1505,8 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1518
1505
|
* @request GET:/events/tx-id/{txId}
|
|
1519
1506
|
*/
|
|
1520
1507
|
getEventsTxIdTxid: (txId: string, query?: {
|
|
1521
|
-
group?: number;
|
|
1522
|
-
}, params?: RequestParams) => Promise<ContractEventsByTxId>;
|
|
1508
|
+
group?: number | undefined;
|
|
1509
|
+
} | undefined, params?: RequestParams) => Promise<ContractEventsByTxId>;
|
|
1523
1510
|
};
|
|
1524
1511
|
}
|
|
1525
1512
|
export {};
|
|
@@ -269,10 +269,10 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
269
269
|
* @request GET:/blocks
|
|
270
270
|
*/
|
|
271
271
|
getBlocks: (query?: {
|
|
272
|
-
page?: number;
|
|
273
|
-
limit?: number;
|
|
274
|
-
reverse?: boolean;
|
|
275
|
-
}, params?: RequestParams) => Promise<ListBlocks>;
|
|
272
|
+
page?: number | undefined;
|
|
273
|
+
limit?: number | undefined;
|
|
274
|
+
reverse?: boolean | undefined;
|
|
275
|
+
} | undefined, params?: RequestParams) => Promise<ListBlocks>;
|
|
276
276
|
/**
|
|
277
277
|
* @description Get a block with hash
|
|
278
278
|
*
|
|
@@ -289,10 +289,10 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
289
289
|
* @request GET:/blocks/{block-hash}/transactions
|
|
290
290
|
*/
|
|
291
291
|
getBlocksBlockHashTransactions: (blockHash: string, query?: {
|
|
292
|
-
page?: number;
|
|
293
|
-
limit?: number;
|
|
294
|
-
reverse?: boolean;
|
|
295
|
-
}, params?: RequestParams) => Promise<Transaction[]>;
|
|
292
|
+
page?: number | undefined;
|
|
293
|
+
limit?: number | undefined;
|
|
294
|
+
reverse?: boolean | undefined;
|
|
295
|
+
} | undefined, params?: RequestParams) => Promise<Transaction[]>;
|
|
296
296
|
};
|
|
297
297
|
transactions: {
|
|
298
298
|
/**
|
|
@@ -321,10 +321,10 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
321
321
|
* @request GET:/addresses/{address}/transactions
|
|
322
322
|
*/
|
|
323
323
|
getAddressesAddressTransactions: (address: string, query?: {
|
|
324
|
-
page?: number;
|
|
325
|
-
limit?: number;
|
|
326
|
-
reverse?: boolean;
|
|
327
|
-
}, params?: RequestParams) => Promise<Transaction[]>;
|
|
324
|
+
page?: number | undefined;
|
|
325
|
+
limit?: number | undefined;
|
|
326
|
+
reverse?: boolean | undefined;
|
|
327
|
+
} | undefined, params?: RequestParams) => Promise<Transaction[]>;
|
|
328
328
|
/**
|
|
329
329
|
* @description Get total transactions of a given address
|
|
330
330
|
*
|
|
@@ -367,10 +367,10 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
367
367
|
* @request GET:/infos/supply
|
|
368
368
|
*/
|
|
369
369
|
getInfosSupply: (query?: {
|
|
370
|
-
page?: number;
|
|
371
|
-
limit?: number;
|
|
372
|
-
reverse?: boolean;
|
|
373
|
-
}, params?: RequestParams) => Promise<TokenSupply[]>;
|
|
370
|
+
page?: number | undefined;
|
|
371
|
+
limit?: number | undefined;
|
|
372
|
+
reverse?: boolean | undefined;
|
|
373
|
+
} | undefined, params?: RequestParams) => Promise<TokenSupply[]>;
|
|
374
374
|
/**
|
|
375
375
|
* @description Get the ALPH total supply
|
|
376
376
|
*
|
package/dist/src/api/index.js
CHANGED
|
@@ -18,11 +18,7 @@ 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
|
-
|
|
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);
|
|
21
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
26
22
|
}) : (function(o, m, k, k2) {
|
|
27
23
|
if (k2 === undefined) k2 = k;
|
|
28
24
|
o[k2] = m[k];
|
|
@@ -10,25 +10,26 @@ declare enum SourceType {
|
|
|
10
10
|
AbstractContract = 2,
|
|
11
11
|
Interface = 3
|
|
12
12
|
}
|
|
13
|
-
export declare type CompilerOptions =
|
|
13
|
+
export declare type CompilerOptions = {
|
|
14
14
|
errorOnWarnings: boolean;
|
|
15
|
+
ignoreUnusedConstantsWarnings: boolean;
|
|
15
16
|
};
|
|
16
|
-
export declare const DEFAULT_NODE_COMPILER_OPTIONS: node.CompilerOptions;
|
|
17
17
|
export declare const DEFAULT_COMPILER_OPTIONS: CompilerOptions;
|
|
18
18
|
declare class TypedMatcher<T extends SourceType> {
|
|
19
19
|
matcher: RegExp;
|
|
20
20
|
type: T;
|
|
21
|
+
name: string | undefined;
|
|
21
22
|
constructor(pattern: string, type: T);
|
|
22
23
|
match(str: string): number;
|
|
23
24
|
}
|
|
24
25
|
declare class SourceFile {
|
|
25
26
|
type: SourceType;
|
|
27
|
+
typeId: string;
|
|
26
28
|
contractPath: string;
|
|
27
29
|
sourceCode: string;
|
|
28
30
|
sourceCodeHash: string;
|
|
29
31
|
getArtifactPath(artifactsRootPath: string): string;
|
|
30
|
-
constructor(type: SourceType,
|
|
31
|
-
static from(type: SourceType, sourceCode: string, contractPath: string): Promise<SourceFile>;
|
|
32
|
+
constructor(type: SourceType, typeId: string, sourceCode: string, contractPath: string);
|
|
32
33
|
}
|
|
33
34
|
declare class Compiled<T extends Artifact> {
|
|
34
35
|
sourceFile: SourceFile;
|
|
@@ -36,27 +37,10 @@ declare class Compiled<T extends Artifact> {
|
|
|
36
37
|
warnings: string[];
|
|
37
38
|
constructor(sourceFile: SourceFile, artifact: T, warnings: string[]);
|
|
38
39
|
}
|
|
39
|
-
declare class ProjectArtifact {
|
|
40
|
-
static readonly artifactFileName = ".project.json";
|
|
41
|
-
compilerOptionsUsed: node.CompilerOptions;
|
|
42
|
-
infos: Map<string, {
|
|
43
|
-
sourceCodeHash: string;
|
|
44
|
-
warnings: string[];
|
|
45
|
-
}>;
|
|
46
|
-
static checkCompilerOptionsParameter(compilerOptions: node.CompilerOptions): void;
|
|
47
|
-
constructor(compilerOptionsUsed: node.CompilerOptions, infos: Map<string, {
|
|
48
|
-
sourceCodeHash: string;
|
|
49
|
-
warnings: string[];
|
|
50
|
-
}>);
|
|
51
|
-
saveToFile(rootPath: string): Promise<void>;
|
|
52
|
-
needToReCompile(compilerOptions: node.CompilerOptions, files: SourceFile[]): boolean;
|
|
53
|
-
static from(rootPath: string): Promise<ProjectArtifact | undefined>;
|
|
54
|
-
}
|
|
55
40
|
export declare class Project {
|
|
56
41
|
sourceFiles: SourceFile[];
|
|
57
42
|
contracts: Compiled<Contract>[];
|
|
58
43
|
scripts: Compiled<Script>[];
|
|
59
|
-
projectArtifact: ProjectArtifact;
|
|
60
44
|
readonly contractsRootPath: string;
|
|
61
45
|
readonly artifactsRootPath: string;
|
|
62
46
|
readonly nodeProvider: NodeProvider;
|
|
@@ -66,23 +50,24 @@ export declare class Project {
|
|
|
66
50
|
static readonly interfaceMatcher: TypedMatcher<SourceType.Interface>;
|
|
67
51
|
static readonly scriptMatcher: TypedMatcher<SourceType.Script>;
|
|
68
52
|
static readonly matchers: TypedMatcher<SourceType>[];
|
|
69
|
-
static buildProjectArtifact(sourceFiles: SourceFile[], contracts: Compiled<Contract>[], scripts: Compiled<Script>[], compilerOptions: node.CompilerOptions): ProjectArtifact;
|
|
70
53
|
private constructor();
|
|
71
54
|
private getContractPath;
|
|
72
|
-
static checkCompilerWarnings
|
|
73
|
-
static contract(path: string): Contract;
|
|
74
|
-
static script(path: string): Script;
|
|
55
|
+
private static checkCompilerWarnings;
|
|
56
|
+
static contract(path: string, compilerOptions?: Partial<CompilerOptions>): Contract;
|
|
57
|
+
static script(path: string, compilerOptions?: Partial<CompilerOptions>): Script;
|
|
75
58
|
private saveArtifactsToFile;
|
|
76
59
|
contractByCodeHash(codeHash: string): Contract;
|
|
60
|
+
private saveProjectArtifactToFile;
|
|
77
61
|
private static compile;
|
|
78
62
|
private static loadArtifacts;
|
|
79
63
|
private static loadSourceFile;
|
|
80
64
|
private static loadSourceFiles;
|
|
81
|
-
static build(
|
|
65
|
+
static build(contractsRootPath?: string, artifactsRootPath?: string): Promise<void>;
|
|
82
66
|
}
|
|
83
67
|
export declare abstract class Artifact {
|
|
68
|
+
readonly typeId: string;
|
|
84
69
|
readonly functions: FunctionSig[];
|
|
85
|
-
constructor(functions: FunctionSig[]);
|
|
70
|
+
constructor(typeId: string, functions: FunctionSig[]);
|
|
86
71
|
abstract buildByteCodeToDeploy(initialFields?: Fields): string;
|
|
87
72
|
publicFunctions(): string[];
|
|
88
73
|
usingPreapprovedAssetsFunctions(): string[];
|
|
@@ -93,9 +78,9 @@ export declare class Contract extends Artifact {
|
|
|
93
78
|
readonly codeHash: string;
|
|
94
79
|
readonly fieldsSig: FieldsSig;
|
|
95
80
|
readonly eventsSig: EventSig[];
|
|
96
|
-
constructor(bytecode: string, codeHash: string, fieldsSig: FieldsSig, eventsSig: EventSig[], functions: FunctionSig[]);
|
|
81
|
+
constructor(typeId: string, bytecode: string, codeHash: string, fieldsSig: FieldsSig, eventsSig: EventSig[], functions: FunctionSig[]);
|
|
97
82
|
static fromJson(artifact: any): Contract;
|
|
98
|
-
static fromCompileResult(result: CompileContractResult): Contract;
|
|
83
|
+
static fromCompileResult(typeId: string, result: CompileContractResult): Contract;
|
|
99
84
|
static fromArtifactFile(path: string): Promise<Contract>;
|
|
100
85
|
fetchState(address: string, group: number): Promise<ContractState>;
|
|
101
86
|
toString(): string;
|
|
@@ -121,8 +106,8 @@ export declare class Contract extends Artifact {
|
|
|
121
106
|
export declare class Script extends Artifact {
|
|
122
107
|
readonly bytecodeTemplate: string;
|
|
123
108
|
readonly fieldsSig: FieldsSig;
|
|
124
|
-
constructor(bytecodeTemplate: string, fieldsSig: FieldsSig, functions: FunctionSig[]);
|
|
125
|
-
static fromCompileResult(result: CompileScriptResult): Script;
|
|
109
|
+
constructor(typeId: string, bytecodeTemplate: string, fieldsSig: FieldsSig, functions: FunctionSig[]);
|
|
110
|
+
static fromCompileResult(typeId: string, result: CompileScriptResult): Script;
|
|
126
111
|
static fromJson(artifact: any): Script;
|
|
127
112
|
static fromArtifactFile(path: string): Promise<Script>;
|
|
128
113
|
toString(): string;
|