@alephium/web3 0.2.0 → 0.3.0-rc.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/api/api-alephium.d.ts +5 -5
- package/dist/src/api/api-alephium.js +1 -1
- package/dist/src/api/api-explorer.d.ts +25 -0
- package/dist/src/api/api-explorer.js +29 -0
- package/dist/src/constants.d.ts +1 -0
- package/dist/src/constants.js +2 -1
- package/dist/src/contract/contract.d.ts +1 -0
- package/dist/src/contract/contract.js +8 -5
- package/dist/src/utils/utils.d.ts +1 -1
- package/dist/src/utils/utils.js +10 -3
- package/package.json +3 -3
- package/src/api/api-alephium.ts +5 -5
- package/src/api/api-explorer.ts +44 -0
- package/src/constants.ts +1 -0
- package/src/contract/contract.ts +9 -5
- package/src/utils/utils.ts +10 -4
|
@@ -346,7 +346,7 @@ export interface CompilerOptions {
|
|
|
346
346
|
ignoreUnusedVariablesWarnings?: boolean;
|
|
347
347
|
ignoreUnusedFieldsWarnings?: boolean;
|
|
348
348
|
ignoreUnusedPrivateFunctionsWarnings?: boolean;
|
|
349
|
-
|
|
349
|
+
ignoreUpdateFieldsCheckWarnings?: boolean;
|
|
350
350
|
ignoreExternalCallCheckWarnings?: boolean;
|
|
351
351
|
}
|
|
352
352
|
export interface Confirmed {
|
|
@@ -737,11 +737,11 @@ export interface UTXO {
|
|
|
737
737
|
ref: OutputRef;
|
|
738
738
|
/** @format uint256 */
|
|
739
739
|
amount: string;
|
|
740
|
-
tokens
|
|
740
|
+
tokens?: Token[];
|
|
741
741
|
/** @format int64 */
|
|
742
|
-
lockTime
|
|
742
|
+
lockTime?: number;
|
|
743
743
|
/** @format hex-string */
|
|
744
|
-
additionalData
|
|
744
|
+
additionalData?: string;
|
|
745
745
|
}
|
|
746
746
|
export interface UTXOs {
|
|
747
747
|
utxos: UTXO[];
|
|
@@ -908,7 +908,7 @@ export declare class HttpClient<SecurityDataType = unknown> {
|
|
|
908
908
|
}
|
|
909
909
|
/**
|
|
910
910
|
* @title Alephium API
|
|
911
|
-
* @version 1.
|
|
911
|
+
* @version 1.6.0
|
|
912
912
|
* @baseUrl ../
|
|
913
913
|
*/
|
|
914
914
|
export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
|
@@ -91,6 +91,8 @@ export interface Input {
|
|
|
91
91
|
outputRef: OutputRef;
|
|
92
92
|
/** @format hex-string */
|
|
93
93
|
unlockScript?: string;
|
|
94
|
+
/** @format 32-byte-hash */
|
|
95
|
+
txHashRef?: string;
|
|
94
96
|
address?: string;
|
|
95
97
|
/** @format uint256 */
|
|
96
98
|
attoAlphAmount?: string;
|
|
@@ -352,6 +354,18 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
352
354
|
limit?: number;
|
|
353
355
|
reverse?: boolean;
|
|
354
356
|
}, params?: RequestParams) => Promise<Transaction[]>;
|
|
357
|
+
/**
|
|
358
|
+
* @description List transactions for given addresses
|
|
359
|
+
*
|
|
360
|
+
* @tags Addresses
|
|
361
|
+
* @name PostAddressesTransactions
|
|
362
|
+
* @request POST:/addresses/transactions
|
|
363
|
+
*/
|
|
364
|
+
postAddressesTransactions: (query?: {
|
|
365
|
+
page?: number;
|
|
366
|
+
limit?: number;
|
|
367
|
+
reverse?: boolean;
|
|
368
|
+
}, data?: string[], params?: RequestParams) => Promise<Transaction[]>;
|
|
355
369
|
/**
|
|
356
370
|
* @description List transactions of a given address within a time-range
|
|
357
371
|
*
|
|
@@ -418,6 +432,17 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
418
432
|
* @request GET:/addresses/{address}/tokens/{token_id}/balance
|
|
419
433
|
*/
|
|
420
434
|
getAddressesAddressTokensTokenIdBalance: (address: string, tokenId: string, params?: RequestParams) => Promise<AddressBalance>;
|
|
435
|
+
/**
|
|
436
|
+
* No description
|
|
437
|
+
*
|
|
438
|
+
* @tags Addresses
|
|
439
|
+
* @name GetAddressesAddressExportTransactionsCsv
|
|
440
|
+
* @request GET:/addresses/{address}/export-transactions/csv
|
|
441
|
+
*/
|
|
442
|
+
getAddressesAddressExportTransactionsCsv: (address: string, query: {
|
|
443
|
+
fromTs: number;
|
|
444
|
+
toTs: number;
|
|
445
|
+
}, params?: RequestParams) => Promise<string>;
|
|
421
446
|
};
|
|
422
447
|
addressesActive: {
|
|
423
448
|
/**
|
|
@@ -253,6 +253,22 @@ class Api extends HttpClient {
|
|
|
253
253
|
format: 'json',
|
|
254
254
|
...params
|
|
255
255
|
}).then(utils_1.convertHttpResponse),
|
|
256
|
+
/**
|
|
257
|
+
* @description List transactions for given addresses
|
|
258
|
+
*
|
|
259
|
+
* @tags Addresses
|
|
260
|
+
* @name PostAddressesTransactions
|
|
261
|
+
* @request POST:/addresses/transactions
|
|
262
|
+
*/
|
|
263
|
+
postAddressesTransactions: (query, data, params = {}) => this.request({
|
|
264
|
+
path: `/addresses/transactions`,
|
|
265
|
+
method: 'POST',
|
|
266
|
+
query: query,
|
|
267
|
+
body: data,
|
|
268
|
+
type: ContentType.Json,
|
|
269
|
+
format: 'json',
|
|
270
|
+
...params
|
|
271
|
+
}).then(utils_1.convertHttpResponse),
|
|
256
272
|
/**
|
|
257
273
|
* @description List transactions of a given address within a time-range
|
|
258
274
|
*
|
|
@@ -345,6 +361,19 @@ class Api extends HttpClient {
|
|
|
345
361
|
method: 'GET',
|
|
346
362
|
format: 'json',
|
|
347
363
|
...params
|
|
364
|
+
}).then(utils_1.convertHttpResponse),
|
|
365
|
+
/**
|
|
366
|
+
* No description
|
|
367
|
+
*
|
|
368
|
+
* @tags Addresses
|
|
369
|
+
* @name GetAddressesAddressExportTransactionsCsv
|
|
370
|
+
* @request GET:/addresses/{address}/export-transactions/csv
|
|
371
|
+
*/
|
|
372
|
+
getAddressesAddressExportTransactionsCsv: (address, query, params = {}) => this.request({
|
|
373
|
+
path: `/addresses/${address}/export-transactions/csv`,
|
|
374
|
+
method: 'GET',
|
|
375
|
+
query: query,
|
|
376
|
+
...params
|
|
348
377
|
}).then(utils_1.convertHttpResponse)
|
|
349
378
|
};
|
|
350
379
|
this.addressesActive = {
|
package/dist/src/constants.d.ts
CHANGED
package/dist/src/constants.js
CHANGED
|
@@ -17,6 +17,7 @@ You should have received a copy of the GNU Lesser General Public License
|
|
|
17
17
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.MIN_UTXO_SET_AMOUNT = exports.TOTAL_NUMBER_OF_GROUPS = void 0;
|
|
20
|
+
exports.ALPH_TOKEN_ID = exports.MIN_UTXO_SET_AMOUNT = exports.TOTAL_NUMBER_OF_GROUPS = void 0;
|
|
21
21
|
exports.TOTAL_NUMBER_OF_GROUPS = 4;
|
|
22
22
|
exports.MIN_UTXO_SET_AMOUNT = BigInt(1000000000000);
|
|
23
|
+
exports.ALPH_TOKEN_ID = ''.padStart(64, '0');
|
|
@@ -118,6 +118,7 @@ export declare class Contract extends Artifact {
|
|
|
118
118
|
toApiContractStates(states?: ContractState[]): node.ContractState[] | undefined;
|
|
119
119
|
toTestContract(funcName: string, params: TestContractParams): node.TestContract;
|
|
120
120
|
fromApiContractState(state: node.ContractState): ContractState;
|
|
121
|
+
static fromApiContractState(state: node.ContractState): ContractState;
|
|
121
122
|
static ContractCreatedEvent: EventSig;
|
|
122
123
|
static ContractDestroyedEvent: EventSig;
|
|
123
124
|
static fromApiEvent(event: node.ContractEventByTxId, codeHash: string | undefined): ContractEventByTxId;
|
|
@@ -65,7 +65,7 @@ exports.DEFAULT_NODE_COMPILER_OPTIONS = {
|
|
|
65
65
|
ignoreUnusedVariablesWarnings: false,
|
|
66
66
|
ignoreUnusedFieldsWarnings: false,
|
|
67
67
|
ignoreUnusedPrivateFunctionsWarnings: false,
|
|
68
|
-
|
|
68
|
+
ignoreUpdateFieldsCheckWarnings: false,
|
|
69
69
|
ignoreExternalCallCheckWarnings: false
|
|
70
70
|
};
|
|
71
71
|
exports.DEFAULT_COMPILER_OPTIONS = { errorOnWarnings: true, ...exports.DEFAULT_NODE_COMPILER_OPTIONS };
|
|
@@ -530,18 +530,21 @@ class Contract extends Artifact {
|
|
|
530
530
|
};
|
|
531
531
|
}
|
|
532
532
|
fromApiContractState(state) {
|
|
533
|
-
const contract = Project.currentProject.contractByCodeHash(state.codeHash);
|
|
534
533
|
return {
|
|
535
534
|
address: state.address,
|
|
536
535
|
contractId: (0, utils_1.binToHex)((0, utils_1.contractIdFromAddress)(state.address)),
|
|
537
536
|
bytecode: state.bytecode,
|
|
538
537
|
initialStateHash: state.initialStateHash,
|
|
539
538
|
codeHash: state.codeHash,
|
|
540
|
-
fields: fromApiFields(state.fields,
|
|
541
|
-
fieldsSig:
|
|
539
|
+
fields: fromApiFields(state.fields, this.fieldsSig),
|
|
540
|
+
fieldsSig: this.fieldsSig,
|
|
542
541
|
asset: fromApiAsset(state.asset)
|
|
543
542
|
};
|
|
544
543
|
}
|
|
544
|
+
static fromApiContractState(state) {
|
|
545
|
+
const contract = Project.currentProject.contractByCodeHash(state.codeHash);
|
|
546
|
+
return contract.fromApiContractState(state);
|
|
547
|
+
}
|
|
545
548
|
static fromApiEvent(event, codeHash) {
|
|
546
549
|
let eventSig;
|
|
547
550
|
if (event.eventIndex == -1) {
|
|
@@ -570,7 +573,7 @@ class Contract extends Artifact {
|
|
|
570
573
|
contractAddress: result.address,
|
|
571
574
|
returns: (0, api_1.fromApiArray)(result.returns, this.functions[`${methodIndex}`].returnTypes),
|
|
572
575
|
gasUsed: result.gasUsed,
|
|
573
|
-
contracts: result.contracts.map((contract) =>
|
|
576
|
+
contracts: result.contracts.map((contract) => Contract.fromApiContractState(contract)),
|
|
574
577
|
txOutputs: result.txOutputs.map(fromApiOutput),
|
|
575
578
|
events: result.events.map((event) => {
|
|
576
579
|
const contractAddress = event.contractAddress;
|
|
@@ -13,7 +13,7 @@ export declare function publicKeyFromPrivateKey(privateKey: string): string;
|
|
|
13
13
|
export declare function addressFromPublicKey(publicKey: string): string;
|
|
14
14
|
export declare function addressFromContractId(contractId: string): string;
|
|
15
15
|
export declare function contractIdFromTx(txId: string, outputIndex: number): string;
|
|
16
|
-
export declare function subContractId(parentContractId: string, pathInHex: string): string;
|
|
16
|
+
export declare function subContractId(parentContractId: string, pathInHex: string, group: number): string;
|
|
17
17
|
export declare function stringToHex(str: string): string;
|
|
18
18
|
export declare function hexToString(str: string): string;
|
|
19
19
|
export declare function timeout(ms: number): Promise<void>;
|
package/dist/src/utils/utils.js
CHANGED
|
@@ -64,7 +64,7 @@ function xorByte(intValue) {
|
|
|
64
64
|
}
|
|
65
65
|
exports.xorByte = xorByte;
|
|
66
66
|
function isHexString(input) {
|
|
67
|
-
return input.length % 2 === 0 &&
|
|
67
|
+
return input.length % 2 === 0 && /^[0-9a-fA-F]*$/.test(input);
|
|
68
68
|
}
|
|
69
69
|
exports.isHexString = isHexString;
|
|
70
70
|
var AddressType;
|
|
@@ -177,9 +177,16 @@ function contractIdFromTx(txId, outputIndex) {
|
|
|
177
177
|
return binToHex(hash);
|
|
178
178
|
}
|
|
179
179
|
exports.contractIdFromTx = contractIdFromTx;
|
|
180
|
-
function subContractId(parentContractId, pathInHex) {
|
|
180
|
+
function subContractId(parentContractId, pathInHex, group) {
|
|
181
|
+
if (group < 0 || group >= constants_1.TOTAL_NUMBER_OF_GROUPS) {
|
|
182
|
+
throw new Error(`Invalid group ${group}`);
|
|
183
|
+
}
|
|
181
184
|
const data = buffer_1.Buffer.concat([hexToBinUnsafe(parentContractId), hexToBinUnsafe(pathInHex)]);
|
|
182
|
-
|
|
185
|
+
const bytes = buffer_1.Buffer.concat([
|
|
186
|
+
blakejs_1.default.blake2b(blakejs_1.default.blake2b(data, undefined, 32), undefined, 32).slice(0, -1),
|
|
187
|
+
buffer_1.Buffer.from([group])
|
|
188
|
+
]);
|
|
189
|
+
return binToHex(bytes);
|
|
183
190
|
}
|
|
184
191
|
exports.subContractId = subContractId;
|
|
185
192
|
function stringToHex(str) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alephium/web3",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-rc.0",
|
|
4
4
|
"description": "A JS/TS library to interact with the Alephium platform",
|
|
5
5
|
"license": "GPL",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
},
|
|
28
28
|
"author": "Alephium dev <dev@alephium.org>",
|
|
29
29
|
"config": {
|
|
30
|
-
"alephium_version": "1.
|
|
31
|
-
"explorer_backend_version": "1.
|
|
30
|
+
"alephium_version": "1.6.0-rc0",
|
|
31
|
+
"explorer_backend_version": "1.11.2"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "rm -rf dist/* && npx tsc --build . && webpack",
|
package/src/api/api-alephium.ts
CHANGED
|
@@ -471,7 +471,7 @@ export interface CompilerOptions {
|
|
|
471
471
|
ignoreUnusedVariablesWarnings?: boolean
|
|
472
472
|
ignoreUnusedFieldsWarnings?: boolean
|
|
473
473
|
ignoreUnusedPrivateFunctionsWarnings?: boolean
|
|
474
|
-
|
|
474
|
+
ignoreUpdateFieldsCheckWarnings?: boolean
|
|
475
475
|
ignoreExternalCallCheckWarnings?: boolean
|
|
476
476
|
}
|
|
477
477
|
|
|
@@ -979,13 +979,13 @@ export interface UTXO {
|
|
|
979
979
|
|
|
980
980
|
/** @format uint256 */
|
|
981
981
|
amount: string
|
|
982
|
-
tokens
|
|
982
|
+
tokens?: Token[]
|
|
983
983
|
|
|
984
984
|
/** @format int64 */
|
|
985
|
-
lockTime
|
|
985
|
+
lockTime?: number
|
|
986
986
|
|
|
987
987
|
/** @format hex-string */
|
|
988
|
-
additionalData
|
|
988
|
+
additionalData?: string
|
|
989
989
|
}
|
|
990
990
|
|
|
991
991
|
export interface UTXOs {
|
|
@@ -1332,7 +1332,7 @@ export class HttpClient<SecurityDataType = unknown> {
|
|
|
1332
1332
|
|
|
1333
1333
|
/**
|
|
1334
1334
|
* @title Alephium API
|
|
1335
|
-
* @version 1.
|
|
1335
|
+
* @version 1.6.0
|
|
1336
1336
|
* @baseUrl ../
|
|
1337
1337
|
*/
|
|
1338
1338
|
export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
package/src/api/api-explorer.ts
CHANGED
|
@@ -133,6 +133,9 @@ export interface Input {
|
|
|
133
133
|
|
|
134
134
|
/** @format hex-string */
|
|
135
135
|
unlockScript?: string
|
|
136
|
+
|
|
137
|
+
/** @format 32-byte-hash */
|
|
138
|
+
txHashRef?: string
|
|
136
139
|
address?: string
|
|
137
140
|
|
|
138
141
|
/** @format uint256 */
|
|
@@ -637,6 +640,28 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
637
640
|
...params
|
|
638
641
|
}).then(convertHttpResponse),
|
|
639
642
|
|
|
643
|
+
/**
|
|
644
|
+
* @description List transactions for given addresses
|
|
645
|
+
*
|
|
646
|
+
* @tags Addresses
|
|
647
|
+
* @name PostAddressesTransactions
|
|
648
|
+
* @request POST:/addresses/transactions
|
|
649
|
+
*/
|
|
650
|
+
postAddressesTransactions: (
|
|
651
|
+
query?: { page?: number; limit?: number; reverse?: boolean },
|
|
652
|
+
data?: string[],
|
|
653
|
+
params: RequestParams = {}
|
|
654
|
+
) =>
|
|
655
|
+
this.request<Transaction[], BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
656
|
+
path: `/addresses/transactions`,
|
|
657
|
+
method: 'POST',
|
|
658
|
+
query: query,
|
|
659
|
+
body: data,
|
|
660
|
+
type: ContentType.Json,
|
|
661
|
+
format: 'json',
|
|
662
|
+
...params
|
|
663
|
+
}).then(convertHttpResponse),
|
|
664
|
+
|
|
640
665
|
/**
|
|
641
666
|
* @description List transactions of a given address within a time-range
|
|
642
667
|
*
|
|
@@ -751,6 +776,25 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
751
776
|
method: 'GET',
|
|
752
777
|
format: 'json',
|
|
753
778
|
...params
|
|
779
|
+
}).then(convertHttpResponse),
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* No description
|
|
783
|
+
*
|
|
784
|
+
* @tags Addresses
|
|
785
|
+
* @name GetAddressesAddressExportTransactionsCsv
|
|
786
|
+
* @request GET:/addresses/{address}/export-transactions/csv
|
|
787
|
+
*/
|
|
788
|
+
getAddressesAddressExportTransactionsCsv: (
|
|
789
|
+
address: string,
|
|
790
|
+
query: { fromTs: number; toTs: number },
|
|
791
|
+
params: RequestParams = {}
|
|
792
|
+
) =>
|
|
793
|
+
this.request<string, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
794
|
+
path: `/addresses/${address}/export-transactions/csv`,
|
|
795
|
+
method: 'GET',
|
|
796
|
+
query: query,
|
|
797
|
+
...params
|
|
754
798
|
}).then(convertHttpResponse)
|
|
755
799
|
}
|
|
756
800
|
addressesActive = {
|
package/src/constants.ts
CHANGED
package/src/contract/contract.ts
CHANGED
|
@@ -69,7 +69,7 @@ export const DEFAULT_NODE_COMPILER_OPTIONS: node.CompilerOptions = {
|
|
|
69
69
|
ignoreUnusedVariablesWarnings: false,
|
|
70
70
|
ignoreUnusedFieldsWarnings: false,
|
|
71
71
|
ignoreUnusedPrivateFunctionsWarnings: false,
|
|
72
|
-
|
|
72
|
+
ignoreUpdateFieldsCheckWarnings: false,
|
|
73
73
|
ignoreExternalCallCheckWarnings: false
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -746,19 +746,23 @@ export class Contract extends Artifact {
|
|
|
746
746
|
}
|
|
747
747
|
|
|
748
748
|
fromApiContractState(state: node.ContractState): ContractState {
|
|
749
|
-
const contract = Project.currentProject.contractByCodeHash(state.codeHash)
|
|
750
749
|
return {
|
|
751
750
|
address: state.address,
|
|
752
751
|
contractId: binToHex(contractIdFromAddress(state.address)),
|
|
753
752
|
bytecode: state.bytecode,
|
|
754
753
|
initialStateHash: state.initialStateHash,
|
|
755
754
|
codeHash: state.codeHash,
|
|
756
|
-
fields: fromApiFields(state.fields,
|
|
757
|
-
fieldsSig:
|
|
755
|
+
fields: fromApiFields(state.fields, this.fieldsSig),
|
|
756
|
+
fieldsSig: this.fieldsSig,
|
|
758
757
|
asset: fromApiAsset(state.asset)
|
|
759
758
|
}
|
|
760
759
|
}
|
|
761
760
|
|
|
761
|
+
static fromApiContractState(state: node.ContractState): ContractState {
|
|
762
|
+
const contract = Project.currentProject.contractByCodeHash(state.codeHash)
|
|
763
|
+
return contract.fromApiContractState(state)
|
|
764
|
+
}
|
|
765
|
+
|
|
762
766
|
static ContractCreatedEvent: EventSig = {
|
|
763
767
|
name: 'ContractCreated',
|
|
764
768
|
fieldNames: ['address'],
|
|
@@ -800,7 +804,7 @@ export class Contract extends Artifact {
|
|
|
800
804
|
contractAddress: result.address,
|
|
801
805
|
returns: fromApiArray(result.returns, this.functions[`${methodIndex}`].returnTypes),
|
|
802
806
|
gasUsed: result.gasUsed,
|
|
803
|
-
contracts: result.contracts.map((contract) =>
|
|
807
|
+
contracts: result.contracts.map((contract) => Contract.fromApiContractState(contract)),
|
|
804
808
|
txOutputs: result.txOutputs.map(fromApiOutput),
|
|
805
809
|
events: result.events.map((event) => {
|
|
806
810
|
const contractAddress = event.contractAddress
|
package/src/utils/utils.ts
CHANGED
|
@@ -63,7 +63,7 @@ export function xorByte(intValue: number): number {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
export function isHexString(input: string): boolean {
|
|
66
|
-
return input.length % 2 === 0 &&
|
|
66
|
+
return input.length % 2 === 0 && /^[0-9a-fA-F]*$/.test(input)
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
enum AddressType {
|
|
@@ -181,10 +181,16 @@ export function contractIdFromTx(txId: string, outputIndex: number): string {
|
|
|
181
181
|
return binToHex(hash)
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
export function subContractId(parentContractId: string, pathInHex: string): string {
|
|
184
|
+
export function subContractId(parentContractId: string, pathInHex: string, group: number): string {
|
|
185
|
+
if (group < 0 || group >= TOTAL_NUMBER_OF_GROUPS) {
|
|
186
|
+
throw new Error(`Invalid group ${group}`)
|
|
187
|
+
}
|
|
185
188
|
const data = Buffer.concat([hexToBinUnsafe(parentContractId), hexToBinUnsafe(pathInHex)])
|
|
186
|
-
|
|
187
|
-
|
|
189
|
+
const bytes = Buffer.concat([
|
|
190
|
+
blake.blake2b(blake.blake2b(data, undefined, 32), undefined, 32).slice(0, -1),
|
|
191
|
+
Buffer.from([group])
|
|
192
|
+
])
|
|
193
|
+
return binToHex(bytes)
|
|
188
194
|
}
|
|
189
195
|
|
|
190
196
|
export function stringToHex(str: string): string {
|