@alephium/web3 0.5.0-rc.18 → 0.5.0-rc.19
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/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/api/types.d.ts +1 -1
- package/dist/src/contract/contract.js +6 -6
- package/dist/src/index.js +3 -0
- package/dist/src/signer/signer.js +1 -1
- package/dist/src/utils/number.d.ts +0 -2
- package/dist/src/utils/number.js +1 -29
- package/package.json +1 -1
- package/src/api/types.ts +1 -1
- package/src/contract/contract.ts +7 -9
- package/src/index.ts +4 -0
- package/src/signer/signer.ts +1 -1
- package/src/utils/number.ts +0 -34
package/dist/src/api/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as node from './api-alephium';
|
|
2
|
-
export declare type Number256 = bigint;
|
|
2
|
+
export declare type Number256 = bigint | string;
|
|
3
3
|
export declare type Val = Number256 | boolean | string | Val[];
|
|
4
4
|
export declare type NamedVals = Record<string, Val>;
|
|
5
5
|
export interface Token {
|
|
@@ -140,7 +140,7 @@ class ProjectArtifact {
|
|
|
140
140
|
compilerOptionsUsed: this.compilerOptionsUsed,
|
|
141
141
|
infos: Object.fromEntries(new Map([...this.infos].sort()))
|
|
142
142
|
};
|
|
143
|
-
const content =
|
|
143
|
+
const content = JSON.stringify(artifact, null, 2);
|
|
144
144
|
return fs_2.promises.writeFile(filepath, content);
|
|
145
145
|
}
|
|
146
146
|
needToReCompile(compilerOptions, sourceInfos) {
|
|
@@ -169,7 +169,7 @@ class ProjectArtifact {
|
|
|
169
169
|
return undefined;
|
|
170
170
|
}
|
|
171
171
|
const content = await fs_2.promises.readFile(filepath);
|
|
172
|
-
const json =
|
|
172
|
+
const json = JSON.parse(content.toString());
|
|
173
173
|
const compilerOptionsUsed = json.compilerOptionsUsed;
|
|
174
174
|
const files = new Map(Object.entries(json.infos));
|
|
175
175
|
return new ProjectArtifact(compilerOptionsUsed, files);
|
|
@@ -480,7 +480,7 @@ class Contract extends Artifact {
|
|
|
480
480
|
// support both 'code.ral' and 'code.ral.json'
|
|
481
481
|
static async fromArtifactFile(path, bytecodeDebugPatch, codeHashDebug) {
|
|
482
482
|
const content = await fs_2.promises.readFile(path);
|
|
483
|
-
const artifact =
|
|
483
|
+
const artifact = JSON.parse(content.toString());
|
|
484
484
|
return Contract.fromJson(artifact, bytecodeDebugPatch, codeHashDebug);
|
|
485
485
|
}
|
|
486
486
|
toString() {
|
|
@@ -493,7 +493,7 @@ class Contract extends Artifact {
|
|
|
493
493
|
eventsSig: this.eventsSig,
|
|
494
494
|
functions: this.functions
|
|
495
495
|
};
|
|
496
|
-
return
|
|
496
|
+
return JSON.stringify(object, null, 2);
|
|
497
497
|
}
|
|
498
498
|
toState(fields, asset, address) {
|
|
499
499
|
const addressDef = typeof address !== 'undefined' ? address : Contract.randomAddress();
|
|
@@ -718,7 +718,7 @@ class Script extends Artifact {
|
|
|
718
718
|
}
|
|
719
719
|
static async fromArtifactFile(path, bytecodeDebugPatch) {
|
|
720
720
|
const content = await fs_2.promises.readFile(path);
|
|
721
|
-
const artifact =
|
|
721
|
+
const artifact = JSON.parse(content.toString());
|
|
722
722
|
return this.fromJson(artifact, bytecodeDebugPatch);
|
|
723
723
|
}
|
|
724
724
|
toString() {
|
|
@@ -729,7 +729,7 @@ class Script extends Artifact {
|
|
|
729
729
|
fieldsSig: this.fieldsSig,
|
|
730
730
|
functions: this.functions
|
|
731
731
|
};
|
|
732
|
-
return
|
|
732
|
+
return JSON.stringify(object, null, 2);
|
|
733
733
|
}
|
|
734
734
|
async txParamsForExecution(signer, params) {
|
|
735
735
|
const selectedAccount = await signer.getSelectedAccount();
|
package/dist/src/index.js
CHANGED
|
@@ -44,6 +44,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
44
44
|
};
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
46
|
exports.utils = exports.web3 = void 0;
|
|
47
|
+
BigInt.prototype['toJSON'] = function () {
|
|
48
|
+
return this.toString();
|
|
49
|
+
};
|
|
47
50
|
__exportStar(require("./api"), exports);
|
|
48
51
|
__exportStar(require("./contract"), exports);
|
|
49
52
|
__exportStar(require("./signer"), exports);
|
|
@@ -61,7 +61,7 @@ class SignerProvider {
|
|
|
61
61
|
const derivedAddress = (0, utils_1.addressFromPublicKey)(account.publicKey, account.keyType);
|
|
62
62
|
const derivedGroup = (0, utils_1.groupOfAddress)(derivedAddress);
|
|
63
63
|
if (derivedAddress !== account.address || derivedGroup !== account.group) {
|
|
64
|
-
throw Error(`Invalid
|
|
64
|
+
throw Error(`Invalid accounot data: ${JSON.stringify(account)}`);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
}
|
|
@@ -14,5 +14,3 @@ export declare function prettifyExactAmount(amount: bigint, decimals: number): s
|
|
|
14
14
|
export declare function prettifyNumber(amount: bigint, decimals: number, config: IPrettifyNumberConfig): string | undefined;
|
|
15
15
|
export declare function convertAmountWithDecimals(amount: string | number, decimals: number): bigint | undefined;
|
|
16
16
|
export declare function convertAlphAmount(amount: string | number): bigint | undefined;
|
|
17
|
-
export declare function stringifyJsonWithBigint(obj: any, space?: string | number): string;
|
|
18
|
-
export declare function parseJsonWithBigint(text: string): any;
|
package/dist/src/utils/number.js
CHANGED
|
@@ -20,7 +20,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
20
20
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.
|
|
23
|
+
exports.convertAlphAmount = exports.convertAmountWithDecimals = exports.prettifyNumber = exports.prettifyExactAmount = exports.prettifyTokenAmount = exports.prettifyAttoAlphAmount = exports.prettifyNumberConfig = exports.isNumeric = void 0;
|
|
24
24
|
// Credits:
|
|
25
25
|
// 1. https://github.com/argentlabs/argent-x/blob/e63affa7f28b27333dca4081a3dcd375bb2da40b/packages/extension/src/shared/utils/number.ts
|
|
26
26
|
// 2. https://github.com/ethers-io/ethers.js/blob/724881f34d428406488a1c9f9dbebe54b6edecda/src.ts/utils/fixednumber.ts
|
|
@@ -142,31 +142,3 @@ function convertAlphAmount(amount) {
|
|
|
142
142
|
return convertAmountWithDecimals(amount, 18);
|
|
143
143
|
}
|
|
144
144
|
exports.convertAlphAmount = convertAlphAmount;
|
|
145
|
-
function replacer(key, value) {
|
|
146
|
-
if (typeof value === 'bigint') {
|
|
147
|
-
return { __bigintval__: value.toString() };
|
|
148
|
-
}
|
|
149
|
-
return value;
|
|
150
|
-
}
|
|
151
|
-
function reviver(key, value) {
|
|
152
|
-
if (value != null && typeof value === 'object' && '__bigintval__' in value) {
|
|
153
|
-
return BigInt(value['__bigintval__']);
|
|
154
|
-
}
|
|
155
|
-
return value;
|
|
156
|
-
}
|
|
157
|
-
function stringifyJsonWithBigint(obj, space) {
|
|
158
|
-
const bigintToString = BigInt.prototype['toJSON'];
|
|
159
|
-
BigInt.prototype['toJSON'] = undefined;
|
|
160
|
-
const result = JSON.stringify(obj, replacer, space);
|
|
161
|
-
BigInt.prototype['toJSON'] = bigintToString;
|
|
162
|
-
return result;
|
|
163
|
-
}
|
|
164
|
-
exports.stringifyJsonWithBigint = stringifyJsonWithBigint;
|
|
165
|
-
function parseJsonWithBigint(text) {
|
|
166
|
-
const bigintToString = BigInt.prototype['toJSON'];
|
|
167
|
-
BigInt.prototype['toJSON'] = undefined;
|
|
168
|
-
const result = JSON.parse(text, reviver);
|
|
169
|
-
BigInt.prototype['toJSON'] = bigintToString;
|
|
170
|
-
return result;
|
|
171
|
-
}
|
|
172
|
-
exports.parseJsonWithBigint = parseJsonWithBigint;
|
package/package.json
CHANGED
package/src/api/types.ts
CHANGED
|
@@ -19,7 +19,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
19
19
|
import { assertType, bs58, Eq } from '../utils'
|
|
20
20
|
import * as node from './api-alephium'
|
|
21
21
|
|
|
22
|
-
export type Number256 = bigint
|
|
22
|
+
export type Number256 = bigint | string
|
|
23
23
|
export type Val = Number256 | boolean | string | Val[]
|
|
24
24
|
export type NamedVals = Record<string, Val>
|
|
25
25
|
|
package/src/contract/contract.ts
CHANGED
|
@@ -54,9 +54,7 @@ import {
|
|
|
54
54
|
Eq,
|
|
55
55
|
Optional,
|
|
56
56
|
groupOfAddress,
|
|
57
|
-
addressFromContractId
|
|
58
|
-
stringifyJsonWithBigint,
|
|
59
|
-
parseJsonWithBigint
|
|
57
|
+
addressFromContractId
|
|
60
58
|
} from '../utils'
|
|
61
59
|
import { getCurrentNodeProvider } from '../global'
|
|
62
60
|
import * as path from 'path'
|
|
@@ -209,7 +207,7 @@ class ProjectArtifact {
|
|
|
209
207
|
compilerOptionsUsed: this.compilerOptionsUsed,
|
|
210
208
|
infos: Object.fromEntries(new Map([...this.infos].sort()))
|
|
211
209
|
}
|
|
212
|
-
const content =
|
|
210
|
+
const content = JSON.stringify(artifact, null, 2)
|
|
213
211
|
return fsPromises.writeFile(filepath, content)
|
|
214
212
|
}
|
|
215
213
|
|
|
@@ -243,7 +241,7 @@ class ProjectArtifact {
|
|
|
243
241
|
return undefined
|
|
244
242
|
}
|
|
245
243
|
const content = await fsPromises.readFile(filepath)
|
|
246
|
-
const json =
|
|
244
|
+
const json = JSON.parse(content.toString())
|
|
247
245
|
const compilerOptionsUsed = json.compilerOptionsUsed as node.CompilerOptions
|
|
248
246
|
const files = new Map(Object.entries<CodeInfo>(json.infos))
|
|
249
247
|
return new ProjectArtifact(compilerOptionsUsed, files)
|
|
@@ -739,7 +737,7 @@ export class Contract extends Artifact {
|
|
|
739
737
|
// support both 'code.ral' and 'code.ral.json'
|
|
740
738
|
static async fromArtifactFile(path: string, bytecodeDebugPatch: string, codeHashDebug: string): Promise<Contract> {
|
|
741
739
|
const content = await fsPromises.readFile(path)
|
|
742
|
-
const artifact =
|
|
740
|
+
const artifact = JSON.parse(content.toString())
|
|
743
741
|
return Contract.fromJson(artifact, bytecodeDebugPatch, codeHashDebug)
|
|
744
742
|
}
|
|
745
743
|
|
|
@@ -753,7 +751,7 @@ export class Contract extends Artifact {
|
|
|
753
751
|
eventsSig: this.eventsSig,
|
|
754
752
|
functions: this.functions
|
|
755
753
|
}
|
|
756
|
-
return
|
|
754
|
+
return JSON.stringify(object, null, 2)
|
|
757
755
|
}
|
|
758
756
|
|
|
759
757
|
toState<T extends Fields>(fields: T, asset: Asset, address?: string): ContractState<T> {
|
|
@@ -1049,7 +1047,7 @@ export class Script extends Artifact {
|
|
|
1049
1047
|
|
|
1050
1048
|
static async fromArtifactFile(path: string, bytecodeDebugPatch: string): Promise<Script> {
|
|
1051
1049
|
const content = await fsPromises.readFile(path)
|
|
1052
|
-
const artifact =
|
|
1050
|
+
const artifact = JSON.parse(content.toString())
|
|
1053
1051
|
return this.fromJson(artifact, bytecodeDebugPatch)
|
|
1054
1052
|
}
|
|
1055
1053
|
|
|
@@ -1061,7 +1059,7 @@ export class Script extends Artifact {
|
|
|
1061
1059
|
fieldsSig: this.fieldsSig,
|
|
1062
1060
|
functions: this.functions
|
|
1063
1061
|
}
|
|
1064
|
-
return
|
|
1062
|
+
return JSON.stringify(object, null, 2)
|
|
1065
1063
|
}
|
|
1066
1064
|
|
|
1067
1065
|
async txParamsForExecution<P extends Fields>(
|
package/src/index.ts
CHANGED
|
@@ -16,6 +16,10 @@ You should have received a copy of the GNU Lesser General Public License
|
|
|
16
16
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
+
BigInt.prototype['toJSON'] = function () {
|
|
20
|
+
return this.toString()
|
|
21
|
+
}
|
|
22
|
+
|
|
19
23
|
export * from './api'
|
|
20
24
|
export * from './contract'
|
|
21
25
|
export * from './signer'
|
package/src/signer/signer.ts
CHANGED
|
@@ -61,7 +61,7 @@ export abstract class SignerProvider {
|
|
|
61
61
|
const derivedAddress = addressFromPublicKey(account.publicKey, account.keyType)
|
|
62
62
|
const derivedGroup = groupOfAddress(derivedAddress)
|
|
63
63
|
if (derivedAddress !== account.address || derivedGroup !== account.group) {
|
|
64
|
-
throw Error(`Invalid
|
|
64
|
+
throw Error(`Invalid accounot data: ${JSON.stringify(account)}`)
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
package/src/utils/number.ts
CHANGED
|
@@ -155,37 +155,3 @@ export function convertAmountWithDecimals(amount: string | number, decimals: num
|
|
|
155
155
|
export function convertAlphAmount(amount: string | number): bigint | undefined {
|
|
156
156
|
return convertAmountWithDecimals(amount, 18)
|
|
157
157
|
}
|
|
158
|
-
|
|
159
|
-
function replacer(key: string, value: any): any {
|
|
160
|
-
if (typeof value === 'bigint') {
|
|
161
|
-
return { __bigintval__: value.toString() }
|
|
162
|
-
}
|
|
163
|
-
return value
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function reviver(key: string, value: any): any {
|
|
167
|
-
if (value != null && typeof value === 'object' && '__bigintval__' in value) {
|
|
168
|
-
return BigInt(value['__bigintval__'])
|
|
169
|
-
}
|
|
170
|
-
return value
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export function stringifyJsonWithBigint(obj: any, space?: string | number): string {
|
|
174
|
-
const bigintToString = BigInt.prototype['toJSON']
|
|
175
|
-
BigInt.prototype['toJSON'] = undefined
|
|
176
|
-
|
|
177
|
-
const result = JSON.stringify(obj, replacer, space)
|
|
178
|
-
|
|
179
|
-
BigInt.prototype['toJSON'] = bigintToString
|
|
180
|
-
return result
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export function parseJsonWithBigint(text: string): any {
|
|
184
|
-
const bigintToString = BigInt.prototype['toJSON']
|
|
185
|
-
BigInt.prototype['toJSON'] = undefined
|
|
186
|
-
|
|
187
|
-
const result = JSON.parse(text, reviver)
|
|
188
|
-
|
|
189
|
-
BigInt.prototype['toJSON'] = bigintToString
|
|
190
|
-
return result
|
|
191
|
-
}
|