@locuschain/lib 0.1.38 → 0.1.39

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 (51) hide show
  1. package/dist/accounts/index.amd.js +306 -0
  2. package/dist/accounts/index.cjs.cjs +2 -2
  3. package/dist/accounts/index.esm.js +2 -2
  4. package/dist/autogen/index.amd.js +151 -0
  5. package/dist/autogen/index.cjs.cjs +2 -2
  6. package/dist/autogen/index.esm.js +2 -2
  7. package/dist/chunks/account-BSrvZ7S8.js +77 -0
  8. package/dist/chunks/address-class-Dp7aNQb2.js +18 -0
  9. package/dist/chunks/base-B_kRRfsf.js +27 -0
  10. package/dist/chunks/debugWalletActions-BDz-h2tl.js +993 -0
  11. package/dist/chunks/{keystore-BFVSylSw.js → keystore-BMgBWq6G.js} +1 -1
  12. package/dist/chunks/{keystore-BbK5pVrh.cjs → keystore-CjcbAa1r.cjs} +1 -1
  13. package/dist/chunks/keystore-D7_ZZNzS.js +143 -0
  14. package/dist/chunks/{lclib-C2eG5HzD.js → lclib-BlnZKIGv.js} +43 -27
  15. package/dist/chunks/lclib-DBHaYcY8.js +3854 -0
  16. package/dist/chunks/{lclib-DuoOR0-Q.cjs → lclib-xRDGxtgw.cjs} +52 -36
  17. package/dist/chunks/rpc-C4n7t9y0.js +25 -0
  18. package/dist/chunks/transport-BBAz1kmP.js +30 -0
  19. package/dist/chunks/tslib.es6-D29rxPkW.js +37 -0
  20. package/dist/chunks/tx-type-CS4wIUJ8.js +68 -0
  21. package/dist/chunks/wasm-BCEa0JCQ.js +213 -0
  22. package/dist/chunks/{wasm-BtPcXTR4.js → wasm-C4WNl2YQ.js} +1 -1
  23. package/dist/chunks/{wasm-DTyHBxcY.cjs → wasm-D4S52Ifh.cjs} +1 -1
  24. package/dist/clients/index.amd.js +97 -0
  25. package/dist/clients/index.cjs.cjs +1 -1
  26. package/dist/clients/index.esm.js +1 -1
  27. package/dist/constant/index.amd.js +458 -0
  28. package/dist/contracts/index.amd.js +19640 -0
  29. package/dist/contracts/index.cjs.cjs +2 -2
  30. package/dist/contracts/index.esm.js +2 -2
  31. package/dist/errors/index.amd.js +17 -0
  32. package/dist/index.amd.js +43 -0
  33. package/dist/index.cjs.cjs +3 -3
  34. package/dist/index.esm.js +3 -3
  35. package/dist/transports/index.amd.js +98 -0
  36. package/dist/utils/index.amd.js +353 -0
  37. package/dist/utils/index.cjs.cjs +3 -3
  38. package/dist/utils/index.esm.js +4 -4
  39. package/dist/vite-plugin/index.amd.js +186 -0
  40. package/dist/vite-plugin/index.cjs.cjs +189 -0
  41. package/dist/vite-plugin/index.d.cts +46 -0
  42. package/dist/vite-plugin/index.d.mts +46 -0
  43. package/dist/vite-plugin/index.esm.js +183 -0
  44. package/dist/webpack-plugin/index.amd.js +101 -0
  45. package/dist/webpack-plugin/index.cjs.cjs +104 -0
  46. package/dist/webpack-plugin/index.d.cts +46 -0
  47. package/dist/webpack-plugin/index.d.mts +46 -0
  48. package/dist/webpack-plugin/index.esm.js +98 -0
  49. package/package.json +36 -6
  50. package/dist/index.umd.d.mts +0 -15
  51. package/dist/umd/index.umd.js +0 -26296
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var tslib_es6 = require('../chunks/tslib.es6-Cfi3-HmA.cjs');
4
- var wasm = require('../chunks/wasm-DTyHBxcY.cjs');
5
- require('../chunks/lclib-DuoOR0-Q.cjs');
4
+ var wasm = require('../chunks/wasm-D4S52Ifh.cjs');
5
+ require('../chunks/lclib-xRDGxtgw.cjs');
6
6
 
7
7
  var commonjsGlobal =
8
8
  typeof globalThis !== 'undefined'
@@ -1,6 +1,6 @@
1
1
  import { _ as __awaiter } from '../chunks/tslib.es6-WQS2tr1v.js';
2
- import { r as convertHexToData, n as convertDataToHex } from '../chunks/wasm-BtPcXTR4.js';
3
- import '../chunks/lclib-C2eG5HzD.js';
2
+ import { r as convertHexToData, n as convertDataToHex } from '../chunks/wasm-C4WNl2YQ.js';
3
+ import '../chunks/lclib-BlnZKIGv.js';
4
4
 
5
5
  var commonjsGlobal =
6
6
  typeof globalThis !== 'undefined'
