@alephium/web3 0.6.1 → 0.6.3
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/constants.d.ts +1 -0
- package/dist/src/constants.js +2 -1
- package/dist/src/utils/utils.d.ts +5 -0
- package/dist/src/utils/utils.js +9 -1
- package/package.json +1 -1
- package/src/constants.ts +1 -0
- package/src/utils/utils.ts +11 -1
package/dist/src/constants.d.ts
CHANGED
package/dist/src/constants.js
CHANGED
|
@@ -17,8 +17,9 @@ 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.DUST_AMOUNT = exports.ONE_ALPH = exports.ALPH_TOKEN_ID = exports.MIN_UTXO_SET_AMOUNT = exports.TOTAL_NUMBER_OF_GROUPS = void 0;
|
|
20
|
+
exports.DUST_AMOUNT = exports.ONE_ALPH = exports.ALPH_TOKEN_ID = exports.MIN_UTXO_SET_AMOUNT = exports.TOTAL_NUMBER_OF_CHAINS = exports.TOTAL_NUMBER_OF_GROUPS = void 0;
|
|
21
21
|
exports.TOTAL_NUMBER_OF_GROUPS = 4;
|
|
22
|
+
exports.TOTAL_NUMBER_OF_CHAINS = exports.TOTAL_NUMBER_OF_GROUPS * exports.TOTAL_NUMBER_OF_GROUPS;
|
|
22
23
|
exports.MIN_UTXO_SET_AMOUNT = BigInt(1000000000000);
|
|
23
24
|
exports.ALPH_TOKEN_ID = ''.padStart(64, '0');
|
|
24
25
|
exports.ONE_ALPH = 10n ** 18n;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ec as EC, SignatureInput } from 'elliptic';
|
|
2
2
|
import BN from 'bn.js';
|
|
3
3
|
import { KeyType } from '../signer';
|
|
4
|
+
import { HexString } from '../contract';
|
|
4
5
|
export declare function encodeSignature(signature: EC.Signature | {
|
|
5
6
|
r: BN;
|
|
6
7
|
s: BN;
|
|
@@ -20,6 +21,10 @@ export declare function addressFromPublicKey(publicKey: string, _keyType?: KeyTy
|
|
|
20
21
|
export declare function addressFromContractId(contractId: string): string;
|
|
21
22
|
export declare function contractIdFromTx(txId: string, outputIndex: number): string;
|
|
22
23
|
export declare function subContractId(parentContractId: string, pathInHex: string, group: number): string;
|
|
24
|
+
export declare function blockChainIndex(blockHash: HexString): {
|
|
25
|
+
fromGroup: number;
|
|
26
|
+
toGroup: number;
|
|
27
|
+
};
|
|
23
28
|
export declare function stringToHex(str: string): string;
|
|
24
29
|
export declare function hexToString(str: string): string;
|
|
25
30
|
export declare function sleep(ms: number): Promise<void>;
|
package/dist/src/utils/utils.js
CHANGED
|
@@ -20,7 +20,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
20
20
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.assertType = exports.sleep = exports.hexToString = exports.stringToHex = exports.subContractId = exports.contractIdFromTx = exports.addressFromContractId = exports.addressFromPublicKey = exports.publicKeyFromPrivateKey = exports.groupOfPrivateKey = exports.binToHex = exports.hexToBinUnsafe = exports.tokenIdFromAddress = exports.contractIdFromAddress = exports.groupOfAddress = exports.isHexString = exports.xorByte = exports.signatureDecode = exports.encodeHexSignature = exports.encodeSignature = void 0;
|
|
23
|
+
exports.assertType = exports.sleep = exports.hexToString = exports.stringToHex = exports.blockChainIndex = exports.subContractId = exports.contractIdFromTx = exports.addressFromContractId = exports.addressFromPublicKey = exports.publicKeyFromPrivateKey = exports.groupOfPrivateKey = exports.binToHex = exports.hexToBinUnsafe = exports.tokenIdFromAddress = exports.contractIdFromAddress = exports.groupOfAddress = exports.isHexString = exports.xorByte = exports.signatureDecode = exports.encodeHexSignature = exports.encodeSignature = void 0;
|
|
24
24
|
const elliptic_1 = require("elliptic");
|
|
25
25
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
26
26
|
const blakejs_1 = __importDefault(require("blakejs"));
|
|
@@ -210,6 +210,14 @@ function subContractId(parentContractId, pathInHex, group) {
|
|
|
210
210
|
return binToHex(bytes);
|
|
211
211
|
}
|
|
212
212
|
exports.subContractId = subContractId;
|
|
213
|
+
function blockChainIndex(blockHash) {
|
|
214
|
+
if (blockHash.length != 64) {
|
|
215
|
+
throw Error(`Invalid block hash: ${blockHash}`);
|
|
216
|
+
}
|
|
217
|
+
const rawIndex = Number('0x' + blockHash.slice(-4)) % constants_1.TOTAL_NUMBER_OF_CHAINS;
|
|
218
|
+
return { fromGroup: Math.floor(rawIndex / constants_1.TOTAL_NUMBER_OF_GROUPS), toGroup: rawIndex % constants_1.TOTAL_NUMBER_OF_GROUPS };
|
|
219
|
+
}
|
|
220
|
+
exports.blockChainIndex = blockChainIndex;
|
|
213
221
|
function stringToHex(str) {
|
|
214
222
|
let hex = '';
|
|
215
223
|
for (let i = 0; i < str.length; i++) {
|
package/package.json
CHANGED
package/src/constants.ts
CHANGED
|
@@ -17,6 +17,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
export const TOTAL_NUMBER_OF_GROUPS = 4
|
|
20
|
+
export const TOTAL_NUMBER_OF_CHAINS = TOTAL_NUMBER_OF_GROUPS * TOTAL_NUMBER_OF_GROUPS
|
|
20
21
|
export const MIN_UTXO_SET_AMOUNT = BigInt(1000000000000)
|
|
21
22
|
export const ALPH_TOKEN_ID = ''.padStart(64, '0')
|
|
22
23
|
export const ONE_ALPH = 10n ** 18n
|
package/src/utils/utils.ts
CHANGED
|
@@ -22,9 +22,10 @@ import blake from 'blakejs'
|
|
|
22
22
|
import bs58 from './bs58'
|
|
23
23
|
import { Buffer } from 'buffer/'
|
|
24
24
|
|
|
25
|
-
import { TOTAL_NUMBER_OF_GROUPS } from '../constants'
|
|
25
|
+
import { TOTAL_NUMBER_OF_GROUPS, TOTAL_NUMBER_OF_CHAINS } from '../constants'
|
|
26
26
|
import djb2 from './djb2'
|
|
27
27
|
import { KeyType } from '../signer'
|
|
28
|
+
import { HexString } from '../contract'
|
|
28
29
|
|
|
29
30
|
const ec = new EC('secp256k1')
|
|
30
31
|
|
|
@@ -215,6 +216,15 @@ export function subContractId(parentContractId: string, pathInHex: string, group
|
|
|
215
216
|
return binToHex(bytes)
|
|
216
217
|
}
|
|
217
218
|
|
|
219
|
+
export function blockChainIndex(blockHash: HexString): { fromGroup: number; toGroup: number } {
|
|
220
|
+
if (blockHash.length != 64) {
|
|
221
|
+
throw Error(`Invalid block hash: ${blockHash}`)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const rawIndex = Number('0x' + blockHash.slice(-4)) % TOTAL_NUMBER_OF_CHAINS
|
|
225
|
+
return { fromGroup: Math.floor(rawIndex / TOTAL_NUMBER_OF_GROUPS), toGroup: rawIndex % TOTAL_NUMBER_OF_GROUPS }
|
|
226
|
+
}
|
|
227
|
+
|
|
218
228
|
export function stringToHex(str: string): string {
|
|
219
229
|
let hex = ''
|
|
220
230
|
for (let i = 0; i < str.length; i++) {
|