@alephium/web3 0.42.0 → 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/{utils → address}/address.js +15 -19
- package/dist/src/address/index.d.ts +1 -0
- package/dist/src/address/index.js +34 -0
- package/dist/src/api/node-provider.js +10 -9
- package/dist/src/api/types.js +1 -1
- package/dist/src/codec/array-codec.d.ts +2 -3
- package/dist/src/codec/array-codec.js +1 -2
- package/dist/src/codec/asset-output-codec.d.ts +3 -4
- package/dist/src/codec/asset-output-codec.js +10 -12
- package/dist/src/codec/bigint-codec.d.ts +2 -3
- package/dist/src/codec/bigint-codec.js +2 -3
- package/dist/src/codec/bytestring-codec.d.ts +5 -6
- package/dist/src/codec/bytestring-codec.js +5 -5
- package/dist/src/codec/codec.d.ts +2 -3
- package/dist/src/codec/compact-int-codec.d.ts +12 -13
- package/dist/src/codec/compact-int-codec.js +22 -22
- package/dist/src/codec/contract-codec.d.ts +5 -6
- package/dist/src/codec/contract-codec.js +24 -24
- package/dist/src/codec/contract-output-codec.d.ts +2 -3
- package/dist/src/codec/contract-output-codec.js +8 -10
- package/dist/src/codec/contract-output-ref-codec.d.ts +3 -4
- package/dist/src/codec/contract-output-ref-codec.js +2 -2
- package/dist/src/codec/either-codec.d.ts +2 -3
- package/dist/src/codec/either-codec.js +1 -2
- package/dist/src/codec/hash.d.ts +2 -3
- package/dist/src/codec/hash.js +17 -0
- package/dist/src/codec/input-codec.d.ts +3 -4
- package/dist/src/codec/input-codec.js +6 -6
- package/dist/src/codec/instr-codec.d.ts +2 -3
- package/dist/src/codec/instr-codec.js +1 -2
- package/dist/src/codec/lockup-script-codec.d.ts +5 -6
- package/dist/src/codec/lockup-script-codec.js +1 -2
- package/dist/src/codec/long-codec.d.ts +2 -3
- package/dist/src/codec/long-codec.js +1 -2
- package/dist/src/codec/method-codec.d.ts +2 -3
- package/dist/src/codec/method-codec.js +1 -2
- package/dist/src/codec/option-codec.d.ts +3 -4
- package/dist/src/codec/option-codec.js +2 -3
- package/dist/src/codec/script-codec.d.ts +4 -5
- package/dist/src/codec/script-codec.js +1 -3
- package/dist/src/codec/signature-codec.d.ts +3 -4
- package/dist/src/codec/signature-codec.js +17 -0
- package/dist/src/codec/signed-int-codec.d.ts +2 -3
- package/dist/src/codec/signed-int-codec.js +1 -2
- package/dist/src/codec/token-codec.d.ts +3 -4
- package/dist/src/codec/token-codec.js +3 -3
- package/dist/src/codec/transaction-codec.d.ts +4 -5
- package/dist/src/codec/transaction-codec.js +12 -13
- package/dist/src/codec/unlock-script-codec.d.ts +5 -6
- package/dist/src/codec/unlock-script-codec.js +14 -15
- package/dist/src/codec/unsigned-tx-codec.d.ts +4 -5
- package/dist/src/codec/unsigned-tx-codec.js +4 -5
- package/dist/src/contract/contract.js +20 -20
- package/dist/src/contract/ralph.d.ts +1 -1
- package/dist/src/contract/ralph.js +9 -10
- package/dist/src/{utils → exchange}/exchange.js +5 -5
- package/dist/src/exchange/index.d.ts +1 -0
- package/dist/src/exchange/index.js +25 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +2 -0
- package/dist/src/signer/signer.js +4 -5
- package/dist/src/signer/tx-builder.js +3 -3
- package/dist/src/utils/index.d.ts +0 -2
- package/dist/src/utils/index.js +0 -7
- package/dist/src/utils/sign.js +1 -1
- package/dist/src/utils/utils.d.ts +1 -0
- package/dist/src/utils/utils.js +30 -11
- package/dist/src/utils/webcrypto.js +3 -4
- package/package.json +1 -2
- package/src/{utils → address}/address.ts +15 -19
- package/src/address/index.ts +19 -0
- package/src/api/node-provider.ts +2 -9
- package/src/api/types.ts +2 -2
- package/src/codec/array-codec.ts +3 -4
- package/src/codec/asset-output-codec.ts +16 -18
- package/src/codec/bigint-codec.ts +4 -5
- package/src/codec/bytestring-codec.ts +8 -8
- package/src/codec/codec.ts +2 -3
- package/src/codec/compact-int-codec.ts +36 -37
- package/src/codec/contract-codec.ts +28 -27
- package/src/codec/contract-output-codec.ts +11 -13
- package/src/codec/contract-output-ref-codec.ts +5 -5
- package/src/codec/either-codec.ts +3 -4
- package/src/codec/hash.ts +2 -3
- package/src/codec/input-codec.ts +10 -10
- package/src/codec/instr-codec.ts +3 -4
- package/src/codec/lockup-script-codec.ts +8 -9
- package/src/codec/long-codec.ts +3 -4
- package/src/codec/method-codec.ts +3 -4
- package/src/codec/option-codec.ts +4 -5
- package/src/codec/script-codec.ts +5 -7
- package/src/codec/signature-codec.ts +3 -4
- package/src/codec/signed-int-codec.ts +3 -4
- package/src/codec/token-codec.ts +6 -6
- package/src/codec/transaction-codec.ts +17 -18
- package/src/codec/unlock-script-codec.ts +26 -27
- package/src/codec/unsigned-tx-codec.ts +10 -11
- package/src/contract/contract.ts +3 -7
- package/src/contract/ralph.ts +10 -11
- package/src/{utils → exchange}/exchange.ts +3 -11
- package/src/exchange/index.ts +19 -0
- package/src/index.ts +2 -0
- package/src/signer/signer.ts +2 -3
- package/src/signer/tx-builder.ts +2 -2
- package/src/utils/index.ts +0 -2
- package/src/utils/sign.ts +1 -1
- package/src/utils/utils.ts +29 -10
- package/src/utils/webcrypto.ts +3 -4
- package/webpack.config.js +1 -5
- /package/dist/src/{utils → address}/address.d.ts +0 -0
- /package/dist/src/{utils → exchange}/exchange.d.ts +0 -0
|
@@ -18,10 +18,10 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.tokensCodec = exports.tokenCodec = exports.TokenCodec = void 0;
|
|
21
|
-
const buffer_1 = require("buffer/");
|
|
22
21
|
const binary_parser_1 = require("binary-parser");
|
|
23
22
|
const compact_int_codec_1 = require("./compact-int-codec");
|
|
24
23
|
const array_codec_1 = require("./array-codec");
|
|
24
|
+
const utils_1 = require("../utils");
|
|
25
25
|
class TokenCodec {
|
|
26
26
|
constructor() {
|
|
27
27
|
this.parser = binary_parser_1.Parser.start()
|
|
@@ -34,8 +34,8 @@ class TokenCodec {
|
|
|
34
34
|
}
|
|
35
35
|
encode(input) {
|
|
36
36
|
const tokenId = input.tokenId;
|
|
37
|
-
const amount =
|
|
38
|
-
return
|
|
37
|
+
const amount = compact_int_codec_1.compactUnsignedIntCodec.encode(input.amount);
|
|
38
|
+
return (0, utils_1.concatBytes)([tokenId, amount]);
|
|
39
39
|
}
|
|
40
40
|
decode(input) {
|
|
41
41
|
return this.parser.parse(input);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Buffer } from 'buffer/';
|
|
2
1
|
import { Parser } from 'binary-parser';
|
|
3
2
|
import { DecodedArray } from './array-codec';
|
|
4
3
|
import { UnsignedTx } from './unsigned-tx-codec';
|
|
@@ -17,10 +16,10 @@ export interface Transaction {
|
|
|
17
16
|
}
|
|
18
17
|
export declare class TransactionCodec implements Codec<Transaction> {
|
|
19
18
|
parser: Parser;
|
|
20
|
-
encode(decodedTx: Transaction):
|
|
21
|
-
decode(input:
|
|
22
|
-
encodeApiTransaction(input: ApiTransaction):
|
|
23
|
-
decodeApiTransaction(input:
|
|
19
|
+
encode(decodedTx: Transaction): Uint8Array;
|
|
20
|
+
decode(input: Uint8Array): Transaction;
|
|
21
|
+
encodeApiTransaction(input: ApiTransaction): Uint8Array;
|
|
22
|
+
decodeApiTransaction(input: Uint8Array): ApiTransaction;
|
|
24
23
|
static toApiTransaction(transaction: Transaction): ApiTransaction;
|
|
25
24
|
static fromApiTransaction(tx: ApiTransaction): Transaction;
|
|
26
25
|
}
|
|
@@ -18,7 +18,6 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.transactionCodec = exports.TransactionCodec = void 0;
|
|
21
|
-
const buffer_1 = require("buffer/");
|
|
22
21
|
const binary_parser_1 = require("binary-parser");
|
|
23
22
|
const unsigned_tx_codec_1 = require("./unsigned-tx-codec");
|
|
24
23
|
const signature_codec_1 = require("./signature-codec");
|
|
@@ -48,13 +47,13 @@ class TransactionCodec {
|
|
|
48
47
|
});
|
|
49
48
|
}
|
|
50
49
|
encode(decodedTx) {
|
|
51
|
-
return
|
|
50
|
+
return (0, utils_1.concatBytes)([
|
|
52
51
|
unsigned_tx_codec_1.unsignedTxCodec.encode(decodedTx.unsigned),
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
new Uint8Array([decodedTx.scriptExecutionOk]),
|
|
53
|
+
contract_output_ref_codec_1.contractOutputRefsCodec.encode(decodedTx.contractInputs.value),
|
|
54
|
+
output_codec_1.outputsCodec.encode(decodedTx.generatedOutputs.value),
|
|
55
|
+
signature_codec_1.signaturesCodec.encode(decodedTx.inputSignatures.value),
|
|
56
|
+
signature_codec_1.signaturesCodec.encode(decodedTx.scriptSignatures.value)
|
|
58
57
|
]);
|
|
59
58
|
}
|
|
60
59
|
decode(input) {
|
|
@@ -74,7 +73,7 @@ class TransactionCodec {
|
|
|
74
73
|
const scriptExecutionOk = !!transaction.scriptExecutionOk;
|
|
75
74
|
const contractInputs = transaction.contractInputs.value.map((contractInput) => {
|
|
76
75
|
const hint = contractInput.hint;
|
|
77
|
-
const key = contractInput.key
|
|
76
|
+
const key = (0, utils_1.binToHex)(contractInput.key);
|
|
78
77
|
return { hint, key };
|
|
79
78
|
});
|
|
80
79
|
const txIdBytes = (0, utils_1.hexToBinUnsafe)(txId);
|
|
@@ -87,15 +86,15 @@ class TransactionCodec {
|
|
|
87
86
|
return contract_output_codec_1.ContractOutputCodec.convertToApiContractOutput(txIdBytes, output.value, index);
|
|
88
87
|
}
|
|
89
88
|
});
|
|
90
|
-
const inputSignatures = transaction.inputSignatures.value.map((signature) => signature.value
|
|
91
|
-
const scriptSignatures = transaction.scriptSignatures.value.map((signature) => signature.value
|
|
89
|
+
const inputSignatures = transaction.inputSignatures.value.map((signature) => (0, utils_1.binToHex)(signature.value));
|
|
90
|
+
const scriptSignatures = transaction.scriptSignatures.value.map((signature) => (0, utils_1.binToHex)(signature.value));
|
|
92
91
|
return { unsigned, scriptExecutionOk, contractInputs, generatedOutputs, inputSignatures, scriptSignatures };
|
|
93
92
|
}
|
|
94
93
|
static fromApiTransaction(tx) {
|
|
95
94
|
const unsigned = unsigned_tx_codec_1.UnsignedTxCodec.fromApiUnsignedTx(tx.unsigned);
|
|
96
95
|
const scriptExecutionOk = tx.scriptExecutionOk ? 1 : 0;
|
|
97
96
|
const contractInputs = tx.contractInputs.map((contractInput) => {
|
|
98
|
-
return { hint: contractInput.hint, key:
|
|
97
|
+
return { hint: contractInput.hint, key: (0, utils_1.hexToBinUnsafe)(contractInput.key) };
|
|
99
98
|
});
|
|
100
99
|
const generatedOutputs = tx.generatedOutputs.map((output) => {
|
|
101
100
|
if (output.type === 'AssetOutput') {
|
|
@@ -109,10 +108,10 @@ class TransactionCodec {
|
|
|
109
108
|
}
|
|
110
109
|
});
|
|
111
110
|
const inputSignatures = tx.inputSignatures.map((signature) => {
|
|
112
|
-
return { value:
|
|
111
|
+
return { value: (0, utils_1.hexToBinUnsafe)(signature) };
|
|
113
112
|
});
|
|
114
113
|
const scriptSignatures = tx.scriptSignatures.map((signature) => {
|
|
115
|
-
return { value:
|
|
114
|
+
return { value: (0, utils_1.hexToBinUnsafe)(signature) };
|
|
116
115
|
});
|
|
117
116
|
return {
|
|
118
117
|
unsigned,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Buffer } from 'buffer/';
|
|
2
1
|
import { Parser } from 'binary-parser';
|
|
3
2
|
import { DecodedArray } from './array-codec';
|
|
4
3
|
import { DecodedCompactInt } from './compact-int-codec';
|
|
@@ -7,7 +6,7 @@ import { DecodedScript } from './script-codec';
|
|
|
7
6
|
import { ByteString } from './bytestring-codec';
|
|
8
7
|
import { LockupScript } from './lockup-script-codec';
|
|
9
8
|
export interface P2PKH {
|
|
10
|
-
publicKey:
|
|
9
|
+
publicKey: Uint8Array;
|
|
11
10
|
}
|
|
12
11
|
export interface P2MPKH {
|
|
13
12
|
publicKeys: DecodedArray<{
|
|
@@ -25,8 +24,8 @@ export interface P2SH {
|
|
|
25
24
|
}
|
|
26
25
|
export declare class P2SHCodec implements Codec<P2SH> {
|
|
27
26
|
parser: Parser;
|
|
28
|
-
encode(input: P2SH):
|
|
29
|
-
decode(input:
|
|
27
|
+
encode(input: P2SH): Uint8Array;
|
|
28
|
+
decode(input: Uint8Array): P2SH;
|
|
30
29
|
}
|
|
31
30
|
export interface UnlockScript {
|
|
32
31
|
scriptType: number;
|
|
@@ -34,7 +33,7 @@ export interface UnlockScript {
|
|
|
34
33
|
}
|
|
35
34
|
export declare class UnlockScriptCodec implements Codec<UnlockScript> {
|
|
36
35
|
parser: Parser;
|
|
37
|
-
encode(input: UnlockScript):
|
|
38
|
-
decode(input:
|
|
36
|
+
encode(input: UnlockScript): Uint8Array;
|
|
37
|
+
decode(input: Uint8Array): UnlockScript;
|
|
39
38
|
}
|
|
40
39
|
export declare const unlockScriptCodec: UnlockScriptCodec;
|
|
@@ -18,13 +18,13 @@ GNU Lesser General Public License for more details.
|
|
|
18
18
|
You should have received a copy of the GNU Lesser General Public License
|
|
19
19
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
21
|
-
const buffer_1 = require("buffer/");
|
|
22
21
|
const binary_parser_1 = require("binary-parser");
|
|
23
22
|
const array_codec_1 = require("./array-codec");
|
|
24
23
|
const compact_int_codec_1 = require("./compact-int-codec");
|
|
25
24
|
const script_codec_1 = require("./script-codec");
|
|
26
25
|
const bytestring_codec_1 = require("./bytestring-codec");
|
|
27
26
|
const lockup_script_codec_1 = require("./lockup-script-codec");
|
|
27
|
+
const utils_1 = require("../utils");
|
|
28
28
|
class P2PKHCodec {
|
|
29
29
|
constructor() {
|
|
30
30
|
this.parser = binary_parser_1.Parser.start().buffer('publicKey', { length: 33 });
|
|
@@ -46,10 +46,10 @@ class P2MPKHCodec {
|
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
encode(input) {
|
|
49
|
-
return
|
|
50
|
-
|
|
49
|
+
return (0, utils_1.concatBytes)([
|
|
50
|
+
compact_int_codec_1.compactUnsignedIntCodec.encode(input.publicKeys.length),
|
|
51
51
|
...input.publicKeys.value.map((v) => {
|
|
52
|
-
return
|
|
52
|
+
return (0, utils_1.concatBytes)([v.publicKey.publicKey, compact_int_codec_1.compactUnsignedIntCodec.encode(v.index)]);
|
|
53
53
|
})
|
|
54
54
|
]);
|
|
55
55
|
}
|
|
@@ -77,23 +77,23 @@ class ValCodec {
|
|
|
77
77
|
const valType = input.type;
|
|
78
78
|
if (valType === 0x00) {
|
|
79
79
|
// Boolean
|
|
80
|
-
return
|
|
80
|
+
return new Uint8Array([valType, input.val]);
|
|
81
81
|
}
|
|
82
82
|
else if (valType === 0x01) {
|
|
83
83
|
// I256
|
|
84
|
-
return
|
|
84
|
+
return new Uint8Array([valType, ...compact_int_codec_1.compactUnsignedIntCodec.encode(input.val)]);
|
|
85
85
|
}
|
|
86
86
|
else if (valType === 0x02) {
|
|
87
87
|
// U256
|
|
88
|
-
return
|
|
88
|
+
return new Uint8Array([valType, ...compact_int_codec_1.compactUnsignedIntCodec.encode(input.val)]);
|
|
89
89
|
}
|
|
90
90
|
else if (valType === 0x03) {
|
|
91
91
|
// ByteVec
|
|
92
|
-
return
|
|
92
|
+
return new Uint8Array([valType, ...bytestring_codec_1.byteStringCodec.encode(input.val)]);
|
|
93
93
|
}
|
|
94
94
|
else if (valType === 0x04) {
|
|
95
95
|
// Address
|
|
96
|
-
return
|
|
96
|
+
return new Uint8Array([valType, ...lockup_script_codec_1.lockupScriptCodec.encode(input.val)]);
|
|
97
97
|
}
|
|
98
98
|
else {
|
|
99
99
|
throw new Error(`ValCodec: unsupported val type: ${valType}`);
|
|
@@ -116,7 +116,7 @@ class P2SHCodec {
|
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
118
|
encode(input) {
|
|
119
|
-
return
|
|
119
|
+
return (0, utils_1.concatBytes)([script_codec_1.scriptCodec.encode(input.script), valsCodec.encode(input.params.value)]);
|
|
120
120
|
}
|
|
121
121
|
decode(input) {
|
|
122
122
|
return this.parser.parse(input);
|
|
@@ -141,22 +141,21 @@ class UnlockScriptCodec {
|
|
|
141
141
|
encode(input) {
|
|
142
142
|
const scriptType = input.scriptType;
|
|
143
143
|
const inputUnLockScript = input.script;
|
|
144
|
-
const inputUnLockScriptType = buffer_1.Buffer.from([scriptType]);
|
|
145
144
|
if (scriptType === 0) {
|
|
146
145
|
// P2PKH
|
|
147
|
-
return
|
|
146
|
+
return new Uint8Array([scriptType, ...p2pkhCodec.encode(inputUnLockScript)]);
|
|
148
147
|
}
|
|
149
148
|
else if (scriptType === 1) {
|
|
150
149
|
// P2MPKH
|
|
151
|
-
return
|
|
150
|
+
return new Uint8Array([scriptType, ...p2mpkhCodec.encode(inputUnLockScript)]);
|
|
152
151
|
}
|
|
153
152
|
else if (scriptType === 2) {
|
|
154
153
|
// P2SH
|
|
155
|
-
return
|
|
154
|
+
return new Uint8Array([scriptType, ...p2shCodec.encode(inputUnLockScript)]);
|
|
156
155
|
}
|
|
157
156
|
else if (scriptType === 3) {
|
|
158
157
|
// SameAsPrevious
|
|
159
|
-
return
|
|
158
|
+
return new Uint8Array([scriptType]);
|
|
160
159
|
}
|
|
161
160
|
else {
|
|
162
161
|
throw new Error(`TODO: encode unlock script: ${scriptType}`);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Buffer } from 'buffer/';
|
|
2
1
|
import { Parser } from 'binary-parser';
|
|
3
2
|
import { UnsignedTx as ApiUnsignedTx } from '../api/api-alephium';
|
|
4
3
|
import { DecodedScript } from './script-codec';
|
|
@@ -19,10 +18,10 @@ export interface UnsignedTx {
|
|
|
19
18
|
}
|
|
20
19
|
export declare class UnsignedTxCodec implements Codec<UnsignedTx> {
|
|
21
20
|
parser: Parser;
|
|
22
|
-
encode(decodedUnsignedTx: UnsignedTx):
|
|
23
|
-
decode(input:
|
|
24
|
-
encodeApiUnsignedTx(input: ApiUnsignedTx):
|
|
25
|
-
decodeApiUnsignedTx(input:
|
|
21
|
+
encode(decodedUnsignedTx: UnsignedTx): Uint8Array;
|
|
22
|
+
decode(input: Uint8Array): UnsignedTx;
|
|
23
|
+
encodeApiUnsignedTx(input: ApiUnsignedTx): Uint8Array;
|
|
24
|
+
decodeApiUnsignedTx(input: Uint8Array): ApiUnsignedTx;
|
|
26
25
|
static txId(unsignedTx: UnsignedTx): string;
|
|
27
26
|
static toApiUnsignedTx(unsigned: UnsignedTx): ApiUnsignedTx;
|
|
28
27
|
static fromApiUnsignedTx(unsignedTx: ApiUnsignedTx): UnsignedTx;
|
|
@@ -18,7 +18,6 @@ GNU Lesser General Public License for more details.
|
|
|
18
18
|
You should have received a copy of the GNU Lesser General Public License
|
|
19
19
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
21
|
-
const buffer_1 = require("buffer/");
|
|
22
21
|
const binary_parser_1 = require("binary-parser");
|
|
23
22
|
const utils_1 = require("../utils");
|
|
24
23
|
const script_codec_1 = require("./script-codec");
|
|
@@ -48,8 +47,8 @@ class UnsignedTxCodec {
|
|
|
48
47
|
});
|
|
49
48
|
}
|
|
50
49
|
encode(decodedUnsignedTx) {
|
|
51
|
-
return
|
|
52
|
-
|
|
50
|
+
return (0, utils_1.concatBytes)([
|
|
51
|
+
new Uint8Array([decodedUnsignedTx.version, decodedUnsignedTx.networkId]),
|
|
53
52
|
script_codec_1.statefulScriptCodecOpt.encode(decodedUnsignedTx.statefulScript),
|
|
54
53
|
compact_int_codec_1.compactSignedIntCodec.encode(decodedUnsignedTx.gasAmount),
|
|
55
54
|
compact_int_codec_1.compactUnsignedIntCodec.encode(decodedUnsignedTx.gasPrice),
|
|
@@ -82,7 +81,7 @@ class UnsignedTxCodec {
|
|
|
82
81
|
const fixedOutputs = asset_output_codec_1.AssetOutputCodec.toFixedAssetOutputs(txIdBytes, unsigned.fixedOutputs.value);
|
|
83
82
|
let scriptOpt = undefined;
|
|
84
83
|
if (unsigned.statefulScript.option === 1) {
|
|
85
|
-
scriptOpt = script_codec_1.scriptCodec.encode(unsigned.statefulScript.value)
|
|
84
|
+
scriptOpt = (0, utils_1.binToHex)(script_codec_1.scriptCodec.encode(unsigned.statefulScript.value));
|
|
86
85
|
}
|
|
87
86
|
return { txId, version, networkId, gasAmount, scriptOpt, gasPrice, inputs, fixedOutputs };
|
|
88
87
|
}
|
|
@@ -95,7 +94,7 @@ class UnsignedTxCodec {
|
|
|
95
94
|
const inputs = input_codec_1.inputsCodec.fromArray(inputsValue);
|
|
96
95
|
const fixedOutputsValue = asset_output_codec_1.AssetOutputCodec.fromFixedAssetOutputs(unsignedTx.fixedOutputs);
|
|
97
96
|
const fixedOutputs = asset_output_codec_1.assetOutputsCodec.fromArray(fixedOutputsValue);
|
|
98
|
-
const statefulScript = script_codec_1.statefulScriptCodecOpt.
|
|
97
|
+
const statefulScript = script_codec_1.statefulScriptCodecOpt.fromBytes(unsignedTx.scriptOpt ? (0, utils_1.hexToBinUnsafe)(unsignedTx.scriptOpt) : undefined);
|
|
99
98
|
return { version, networkId, gasAmount, gasPrice, inputs, fixedOutputs, statefulScript };
|
|
100
99
|
}
|
|
101
100
|
}
|
|
@@ -41,11 +41,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
41
41
|
};
|
|
42
42
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
43
|
exports.getTokenIdFromUnsignedTx = exports.getContractIdFromUnsignedTx = exports.getContractEventsCurrentCount = exports.multicallMethods = exports.callMethod = exports.subscribeContractEvents = exports.subscribeContractEvent = exports.decodeEvent = exports.subscribeContractDestroyedEvent = exports.subscribeContractCreatedEvent = exports.fetchContractState = exports.ContractInstance = exports.getMapItem = exports.RalphMap = exports.testMethod = exports.addStdIdToFields = exports.subscribeEventsFromContract = exports.decodeContractDestroyedEvent = exports.decodeContractCreatedEvent = exports.DestroyContractEventAddresses = exports.CreateContractEventAddresses = exports.ExecutableScript = exports.ContractFactory = exports.randomTxId = exports.fromApiEventFields = exports.fromApiArray = exports.getDefaultValue = exports.fromApiFields = exports.Script = exports.Contract = exports.Artifact = exports.Struct = exports.DEFAULT_COMPILER_OPTIONS = exports.DEFAULT_NODE_COMPILER_OPTIONS = exports.StdIdFieldName = void 0;
|
|
44
|
-
const buffer_1 = require("buffer/");
|
|
45
44
|
const fs_1 = require("fs");
|
|
46
45
|
const api_1 = require("../api");
|
|
47
46
|
const ralph = __importStar(require("./ralph"));
|
|
48
47
|
const utils_1 = require("../utils");
|
|
48
|
+
const address_1 = require("../address");
|
|
49
49
|
const global_1 = require("../global");
|
|
50
50
|
const events_1 = require("./events");
|
|
51
51
|
const constants_1 = require("../constants");
|
|
@@ -128,7 +128,7 @@ class Contract extends Artifact {
|
|
|
128
128
|
this.stdInterfaceId = stdInterfaceId;
|
|
129
129
|
this.bytecodeDebug = ralph.buildDebugBytecode(this.bytecode, this.bytecodeDebugPatch);
|
|
130
130
|
this.codeHashDebug = codeHashDebug;
|
|
131
|
-
this.decodedMethods = codec_1.contract.contractCodec.decodeContract(
|
|
131
|
+
this.decodedMethods = codec_1.contract.contractCodec.decodeContract((0, utils_1.hexToBinUnsafe)(bytecode)).methods;
|
|
132
132
|
}
|
|
133
133
|
publicFunctions() {
|
|
134
134
|
return this.functions.filter((_, index) => this.decodedMethods[`${index}`].isPublic);
|
|
@@ -198,7 +198,7 @@ class Contract extends Artifact {
|
|
|
198
198
|
const addressDef = typeof address !== 'undefined' ? address : Contract.randomAddress();
|
|
199
199
|
return {
|
|
200
200
|
address: addressDef,
|
|
201
|
-
contractId: (0, utils_1.binToHex)((0,
|
|
201
|
+
contractId: (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(addressDef)),
|
|
202
202
|
bytecode: this.bytecode,
|
|
203
203
|
codeHash: this.codeHash,
|
|
204
204
|
fields: fields,
|
|
@@ -271,7 +271,7 @@ class Contract extends Artifact {
|
|
|
271
271
|
fromApiContractState(state) {
|
|
272
272
|
return {
|
|
273
273
|
address: state.address,
|
|
274
|
-
contractId: (0, utils_1.binToHex)((0,
|
|
274
|
+
contractId: (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(state.address)),
|
|
275
275
|
bytecode: state.bytecode,
|
|
276
276
|
initialStateHash: state.initialStateHash,
|
|
277
277
|
codeHash: state.codeHash,
|
|
@@ -319,7 +319,7 @@ class Contract extends Artifact {
|
|
|
319
319
|
addressToCodeHash.set(result.address, result.codeHash);
|
|
320
320
|
result.contracts.forEach((contract) => addressToCodeHash.set(contract.address, contract.codeHash));
|
|
321
321
|
return {
|
|
322
|
-
contractId: (0, utils_1.binToHex)((0,
|
|
322
|
+
contractId: (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(result.address)),
|
|
323
323
|
contractAddress: result.address,
|
|
324
324
|
returns: returns,
|
|
325
325
|
gasUsed: result.gasUsed,
|
|
@@ -647,7 +647,7 @@ function specialContractAddress(eventIndex, groupIndex) {
|
|
|
647
647
|
const bytes = new Uint8Array(32).fill(0);
|
|
648
648
|
bytes[30] = eventIndex;
|
|
649
649
|
bytes[31] = groupIndex;
|
|
650
|
-
return (0,
|
|
650
|
+
return (0, address_1.addressFromContractId)((0, utils_1.binToHex)(bytes));
|
|
651
651
|
}
|
|
652
652
|
exports.CreateContractEventAddresses = Array.from(Array(constants_1.TOTAL_NUMBER_OF_GROUPS).keys()).map((groupIndex) => specialContractAddress(Contract.ContractCreatedEventIndex, groupIndex));
|
|
653
653
|
exports.DestroyContractEventAddresses = Array.from(Array(constants_1.TOTAL_NUMBER_OF_GROUPS).keys()).map((groupIndex) => specialContractAddress(Contract.ContractDestroyedEventIndex, groupIndex));
|
|
@@ -718,7 +718,7 @@ function calcWrapperContractId(parentContractId, mapIndex, key, keyType, group)
|
|
|
718
718
|
const prefix = ralph.encodeMapPrefix(mapIndex);
|
|
719
719
|
const encodedKey = ralph.primitiveToByteVec(key, keyType);
|
|
720
720
|
const path = (0, utils_1.binToHex)(prefix) + (0, utils_1.binToHex)(encodedKey);
|
|
721
|
-
return (0,
|
|
721
|
+
return (0, address_1.subContractId)(parentContractId, path, group);
|
|
722
722
|
}
|
|
723
723
|
function genCodeForType(type, structs) {
|
|
724
724
|
const { immFields, mutFields } = ralph.calcFieldSize(type, true, structs);
|
|
@@ -766,7 +766,7 @@ function genCodeForType(type, structs) {
|
|
|
766
766
|
fieldLength: immFields + mutFields + 1,
|
|
767
767
|
methods: [loadImmFieldByIndex, loadMutFieldByIndex, storeMutFieldByIndex, destroy]
|
|
768
768
|
};
|
|
769
|
-
const bytecode = codec_1.contract.contractCodec.
|
|
769
|
+
const bytecode = codec_1.contract.contractCodec.encodeContract(c);
|
|
770
770
|
const codeHash = blake.blake2b(bytecode, undefined, 32);
|
|
771
771
|
return { bytecode: (0, utils_1.binToHex)(bytecode), codeHash: (0, utils_1.binToHex)(codeHash) };
|
|
772
772
|
}
|
|
@@ -785,7 +785,7 @@ function mapToExistingContracts(contract, parentContractId, group, map, mapIndex
|
|
|
785
785
|
const contractId = calcWrapperContractId(parentContractId, mapIndex, key, keyType, group);
|
|
786
786
|
return {
|
|
787
787
|
...generatedContract,
|
|
788
|
-
address: (0,
|
|
788
|
+
address: (0, address_1.addressFromContractId)(contractId),
|
|
789
789
|
contractId: contractId,
|
|
790
790
|
fieldsSig: getContractFieldsSig(valueType),
|
|
791
791
|
fields,
|
|
@@ -811,8 +811,8 @@ function mapsToExistingContracts(contract, parentContractId, group, initialMaps)
|
|
|
811
811
|
async function testMethod(factory, methodName, params, getContractByCodeHash) {
|
|
812
812
|
const txId = params?.txId ?? randomTxId();
|
|
813
813
|
const contract = factory.contract;
|
|
814
|
-
const address = params.address ?? (0,
|
|
815
|
-
const contractId = (0, utils_1.binToHex)((0,
|
|
814
|
+
const address = params.address ?? (0, address_1.addressFromContractId)((0, utils_1.binToHex)(crypto.getRandomValues(new Uint8Array(32))));
|
|
815
|
+
const contractId = (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(address));
|
|
816
816
|
const group = params.group ?? 0;
|
|
817
817
|
const initialMaps = params.initialMaps ?? {};
|
|
818
818
|
const contractStates = mapsToExistingContracts(contract, contractId, group, initialMaps);
|
|
@@ -839,7 +839,7 @@ class RalphMap {
|
|
|
839
839
|
this.parentContract = parentContract;
|
|
840
840
|
this.parentContractId = parentContractId;
|
|
841
841
|
this.mapName = mapName;
|
|
842
|
-
this.groupIndex = (0,
|
|
842
|
+
this.groupIndex = (0, address_1.groupOfAddress)((0, address_1.addressFromContractId)(parentContractId));
|
|
843
843
|
}
|
|
844
844
|
async get(key) {
|
|
845
845
|
return getMapItem(this.parentContract, this.parentContractId, this.groupIndex, this.mapName, key);
|
|
@@ -864,7 +864,7 @@ async function getMapItem(parentContract, parentContractId, groupIndex, mapName,
|
|
|
864
864
|
}
|
|
865
865
|
const [keyType, valueType] = ralph.parseMapType(mapType);
|
|
866
866
|
const mapItemContractId = calcWrapperContractId(parentContractId, index, key, keyType, groupIndex);
|
|
867
|
-
const mapItemAddress = (0,
|
|
867
|
+
const mapItemAddress = (0, address_1.addressFromContractId)(mapItemContractId);
|
|
868
868
|
try {
|
|
869
869
|
const state = await (0, global_1.getCurrentNodeProvider)().contracts.getContractsAddressState(mapItemAddress);
|
|
870
870
|
const fieldsSig = getContractFieldsSig(valueType);
|
|
@@ -892,7 +892,7 @@ function buildMapInfo(contract, fields) {
|
|
|
892
892
|
});
|
|
893
893
|
}
|
|
894
894
|
function extractFromEventLog(contract, result, allMaps, address, group) {
|
|
895
|
-
const parentContractId = (0, utils_1.binToHex)((0,
|
|
895
|
+
const parentContractId = (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(address));
|
|
896
896
|
const newInserted = [];
|
|
897
897
|
result.debugMessages.forEach((message) => {
|
|
898
898
|
if (message.contractAddress !== address)
|
|
@@ -902,12 +902,12 @@ function extractFromEventLog(contract, result, allMaps, address, group) {
|
|
|
902
902
|
return;
|
|
903
903
|
const map = allMaps[`${decoded.mapIndex}`];
|
|
904
904
|
const decodedKey = ralph.decodePrimitive(decoded.encodedKey, map.keyType);
|
|
905
|
-
const contractId = (0,
|
|
905
|
+
const contractId = (0, address_1.subContractId)(parentContractId, decoded.path, group);
|
|
906
906
|
if (!decoded.isInsert) {
|
|
907
907
|
map.value.delete(decodedKey);
|
|
908
908
|
return;
|
|
909
909
|
}
|
|
910
|
-
const state = result.contracts.find((s) => s.address === (0,
|
|
910
|
+
const state = result.contracts.find((s) => s.address === (0, address_1.addressFromContractId)(contractId));
|
|
911
911
|
if (state === undefined) {
|
|
912
912
|
throw new Error(`Cannot find contract state for map value, map field: ${map.name}, value type: ${map.valueType}`);
|
|
913
913
|
}
|
|
@@ -919,12 +919,12 @@ function extractFromEventLog(contract, result, allMaps, address, group) {
|
|
|
919
919
|
return newInserted;
|
|
920
920
|
}
|
|
921
921
|
function updateMaps(contract, result, allMaps, address, group) {
|
|
922
|
-
const parentContractId = (0, utils_1.binToHex)((0,
|
|
922
|
+
const parentContractId = (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(address));
|
|
923
923
|
const updated = [];
|
|
924
924
|
allMaps.forEach((map) => {
|
|
925
925
|
Array.from(map.value.keys()).forEach((key) => {
|
|
926
926
|
const contractId = calcWrapperContractId(parentContractId, map.index, key, map.keyType, group);
|
|
927
|
-
const updatedState = result.contracts.find((s) => s.address === (0,
|
|
927
|
+
const updatedState = result.contracts.find((s) => s.address === (0, address_1.addressFromContractId)(contractId));
|
|
928
928
|
if (updatedState === undefined)
|
|
929
929
|
return;
|
|
930
930
|
updated.push(updatedState.address);
|
|
@@ -950,8 +950,8 @@ function existingContractsToMaps(contract, address, group, result, maps) {
|
|
|
950
950
|
class ContractInstance {
|
|
951
951
|
constructor(address) {
|
|
952
952
|
this.address = address;
|
|
953
|
-
this.contractId = (0, utils_1.binToHex)((0,
|
|
954
|
-
this.groupIndex = (0,
|
|
953
|
+
this.contractId = (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(address));
|
|
954
|
+
this.groupIndex = (0, address_1.groupOfAddress)(address);
|
|
955
955
|
}
|
|
956
956
|
}
|
|
957
957
|
exports.ContractInstance = ContractInstance;
|
|
@@ -5,7 +5,7 @@ export declare function encodeBool(bool: boolean): Uint8Array;
|
|
|
5
5
|
export declare function decodeBool(bytes: Uint8Array): boolean;
|
|
6
6
|
export declare function encodeI256(i256: bigint): Uint8Array;
|
|
7
7
|
export declare function encodeU256(u256: bigint): Uint8Array;
|
|
8
|
-
export declare function encodeByteVec(
|
|
8
|
+
export declare function encodeByteVec(hex: string): Uint8Array;
|
|
9
9
|
export declare function encodeAddress(address: string): Uint8Array;
|
|
10
10
|
export declare enum VmValType {
|
|
11
11
|
Bool = 0,
|
|
@@ -19,7 +19,6 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
19
19
|
var _a;
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
21
|
exports.buildDebugBytecode = exports.encodeContractField = exports.buildContractByteCode = exports.encodeContractFields = exports.buildScriptByteCode = exports.flattenFields = exports.primitiveToByteVec = exports.decodePrimitive = exports.tryDecodeMapDebugLog = exports.calcFieldSize = exports.encodeMapPrefix = exports.parseMapType = exports.splitFields = exports.encodeScriptField = exports.encodeScriptFieldAsString = exports.encodePrimitiveValues = exports.addressVal = exports.byteVecVal = exports.u256Val = exports.i256Val = exports.boolVal = exports.encodeVmAddress = exports.encodeVmByteVec = exports.encodeVmU256 = exports.encodeVmI256 = exports.encodeVmBool = exports.VmValType = exports.encodeAddress = exports.encodeByteVec = exports.encodeU256 = exports.encodeI256 = exports.decodeBool = exports.encodeBool = void 0;
|
|
22
|
-
const buffer_1 = require("buffer/");
|
|
23
22
|
const api_1 = require("../api");
|
|
24
23
|
const utils_1 = require("../utils");
|
|
25
24
|
const codec_1 = require("../codec");
|
|
@@ -159,13 +158,13 @@ function encodeU256(u256) {
|
|
|
159
158
|
}
|
|
160
159
|
}
|
|
161
160
|
exports.encodeU256 = encodeU256;
|
|
162
|
-
function encodeByteVec(
|
|
163
|
-
if (!(0, utils_1.isHexString)(
|
|
164
|
-
throw Error(`Given value ${
|
|
161
|
+
function encodeByteVec(hex) {
|
|
162
|
+
if (!(0, utils_1.isHexString)(hex)) {
|
|
163
|
+
throw Error(`Given value ${hex} is not a valid hex string`);
|
|
165
164
|
}
|
|
166
|
-
const
|
|
167
|
-
const
|
|
168
|
-
return
|
|
165
|
+
const bytes0 = (0, utils_1.hexToBinUnsafe)(hex);
|
|
166
|
+
const bytes1 = encodeI256(BigInt(bytes0.length));
|
|
167
|
+
return (0, utils_1.concatBytes)([bytes1, bytes0]);
|
|
169
168
|
}
|
|
170
169
|
exports.encodeByteVec = encodeByteVec;
|
|
171
170
|
function encodeAddress(address) {
|
|
@@ -258,7 +257,7 @@ function encodeScriptFieldU256(value) {
|
|
|
258
257
|
return new Uint8Array([Instruction.u256Const, ...encodeU256(value)]);
|
|
259
258
|
}
|
|
260
259
|
function encodeScriptFieldAsString(tpe, value) {
|
|
261
|
-
return
|
|
260
|
+
return (0, utils_1.binToHex)(encodeScriptField(tpe, value));
|
|
262
261
|
}
|
|
263
262
|
exports.encodeScriptFieldAsString = encodeScriptFieldAsString;
|
|
264
263
|
function encodeScriptField(tpe, value) {
|
|
@@ -369,9 +368,9 @@ function decodePrimitive(value, type) {
|
|
|
369
368
|
case 'Bool':
|
|
370
369
|
return decodeBool(value);
|
|
371
370
|
case 'I256':
|
|
372
|
-
return codec_1.compactSignedIntCodec.decodeI256(
|
|
371
|
+
return codec_1.compactSignedIntCodec.decodeI256(value);
|
|
373
372
|
case 'U256':
|
|
374
|
-
return codec_1.compactUnsignedIntCodec.decodeU256(
|
|
373
|
+
return codec_1.compactUnsignedIntCodec.decodeU256(value);
|
|
375
374
|
case 'ByteVec':
|
|
376
375
|
return (0, utils_1.binToHex)(value);
|
|
377
376
|
case 'Address':
|
|
@@ -18,9 +18,9 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.getAddressFromUnlockScript = exports.getSenderAddress = exports.getALPHDepositInfo = exports.isALPHTransferTx = exports.validateExchangeAddress = void 0;
|
|
21
|
+
const address_1 = require("../address");
|
|
21
22
|
const utils_1 = require("../utils");
|
|
22
23
|
const unlock_script_codec_1 = require("../codec/unlock-script-codec");
|
|
23
|
-
const buffer_1 = require("buffer/");
|
|
24
24
|
const script_codec_1 = require("../codec/script-codec");
|
|
25
25
|
function validateExchangeAddress(address) {
|
|
26
26
|
let decoded;
|
|
@@ -33,7 +33,7 @@ function validateExchangeAddress(address) {
|
|
|
33
33
|
if (decoded.length === 0)
|
|
34
34
|
throw new Error('Address is empty');
|
|
35
35
|
const addressType = decoded[0];
|
|
36
|
-
if (addressType !==
|
|
36
|
+
if (addressType !== address_1.AddressType.P2PKH && addressType !== address_1.AddressType.P2SH) {
|
|
37
37
|
throw new Error('Invalid address type');
|
|
38
38
|
}
|
|
39
39
|
if (decoded.length !== 33) {
|
|
@@ -98,7 +98,7 @@ function getAddressFromUnlockScript(unlockScript) {
|
|
|
98
98
|
if (unlockScriptBody.length !== 33) {
|
|
99
99
|
throw new Error(`Invalid p2pkh unlock script: ${unlockScript}`);
|
|
100
100
|
}
|
|
101
|
-
return (0,
|
|
101
|
+
return (0, address_1.addressFromPublicKey)((0, utils_1.binToHex)(unlockScriptBody));
|
|
102
102
|
}
|
|
103
103
|
if (unlockScriptType === UnlockScriptType.P2MPKH) {
|
|
104
104
|
throw new Error('Naive multi-sig address is not supported for exchanges as it will be replaced by P2SH');
|
|
@@ -106,12 +106,12 @@ function getAddressFromUnlockScript(unlockScript) {
|
|
|
106
106
|
if (unlockScriptType === UnlockScriptType.P2SH) {
|
|
107
107
|
let p2sh;
|
|
108
108
|
try {
|
|
109
|
-
p2sh = unlock_script_codec_1.unlockScriptCodec.decode(
|
|
109
|
+
p2sh = unlock_script_codec_1.unlockScriptCodec.decode(decoded).script;
|
|
110
110
|
}
|
|
111
111
|
catch (_) {
|
|
112
112
|
throw new Error(`Invalid p2sh unlock script: ${unlockScript}`);
|
|
113
113
|
}
|
|
114
|
-
return (0,
|
|
114
|
+
return (0, address_1.addressFromScript)(script_codec_1.scriptCodec.encode(p2sh.script));
|
|
115
115
|
}
|
|
116
116
|
throw new Error('Invalid unlock script type');
|
|
117
117
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { validateExchangeAddress, isALPHTransferTx, getSenderAddress, getALPHDepositInfo } from './exchange';
|
|
@@ -0,0 +1,25 @@
|
|
|
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.getALPHDepositInfo = exports.getSenderAddress = exports.isALPHTransferTx = exports.validateExchangeAddress = void 0;
|
|
21
|
+
var exchange_1 = require("./exchange");
|
|
22
|
+
Object.defineProperty(exports, "validateExchangeAddress", { enumerable: true, get: function () { return exchange_1.validateExchangeAddress; } });
|
|
23
|
+
Object.defineProperty(exports, "isALPHTransferTx", { enumerable: true, get: function () { return exchange_1.isALPHTransferTx; } });
|
|
24
|
+
Object.defineProperty(exports, "getSenderAddress", { enumerable: true, get: function () { return exchange_1.getSenderAddress; } });
|
|
25
|
+
Object.defineProperty(exports, "getALPHDepositInfo", { enumerable: true, get: function () { return exchange_1.getALPHDepositInfo; } });
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.js
CHANGED
|
@@ -59,3 +59,5 @@ exports.codec = __importStar(require("./codec"));
|
|
|
59
59
|
exports.utils = __importStar(require("./utils"));
|
|
60
60
|
__exportStar(require("./debug"), exports);
|
|
61
61
|
__exportStar(require("./block"), exports);
|
|
62
|
+
__exportStar(require("./address"), exports);
|
|
63
|
+
__exportStar(require("./exchange"), exports);
|
|
@@ -44,13 +44,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
44
44
|
};
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
46
|
exports.fromApiDestination = exports.toApiDestinations = exports.toApiDestination = exports.verifySignedMessage = exports.hashMessage = exports.extendMessage = exports.SignerProviderWithCachedAccounts = exports.SignerProviderWithMultipleAccounts = exports.SignerProviderSimple = exports.InteractiveSignerProvider = exports.SignerProvider = void 0;
|
|
47
|
-
const buffer_1 = require("buffer/");
|
|
48
47
|
const crypto_1 = require("crypto");
|
|
49
48
|
const api_1 = require("../api");
|
|
50
49
|
const utils = __importStar(require("../utils"));
|
|
51
50
|
const blakejs_1 = __importDefault(require("blakejs"));
|
|
52
51
|
const tx_builder_1 = require("./tx-builder");
|
|
53
|
-
const
|
|
52
|
+
const address_1 = require("../address");
|
|
54
53
|
class SignerProvider {
|
|
55
54
|
async getSelectedAccount() {
|
|
56
55
|
const account = await this.unsafeGetSelectedAccount();
|
|
@@ -58,8 +57,8 @@ class SignerProvider {
|
|
|
58
57
|
return account;
|
|
59
58
|
}
|
|
60
59
|
static validateAccount(account) {
|
|
61
|
-
const derivedAddress = (0,
|
|
62
|
-
const derivedGroup = (0,
|
|
60
|
+
const derivedAddress = (0, address_1.addressFromPublicKey)(account.publicKey, account.keyType);
|
|
61
|
+
const derivedGroup = (0, address_1.groupOfAddress)(derivedAddress);
|
|
63
62
|
if (derivedAddress !== account.address || derivedGroup !== account.group) {
|
|
64
63
|
throw Error(`Invalid accounot data: ${JSON.stringify(account)}`);
|
|
65
64
|
}
|
|
@@ -206,7 +205,7 @@ function hashMessage(message, hasher) {
|
|
|
206
205
|
return utils.binToHex(blakejs_1.default.blake2b(extendMessage(message), undefined, 32));
|
|
207
206
|
case 'sha256':
|
|
208
207
|
const sha256 = (0, crypto_1.createHash)('sha256');
|
|
209
|
-
sha256.update(
|
|
208
|
+
sha256.update(new TextEncoder().encode(message));
|
|
210
209
|
return utils.binToHex(sha256.digest());
|
|
211
210
|
case 'blake2b':
|
|
212
211
|
return utils.binToHex(blakejs_1.default.blake2b(message, undefined, 32));
|