@@ -0,0 +1,17 @@
1
+ define(['exports', '../chunks/base-B_kRRfsf', '../chunks/rpc-C4n7t9y0', '../chunks/transport-BBAz1kmP', '../chunks/account-BSrvZ7S8'], (function (exports, base, rpc, transport, account) { 'use strict';
2
+
3
+
4
+
5
+ exports.BaseError = base.BaseError;
6
+ exports.RpcRequestError = rpc.RpcRequestError;
7
+ exports.RpcResponseError = rpc.RpcResponseError;
8
+ exports.AbortedError = transport.AbortedError;
9
+ exports.HttpRequestError = transport.HttpRequestError;
10
+ exports.TimeoutError = transport.TimeoutError;
11
+ exports.AccountRequiredError = account.AccountRequiredError;
12
+ exports.DegenerateKeyError = account.DegenerateKeyError;
13
+ exports.InvalidTxResultError = account.InvalidTxResultError;
14
+ exports.SignFailedError = account.SignFailedError;
15
+ exports.SignKeyBindUnsupportedError = account.SignKeyBindUnsupportedError;
16
+
17
+ }));
@@ -0,0 +1,43 @@
1
+ define(['exports', './clients/index.amd', './transports/index.amd', './accounts/index.amd', './chunks/base-B_kRRfsf', './chunks/rpc-C4n7t9y0', './chunks/transport-BBAz1kmP', './chunks/account-BSrvZ7S8', './contracts/index.amd', './constant/index.amd', './chunks/keystore-D7_ZZNzS', './chunks/lclib-DBHaYcY8', './chunks/tslib.es6-D29rxPkW', './chunks/debugWalletActions-BDz-h2tl', './chunks/tx-type-CS4wIUJ8', './chunks/wasm-BCEa0JCQ', './chunks/address-class-Dp7aNQb2'], (function (exports, clients, transports, accounts, base, rpc, transport, account, contracts, constant, keystore, lclib, tslib_es6, debugWalletActions, txType, wasm, addressClass) { 'use strict';
2
+
3
+
4
+
5
+ exports.createClient = clients.createClient;
6
+ exports.createLocusPublicClient = clients.createLocusPublicClient;
7
+ exports.createLocusWalletClient = clients.createLocusWalletClient;
8
+ exports.createPublicClient = clients.createPublicClient;
9
+ exports.createWalletClient = clients.createWalletClient;
10
+ exports.http = transports.http;
11
+ exports.dualKeyAccount = accounts.dualKeyAccount;
12
+ exports.keysToAccount = accounts.keysToAccount;
13
+ exports.localKeySource = accounts.localKeySource;
14
+ exports.mnemonicToAccount = accounts.mnemonicToAccount;
15
+ exports.toAccount = accounts.toAccount;
16
+ exports.toKeySource = accounts.toKeySource;
17
+ exports.BaseError = base.BaseError;
18
+ exports.RpcRequestError = rpc.RpcRequestError;
19
+ exports.RpcResponseError = rpc.RpcResponseError;
20
+ exports.AbortedError = transport.AbortedError;
21
+ exports.HttpRequestError = transport.HttpRequestError;
22
+ exports.TimeoutError = transport.TimeoutError;
23
+ exports.AccountRequiredError = account.AccountRequiredError;
24
+ exports.DegenerateKeyError = account.DegenerateKeyError;
25
+ exports.InvalidTxResultError = account.InvalidTxResultError;
26
+ exports.SignFailedError = account.SignFailedError;
27
+ exports.SignKeyBindUnsupportedError = account.SignKeyBindUnsupportedError;
28
+ exports.erc20Abi = contracts.erc20Abi;
29
+ exports.getContract = contracts.getContract;
30
+ exports.AddressClass = constant.AddressClass;
31
+ exports.Currency = constant.Currency;
32
+ exports.FeeType = constant.FeeType;
33
+ exports.GRANT_COST_PER_TX = constant.GRANT_COST_PER_TX;
34
+ exports.MaxVMRewardsCount = constant.MaxVMRewardsCount;
35
+ exports.TxType = constant.TxType;
36
+ exports.TxTypes = constant.TxTypes;
37
+ exports.createKeystoreBundle = keystore.createKeystoreBundle;
38
+ exports.splitKeystoreBundle = keystore.splitKeystoreBundle;
39
+ exports.unlockKeystoreBundle = keystore.unlockKeystoreBundle;
40
+ exports.unlockMasterKeystore = keystore.unlockMasterKeystore;
41
+ exports.unlockNormalKeystore = keystore.unlockNormalKeystore;
42
+
43
+ }));
@@ -9,12 +9,12 @@ var transport = require('./chunks/transport-VThNtzck.cjs');
9
9
  var account = require('./chunks/account-BAsiKnSL.cjs');
10
10
  var contracts = require('./contracts/index.cjs.cjs');
11
11
  var constant = require('./constant/index.cjs.cjs');
12
- var keystore = require('./chunks/keystore-BbK5pVrh.cjs');
13
- require('./chunks/lclib-DuoOR0-Q.cjs');
12
+ var keystore = require('./chunks/keystore-CjcbAa1r.cjs');
13
+ require('./chunks/lclib-xRDGxtgw.cjs');
14
14
  require('./chunks/tslib.es6-Cfi3-HmA.cjs');
15
15
  require('./chunks/debugWalletActions-6qjkZVq9.cjs');
16
16
  require('./chunks/tx-type-DI_nKG8B.cjs');
17
- require('./chunks/wasm-DTyHBxcY.cjs');
17
+ require('./chunks/wasm-D4S52Ifh.cjs');
18
18
  require('./chunks/address-class-Cjy48Uqk.cjs');
19
19
 
20
20
 
package/dist/index.esm.js CHANGED
@@ -7,10 +7,10 @@ export { A as AbortedError, H as HttpRequestError, T as TimeoutError } from './c
7
7
  export { A as AccountRequiredError, D as DegenerateKeyError, I as InvalidTxResultError, S as SignFailedError, a as SignKeyBindUnsupportedError } from './chunks/account-FZT9LH_s.js';
8
8
  export { erc20Abi, getContract } from './contracts/index.esm.js';
9
9
  export { AddressClass, Currency, FeeType, GRANT_COST_PER_TX, MaxVMRewardsCount, TxType, TxTypes } from './constant/index.esm.js';
10
- export { c as createKeystoreBundle, s as splitKeystoreBundle, u as unlockKeystoreBundle, a as unlockMasterKeystore, b as unlockNormalKeystore } from './chunks/keystore-BFVSylSw.js';
11
- import './chunks/lclib-C2eG5HzD.js';
10
+ export { c as createKeystoreBundle, s as splitKeystoreBundle, u as unlockKeystoreBundle, a as unlockMasterKeystore, b as unlockNormalKeystore } from './chunks/keystore-BMgBWq6G.js';
11
+ import './chunks/lclib-BlnZKIGv.js';
12
12
  import './chunks/tslib.es6-WQS2tr1v.js';
13
13
  import './chunks/debugWalletActions-D5-Ds7Hl.js';
14
14
  import './chunks/tx-type-BPkhMGad.js';
15
- import './chunks/wasm-BtPcXTR4.js';
15
+ import './chunks/wasm-C4WNl2YQ.js';
16
16
  import './chunks/address-class-CHAZYhdZ.js';
@@ -0,0 +1,98 @@
1
+ define(['exports', '../chunks/tslib.es6-D29rxPkW', '../chunks/rpc-C4n7t9y0', '../chunks/transport-BBAz1kmP', '../chunks/base-B_kRRfsf'], (function (exports, tslib_es6, rpc, transport, base) { 'use strict';
2
+
3
+ const DEFAULT_TIMEOUT_MS = 30000;
4
+ /**
5
+ * HTTP JSON-RPC 트랜스포트를 만든다.
6
+ *
7
+ * 반환된 함수는 createClient() 가 호출하면서 id 제너레이터를 전달하고,
8
+ * 그렇게 만들어진 TransportInstance 는 각 JSON-RPC envelope 의 `id` 필드를
9
+ * 증가시키며 채워 넣는다.
10
+ */
11
+ function http(url, config = {}) {
12
+ var _a;
13
+ const timeout = (_a = config.timeout) !== null && _a !== void 0 ? _a : DEFAULT_TIMEOUT_MS;
14
+ return ({ id } = {}) => {
15
+ let counter = 0;
16
+ const nextId = id !== null && id !== void 0 ? id : (() => {
17
+ if (counter === Number.MAX_SAFE_INTEGER)
18
+ counter = 0;
19
+ return ++counter;
20
+ });
21
+ const instance = {
22
+ type: 'http',
23
+ url,
24
+ request: (args_1, ...args_2) => tslib_es6.__awaiter(this, [args_1, ...args_2], void 0, function* (args, opts = {}) {
25
+ var _a, _b, _c;
26
+ const signal = mergeSignals(config.signal, opts.signal, timeout);
27
+ if (signal.aborted) {
28
+ throw new transport.AbortedError('request aborted before send', { url });
29
+ }
30
+ const body = JSON.stringify({
31
+ id: nextId(),
32
+ jsonrpc: '2.0',
33
+ method: args.method,
34
+ params: args.params,
35
+ });
36
+ let res;
37
+ try {
38
+ res = yield fetch(url, Object.assign(Object.assign({}, ((_a = config.fetchOptions) !== null && _a !== void 0 ? _a : {})), { method: 'POST', headers: Object.assign(Object.assign({ Accept: 'application/json, text/plain', 'Content-Type': 'application/json;charset=UTF-8' }, ((_b = config.headers) !== null && _b !== void 0 ? _b : {})), ((_c = opts.headers) !== null && _c !== void 0 ? _c : {})), body,
39
+ signal }));
40
+ }
41
+ catch (err) {
42
+ throw mapFetchError(err, url);
43
+ }
44
+ if (!res.ok) {
45
+ throw new transport.HttpRequestError(`http ${res.status}`, {
46
+ url,
47
+ status: res.status,
48
+ });
49
+ }
50
+ let envelope;
51
+ try {
52
+ envelope = yield res.json();
53
+ }
54
+ catch (err) {
55
+ throw new transport.HttpRequestError('failed to parse JSON-RPC response body', {
56
+ url,
57
+ cause: err,
58
+ });
59
+ }
60
+ if (envelope.error) {
61
+ const { code, message } = envelope.error;
62
+ if (message === 'timeout error') {
63
+ throw new transport.TimeoutError(message, { url });
64
+ }
65
+ throw new rpc.RpcResponseError(message, {
66
+ code,
67
+ method: args.method,
68
+ });
69
+ }
70
+ return envelope.result;
71
+ }),
72
+ };
73
+ return instance;
74
+ };
75
+ }
76
+ function mergeSignals(clientSignal, userSignal, timeoutMs) {
77
+ const timeoutSignal = AbortSignal.timeout(timeoutMs);
78
+ const extra = [clientSignal, userSignal].filter((s) => !!s);
79
+ if (extra.length === 0)
80
+ return timeoutSignal;
81
+ return AbortSignal.any([...extra, timeoutSignal]);
82
+ }
83
+ function mapFetchError(err, url) {
84
+ var _a;
85
+ if (err && typeof err === 'object') {
86
+ const name = err.name;
87
+ const message = (_a = err.message) !== null && _a !== void 0 ? _a : String(err);
88
+ if (name === 'TimeoutError')
89
+ return new transport.TimeoutError(message, { url, cause: err });
90
+ if (name === 'AbortError')
91
+ return new transport.AbortedError(message, { url, cause: err });
92
+ }
93
+ return new transport.HttpRequestError(err instanceof Error ? err.message : String(err), { url, cause: err });
94
+ }
95
+
96
+ exports.http = http;
97
+
98
+ }));
@@ -0,0 +1,353 @@
1
+ define(['exports', '../chunks/address-class-Dp7aNQb2', '../chunks/wasm-BCEa0JCQ', '../chunks/keystore-D7_ZZNzS', '../chunks/lclib-DBHaYcY8', '../chunks/base-B_kRRfsf', '../chunks/account-BSrvZ7S8', '../chunks/tslib.es6-D29rxPkW'], (function (exports, addressClass, wasm, keystore, lclib, base, account, tslib_es6) { 'use strict';
2
+
3
+ class TxValidator {
4
+ constructor() {
5
+ this.verifyTxParams = (rpcResult, params, options) => {
6
+ try {
7
+ if (options.targetTxHash) {
8
+ const genHash = JSON.parse(wasm.verifyTx(JSON.stringify(rpcResult.tx))).hash;
9
+ if (options.targetTxHash !== genHash) {
10
+ console.warn(`[TxnIntegrityChecker] Tx hash not matched.`, options.targetTxHash, '!==', genHash);
11
+ return { result: false, reason: 'tx verify fail' };
12
+ }
13
+ }
14
+ const checks = [];
15
+ const tx = rpcResult.tx;
16
+ switch (tx.type) {
17
+ case 'TX_TRANSFER_COIN':
18
+ case 'TX_TRANSFER_COIN_FEE':
19
+ checks.push(() => this.checkFields(params, tx, { to: 'target', amount: 'amount' }));
20
+ break;
21
+ case 'TX_TRANSFER_COIN_EXPRESS':
22
+ checks.push(() => this.checkFields(params, tx, {
23
+ to: 'target',
24
+ amount: 'amount',
25
+ 'source.owner': 'source.addr',
26
+ 'source.height': 'source.index'
27
+ }));
28
+ break;
29
+ case 'TX_CREATE_TOKEN':
30
+ case 'TX_CREATE_TOKEN_FEE':
31
+ checks.push(() => this.checkFields(params, tx, { tokenBalance: 'tokenBalance.v' }));
32
+ break;
33
+ case 'TX_TRANSFER_TOKEN':
34
+ case 'TX_TRANSFER_TOKEN_FEE':
35
+ checks.push(() => this.checkFields(params, tx, { to: 'target', amount: 'amount' }), () => this.checkComplexField(params, tx, {
36
+ paramPath: 'tokenAmounts',
37
+ txPath: 'tokens',
38
+ paramTransform: tokens => (tokens !== null && tokens !== void 0 ? tokens : []).map((d) => ({ t: d.tokenId, a: d.amountToken })),
39
+ txTransform: tokens => (tokens !== null && tokens !== void 0 ? tokens : []).map((d) => ({ t: d.t, a: d.a }))
40
+ }));
41
+ break;
42
+ case 'TX_CREATE_ASSETOBJECT':
43
+ case 'TX_CREATE_ASSETOBJECT_FEE':
44
+ checks.push(() => this.checkFields(params, tx, Object.assign({
45
+ assetType: 'object.type',
46
+ metaData: 'object.metaData'
47
+ }, (params.amount === '0' ? {} : { amount: 'object.amount' })))
48
+ // TODO: params.operator !== tx.Object.Operator ("" !== "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHF3E")
49
+ );
50
+ break;
51
+ case 'TX_TRANSFER_ASSETOBJECT':
52
+ case 'TX_TRANSFER_ASSETOBJECT_FEE':
53
+ checks.push(() => this.checkFields(params, tx, { to: 'target' }), () => this.checkFields(params, tx, {
54
+ to: 'target',
55
+ amount: 'assetObjects.assetObjects[0].targetObject.amount',
56
+ assetId: 'assetObjects.assetObjects[0].targetObject.assetId'
57
+ }));
58
+ break;
59
+ case 'TX_CREATE_CONTRACT':
60
+ case 'TX_CREATE_CONTRACT_FEE':
61
+ checks.push(() => this.checkFields(params, tx, {
62
+ code: 'code',
63
+ amount: 'amount',
64
+ fuelLimit: 'fuelLimit',
65
+ sysId: 'sysId',
66
+ until: 'until'
67
+ }, {
68
+ contractAccount: 'target'
69
+ }), () => this.checkComplexField(params, tx, {
70
+ paramPath: 'tokenAmounts',
71
+ txPath: 'tokens',
72
+ paramTransform: tokens => (tokens !== null && tokens !== void 0 ? tokens : []).map((d) => ({ t: d.tokenId, a: d.amountToken })),
73
+ txTransform: tokens => (tokens !== null && tokens !== void 0 ? tokens : []).map((d) => ({ t: d.t, a: d.a }))
74
+ }));
75
+ break;
76
+ case 'TX_CALL_CONTRACT':
77
+ case 'TX_CALL_CONTRACT_FEE':
78
+ checks.push(() => this.checkFields(params, tx, {
79
+ contractAccount: 'target',
80
+ amount: 'amount',
81
+ fuelLimit: 'fuelLimit',
82
+ func: 'func',
83
+ argData: 'argData'
84
+ }), () => this.checkComplexField(params, tx, {
85
+ paramPath: 'tokenAmounts',
86
+ txPath: 'tokens',
87
+ paramTransform: tokens => (tokens !== null && tokens !== void 0 ? tokens : []).map((d) => ({ t: d.tokenId, a: d.amountToken })),
88
+ txTransform: tokens => (tokens !== null && tokens !== void 0 ? tokens : []).map((d) => ({ t: d.t, a: d.a }))
89
+ })
90
+ // TODO: tx.AssetObjects 는 아직 rpc가 만들어지지 않아서 확인을 하지 못했다
91
+ );
92
+ break;
93
+ case 'TX_POST_DATA':
94
+ case 'TX_POST_DATA_FEE':
95
+ checks.push(() => this.checkFields(params, tx, { data: 'data', label: 'label' }));
96
+ break;
97
+ case 'TX_OPEN_ACCOUNT':
98
+ checks.push(() => this.checkFields(params, tx, { account: 'addr', pk: 'key' }, {
99
+ sender: 'refLink.addr',
100
+ index: 'refLink.index'
101
+ }));
102
+ break;
103
+ case 'TX_PROVIDE_SCRIPT':
104
+ checks.push(() => this.checkFields(params, tx, {
105
+ target: 'target',
106
+ targetAfterTimeLock: 'targetAfterTimeLock',
107
+ amount: 'amount'
108
+ }), () => this.checkComplexField(params, tx, {
109
+ paramPath: 'scriptProvide',
110
+ txPath: 'scriptProvide',
111
+ paramTransform: code => wasm.compileCoreScript(code),
112
+ txTransform: code => code
113
+ }), () => this.checkComplexField(params, tx, {
114
+ paramPath: 'scriptAccept',
115
+ txPath: 'scriptAccept',
116
+ paramTransform: code => wasm.compileCoreScript(code),
117
+ txTransform: code => code
118
+ }), () => this.checkComplexField(params, tx, {
119
+ paramPath: 'args',
120
+ txPath: 'args',
121
+ paramTransform: args => args !== null && args !== void 0 ? args : [],
122
+ txTransform: args => args !== null && args !== void 0 ? args : []
123
+ }));
124
+ break;
125
+ case 'TX_ACCEPT_SCRIPT':
126
+ checks.push(() => this.checkFields(params, tx, { provider: 'refLink.addr', index: 'refLink.index' }), () => this.checkComplexField(params, tx, {
127
+ paramPath: 'args',
128
+ txPath: 'args',
129
+ paramTransform: args => args !== null && args !== void 0 ? args : [],
130
+ txTransform: args => args !== null && args !== void 0 ? args : []
131
+ }) // 배열 비교라서..
132
+ );
133
+ break;
134
+ case 'TX_CLOSE_ACCOUNT':
135
+ checks.push(() => this.checkFields(params, tx, { to: 'target' }));
136
+ break;
137
+ case 'TX_BECOME_HOST':
138
+ case 'TX_BECOME_GUEST':
139
+ break;
140
+ default:
141
+ break;
142
+ }
143
+ for (const check of checks) {
144
+ const result = check();
145
+ if (result !== true)
146
+ return result;
147
+ }
148
+ return { result: true, reason: 'success' };
149
+ }
150
+ catch (e) {
151
+ console.error(e);
152
+ return { result: false, reason: `tx verify fail. error: ${e.message}` };
153
+ }
154
+ };
155
+ /**
156
+ * params 객체와 tx 객체의 필드를 주어진 매핑에 따라 비교합니다.
157
+ * @param params 파라미터 객체.
158
+ * @param tx 검증할 트랜잭션 객체.
159
+ * @param mapping 키는 `params`의 속성 경로, 값은 `tx`의 속성 경로인 객체.
160
+ * @param optional mapping과 동일한 구조이나, `params` 값이 있을경우만 체크합니다. string은 빈문자열이 아닌 문자열, number는 0을 없다고 판단합니다
161
+ * @returns 모든 필드가 일치하면 `true`, 실패 시 `IntegrityCheckResult` 객체를 반환합니다.
162
+ */
163
+ this.checkFields = (params, tx, mapping, optional) => {
164
+ for (const paramKey in mapping) {
165
+ const txKey = mapping[paramKey];
166
+ const paramValue = this.getByPathIgnoreCase(params, paramKey);
167
+ const txValue = this.getByPath(tx, txKey);
168
+ if (paramValue !== txValue) {
169
+ return this.logAndFail(tx.type, paramKey, paramValue, txValue);
170
+ }
171
+ }
172
+ for (const paramKey in optional !== null && optional !== void 0 ? optional : {}) {
173
+ const txKey = optional[paramKey];
174
+ const paramValue = this.getByPathIgnoreCase(params, paramKey);
175
+ if (paramValue && paramValue !== '' && paramValue !== 0) {
176
+ const txValue = this.getByPath(tx, txKey);
177
+ if (paramValue !== txValue) {
178
+ return this.logAndFail(tx.type, paramKey, paramValue, txValue);
179
+ }
180
+ }
181
+ }
182
+ return true;
183
+ };
184
+ this.checkComplexField = (params, tx, { paramPath, txPath, paramTransform, txTransform }) => {
185
+ const paramValue = paramTransform(this.getByPathIgnoreCase(params, paramPath));
186
+ const txValue = txTransform(this.getByPath(tx, txPath));
187
+ if (!this.isDeepEqual(paramValue, txValue)) {
188
+ return this.logAndFail(tx.type, paramPath, paramValue, txValue);
189
+ }
190
+ return true;
191
+ };
192
+ }
193
+ logAndFail(txType, field, expected, actual) {
194
+ console.warn(`[TxnIntegrityChecker] ${txType} ${field}:`, expected, actual);
195
+ return { result: false, reason: 'tx integrity check fail', field };
196
+ }
197
+ // 속성명의 대소문자를 무시하고 값을 구한다
198
+ getByPathIgnoreCase(obj, path) {
199
+ const keys = path.split('.');
200
+ let current = obj;
201
+ for (const key of keys) {
202
+ if (current === null || typeof current !== 'object')
203
+ return undefined;
204
+ const actualKey = Object.keys(current).find(k => k.toLowerCase() === key.toLowerCase());
205
+ if (actualKey === undefined)
206
+ return undefined;
207
+ current = current[actualKey];
208
+ }
209
+ return current;
210
+ }
211
+ getByPath(obj, path) {
212
+ const keys = path.split('.');
213
+ let current = obj;
214
+ for (const key of keys) {
215
+ if (current == null)
216
+ return undefined;
217
+ current = current[key];
218
+ }
219
+ return current;
220
+ }
221
+ isDeepEqual(a, b) {
222
+ if (a === b)
223
+ return true;
224
+ if (a == null || b == null)
225
+ return a === b;
226
+ if (typeof a !== typeof b || typeof a !== 'object')
227
+ return false;
228
+ if (Array.isArray(a) !== Array.isArray(b))
229
+ return false;
230
+ if (Array.isArray(a)) {
231
+ if (a.length !== b.length)
232
+ return false;
233
+ return a.every((v, i) => this.isDeepEqual(v, b[i]));
234
+ }
235
+ const keysA = Object.keys(a);
236
+ const keysB = Object.keys(b);
237
+ if (keysA.length !== keysB.length)
238
+ return false;
239
+ return keysA.every(k => Object.prototype.hasOwnProperty.call(b, k) && this.isDeepEqual(a[k], b[k]));
240
+ }
241
+ }
242
+
243
+ /**
244
+ * Locus Chain WASM 4 개(Go lclib + AIMER/SMAUGT/HAETAE) 를 fetch 로 로드한다.
245
+ * 브라우저 / Node 양쪽 모두 동작.
246
+ */
247
+ const loadLocusWasm = lclib.load;
248
+ const txValidator = new TxValidator();
249
+ const verifyTxParams = txValidator.verifyTxParams;
250
+ const getClassByte = (hexstring) => {
251
+ // 0x 접두사 제거
252
+ const hex = hexstring.startsWith('0x') || hexstring.startsWith('0X')
253
+ ? hexstring.slice(2)
254
+ : hexstring;
255
+ // addressClassOffset = addressHashEnd - 1 이므로 해시의 마지막 바이트가 class byte
256
+ // (hex 문자 2개 = 1 byte)
257
+ const classByte = parseInt(hex.slice(-2), 16);
258
+ if (Number.isNaN(classByte)) {
259
+ throw new Error(`Invalid hex string: ${hexstring}`);
260
+ }
261
+ // 최상위 비트(0x80)가 세팅되어 있으면 User 클래스로 간주
262
+ if ((classByte & 0x80) !== 0) {
263
+ return addressClass.AddressClass.User;
264
+ }
265
+ return classByte;
266
+ };
267
+ const checkAddressType = (address) => {
268
+ try {
269
+ const hex = wasm.convertAddressToHex(address);
270
+ const classByte = getClassByte(hex);
271
+ // console.log('>>>>>>>>>>>', classByte)
272
+ const key = Object.keys(addressClass.AddressClass).find(k => classByte === addressClass.AddressClass[k]);
273
+ if (!key)
274
+ return -1;
275
+ return addressClass.AddressClass[key];
276
+ // console.warn('unknown address type', hex);
277
+ // // 참고!! ERC20 토큰은 주소로 알수 없음
278
+ }
279
+ catch (e) {
280
+ console.error(e + ' ' + address);
281
+ throw new Error('check error');
282
+ }
283
+ // return AddressType.UNKNOWN;
284
+ };
285
+ const isAccount = (addressType) => addressType === addressClass.AddressClass.User || addressType === addressClass.AddressClass.Synthetic || addressClass.AddressClass.VmEngine;
286
+ const isContract = (addressType) => addressType === addressClass.AddressClass.Contract;
287
+ const isToken = (addressType) => addressType === addressClass.AddressClass.UserToken ||
288
+ addressType === addressClass.AddressClass.ContractToken ||
289
+ addressType === addressClass.AddressClass.AssetToken ||
290
+ addressType === addressClass.AddressClass.AssetNFT;
291
+ const isSystemToken = (addressType) => addressType === addressClass.AddressClass.UserToken || addressType === addressClass.AddressClass.ContractToken;
292
+
293
+ exports.calculateTxLinkHash = wasm.calculateTxLinkHash;
294
+ exports.compileCoreScript = wasm.compileCoreScript;
295
+ exports.convertAddressToData = wasm.convertAddressToData;
296
+ exports.convertAddressToHex = wasm.convertAddressToHex;
297
+ exports.convertBase32ToData = wasm.convertBase32ToData;
298
+ exports.convertBase32ToHex = wasm.convertBase32ToHex;
299
+ exports.convertCurrency = wasm.convertCurrency;
300
+ exports.convertDataTo = wasm.convertDataTo;
301
+ exports.convertDataToAddress = wasm.convertDataToAddress;
302
+ exports.convertDataToBase32 = wasm.convertDataToBase32;
303
+ exports.convertDataToHex = wasm.convertDataToHex;
304
+ exports.convertDataToString = wasm.convertDataToString;
305
+ exports.convertHexToAddress = wasm.convertHexToAddress;
306
+ exports.convertHexToBase32 = wasm.convertHexToBase32;
307
+ exports.convertHexToData = wasm.convertHexToData;
308
+ exports.convertStringToData = wasm.convertStringToData;
309
+ exports.convertToData = wasm.convertToData;
310
+ exports.createAccountAndKeystore = wasm.createAccountAndKeystore;
311
+ exports.createMasterKeystore = wasm.createMasterKeystore;
312
+ exports.createNormalKey = wasm.createNormalKey;
313
+ exports.createNormalKeystore = wasm.createNormalKeystore;
314
+ exports.decodeTxs = wasm.decodeTxs;
315
+ exports.deriveKeysFromMnemonic = wasm.deriveKeysFromMnemonic;
316
+ exports.deriveKeysFromMnemonicAndPath = wasm.deriveKeysFromMnemonicAndPath;
317
+ exports.disCompileCoreScript = wasm.disCompileCoreScript;
318
+ exports.encodeTxCurrency = wasm.encodeTxCurrency;
319
+ exports.encodeTxNumber = wasm.encodeTxNumber;
320
+ exports.generateMnemonic = wasm.generateMnemonic;
321
+ exports.generateMnemonicBySeed = wasm.generateMnemonicBySeed;
322
+ exports.getDefFromCoreScript = wasm.getDefFromCoreScript;
323
+ exports.getHomeShard = wasm.getHomeShard;
324
+ exports.getLibraryVersions = wasm.getLibraryVersions;
325
+ exports.gzipAndEncode = wasm.gzipAndEncode;
326
+ exports.hash = wasm.hash;
327
+ exports.isGrantConsumingTx = wasm.isGrantConsumingTx;
328
+ exports.loadMasterKeystore = wasm.loadMasterKeystore;
329
+ exports.loadNormalKeystore = wasm.loadNormalKeystore;
330
+ exports.makeCurrency = wasm.makeCurrency;
331
+ exports.sign = wasm.sign;
332
+ exports.signByMasterKey = wasm.signByMasterKey;
333
+ exports.signKeyBind = wasm.signKeyBind;
334
+ exports.testCoreScript = wasm.testCoreScript;
335
+ exports.verify = wasm.verify;
336
+ exports.verifyByMasterKey = wasm.verifyByMasterKey;
337
+ exports.verifyMerkleProof = wasm.verifyMerkleProof;
338
+ exports.verifyTx = wasm.verifyTx;
339
+ exports.createKeystoreBundle = keystore.createKeystoreBundle;
340
+ exports.splitKeystoreBundle = keystore.splitKeystoreBundle;
341
+ exports.unlockKeystoreBundle = keystore.unlockKeystoreBundle;
342
+ exports.unlockMasterKeystore = keystore.unlockMasterKeystore;
343
+ exports.unlockNormalKeystore = keystore.unlockNormalKeystore;
344
+ exports.checkAddressType = checkAddressType;
345
+ exports.isAccount = isAccount;
346
+ exports.isContract = isContract;
347
+ exports.isSystemToken = isSystemToken;
348
+ exports.isToken = isToken;
349
+ exports.loadLocusWasm = loadLocusWasm;
350
+ exports.txValidator = txValidator;
351
+ exports.verifyTxParams = verifyTxParams;
352
+
353
+ }));
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  var addressClass = require('../chunks/address-class-Cjy48Uqk.cjs');
4
- var wasm = require('../chunks/wasm-DTyHBxcY.cjs');
5
- var keystore = require('../chunks/keystore-BbK5pVrh.cjs');
6
- var lclib = require('../chunks/lclib-DuoOR0-Q.cjs');
4
+ var wasm = require('../chunks/wasm-D4S52Ifh.cjs');
5
+ var keystore = require('../chunks/keystore-CjcbAa1r.cjs');
6
+ var lclib = require('../chunks/lclib-xRDGxtgw.cjs');
7
7
  require('../chunks/base-Cy5SSYLF.cjs');
8
8
  require('../chunks/account-BAsiKnSL.cjs');
9
9
  require('../chunks/tslib.es6-Cfi3-HmA.cjs');
@@ -1,8 +1,8 @@
1
1
  import { A as AddressClass } from '../chunks/address-class-CHAZYhdZ.js';
2
- import { T as verifyTx, d as compileCoreScript, f as convertAddressToHex } from '../chunks/wasm-BtPcXTR4.js';
3
- export { b as calculateTxLinkHash, e as convertAddressToData, g as convertBase32ToData, h as convertBase32ToHex, i as convertCurrency, j as convertDataTo, k as convertDataToAddress, m as convertDataToBase32, n as convertDataToHex, o as convertDataToString, p as convertHexToAddress, q as convertHexToBase32, r as convertHexToData, s as convertStringToData, t as convertToData, c as createAccountAndKeystore, u as createMasterKeystore, v as createNormalKey, w as createNormalKeystore, x as decodeTxs, y as deriveKeysFromMnemonic, z as deriveKeysFromMnemonicAndPath, A as disCompileCoreScript, B as encodeTxCurrency, C as encodeTxNumber, D as generateMnemonic, E as generateMnemonicBySeed, F as getDefFromCoreScript, G as getHomeShard, H as getLibraryVersions, I as gzipAndEncode, J as hash, K as isGrantConsumingTx, l as loadMasterKeystore, a as loadNormalKeystore, L as makeCurrency, M as sign, N as signByMasterKey, O as signKeyBind, P as testCoreScript, Q as verify, R as verifyByMasterKey, S as verifyMerkleProof } from '../chunks/wasm-BtPcXTR4.js';
4
- export { c as createKeystoreBundle, s as splitKeystoreBundle, u as unlockKeystoreBundle, a as unlockMasterKeystore, b as unlockNormalKeystore } from '../chunks/keystore-BFVSylSw.js';
5
- import { l as load } from '../chunks/lclib-C2eG5HzD.js';
2
+ import { T as verifyTx, d as compileCoreScript, f as convertAddressToHex } from '../chunks/wasm-C4WNl2YQ.js';
3
+ export { b as calculateTxLinkHash, e as convertAddressToData, g as convertBase32ToData, h as convertBase32ToHex, i as convertCurrency, j as convertDataTo, k as convertDataToAddress, m as convertDataToBase32, n as convertDataToHex, o as convertDataToString, p as convertHexToAddress, q as convertHexToBase32, r as convertHexToData, s as convertStringToData, t as convertToData, c as createAccountAndKeystore, u as createMasterKeystore, v as createNormalKey, w as createNormalKeystore, x as decodeTxs, y as deriveKeysFromMnemonic, z as deriveKeysFromMnemonicAndPath, A as disCompileCoreScript, B as encodeTxCurrency, C as encodeTxNumber, D as generateMnemonic, E as generateMnemonicBySeed, F as getDefFromCoreScript, G as getHomeShard, H as getLibraryVersions, I as gzipAndEncode, J as hash, K as isGrantConsumingTx, l as loadMasterKeystore, a as loadNormalKeystore, L as makeCurrency, M as sign, N as signByMasterKey, O as signKeyBind, P as testCoreScript, Q as verify, R as verifyByMasterKey, S as verifyMerkleProof } from '../chunks/wasm-C4WNl2YQ.js';
4
+ export { c as createKeystoreBundle, s as splitKeystoreBundle, u as unlockKeystoreBundle, a as unlockMasterKeystore, b as unlockNormalKeystore } from '../chunks/keystore-BMgBWq6G.js';
5
+ import { l as load } from '../chunks/lclib-BlnZKIGv.js';
6
6
  import '../chunks/base-BQXfRsuw.js';
7
7
  import '../chunks/account-FZT9LH_s.js';
8
8
  import '../chunks/tslib.es6-WQS2tr1v.js';