New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ckb-lumos/helpers

Package Overview
Dependencies
Maintainers
3
Versions
199
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ckb-lumos/helpers - npm Package Compare versions

Comparing version 0.0.0-canary-6bb442c-20230724120406 to 0.0.0-canary-6e0d0e2-20240521064506

lib/refresh.d.ts

37

lib/address-to-script.js

@@ -9,5 +9,6 @@ "use strict";

exports.parseFullFormatAddress = parseFullFormatAddress;
var _base = require("@ckb-lumos/base");
var _codec = require("@ckb-lumos/codec");
var _configManager = require("@ckb-lumos/config-manager");
var _bech = require("bech32");
var _utils = require("./utils");
// https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md

@@ -26,3 +27,3 @@ // | format type | description |

*/
const ADDRESS_FORMAT_FULL = 0x00;
const ADDRESS_FORMAT_FULL = exports.ADDRESS_FORMAT_FULL = 0x00;
/**

@@ -32,4 +33,3 @@ * @deprecated

*/
exports.ADDRESS_FORMAT_FULL = ADDRESS_FORMAT_FULL;
const ADDRESS_FORMAT_SHORT = 0x01;
const ADDRESS_FORMAT_SHORT = exports.ADDRESS_FORMAT_SHORT = 0x01;

@@ -40,4 +40,3 @@ /**

*/
exports.ADDRESS_FORMAT_SHORT = ADDRESS_FORMAT_SHORT;
const ADDRESS_FORMAT_FULLDATA = 0x02;
const ADDRESS_FORMAT_FULLDATA = exports.ADDRESS_FORMAT_FULLDATA = 0x02;

@@ -48,5 +47,3 @@ /**

*/
exports.ADDRESS_FORMAT_FULLDATA = ADDRESS_FORMAT_FULLDATA;
const ADDRESS_FORMAT_FULLTYPE = 0x04;
exports.ADDRESS_FORMAT_FULLTYPE = ADDRESS_FORMAT_FULLTYPE;
const ADDRESS_FORMAT_FULLTYPE = exports.ADDRESS_FORMAT_FULLTYPE = 0x04;
function parseFullFormatAddress(address, {

@@ -73,11 +70,5 @@ config

}
const codeHash = (0, _utils.byteArrayToHex)(body.slice(0, 32));
const hashType = (() => {
const serializedHashType = body[32];
if (serializedHashType === 0) return "data";
if (serializedHashType === 1) return "type";
if (serializedHashType === 2) return "data1";
throw new Error(`Invalid hashType ${serializedHashType}`);
})();
const args = (0, _utils.byteArrayToHex)(body.slice(33));
const codeHash = _codec.bytes.hexify(body.slice(0, 32));
const hashType = _base.blockchain.HashType.unpack(body.slice(32, 33));
const args = _codec.bytes.hexify(body.slice(33));
return {

@@ -121,3 +112,3 @@ codeHash,

hashType: scriptTemplate.HASH_TYPE,
args: (0, _utils.byteArrayToHex)(argsBytes)
args: _codec.bytes.hexify(argsBytes)
};

@@ -132,5 +123,5 @@ }

return {
codeHash: (0, _utils.byteArrayToHex)(body.slice(0, 32)),
codeHash: _codec.bytes.hexify(body.slice(0, 32)),
hashType: "data",
args: (0, _utils.byteArrayToHex)(body.slice(32))
args: _codec.bytes.hexify(body.slice(32))
};

@@ -145,5 +136,5 @@ }

return {
codeHash: (0, _utils.byteArrayToHex)(body.slice(0, 32)),
codeHash: _codec.bytes.hexify(body.slice(0, 32)),
hashType: "type",
args: (0, _utils.byteArrayToHex)(body.slice(32))
args: _codec.bytes.hexify(body.slice(32))
};

@@ -150,0 +141,0 @@ }

@@ -123,3 +123,3 @@ import { Address, Cell, CellDep, CellProvider, Hash, HexString, PackedSince, Script, Transaction, OutPoint } from "@ckb-lumos/base";

export declare function objectToTransactionSkeleton(obj: TransactionSkeletonObject): TransactionSkeletonType;
export {};
export { refreshTypeIdCellDeps } from "./refresh";
//# sourceMappingURL=index.d.ts.map

@@ -21,2 +21,8 @@ "use strict";

exports.parseAddress = parseAddress;
Object.defineProperty(exports, "refreshTypeIdCellDeps", {
enumerable: true,
get: function () {
return _refresh.refreshTypeIdCellDeps;
}
});
exports.scriptToAddress = void 0;

@@ -34,2 +40,4 @@ exports.sealTransaction = sealTransaction;

var _toolkit = require("@ckb-lumos/toolkit");
var _blockchain = require("@ckb-lumos/base/lib/blockchain");
var _refresh = require("./refresh");
const {

@@ -48,2 +56,3 @@ bytify,

}
const ONE_CKB = 100_000_000;
function minimalScriptCapacityCompatible(script, {

@@ -60,3 +69,3 @@ validate = true

bytes += 1;
return _bi.BI.from(bytes).mul(100000000);
return _bi.BI.from(bytes).mul(ONE_CKB);
}

@@ -91,3 +100,3 @@ function minimalCellCapacity(fullCell, {

}
return _bi.BI.from(bytes).mul(100000000);
return _bi.BI.from(bytes).mul(ONE_CKB);
}

@@ -112,2 +121,12 @@ function locateCellDep(script, {

// |format type|description |
// |-----------|----------------------------------------------------------|
// |0x00 |full version identifies the hash_type |
// |0x01 |short version for locks with popular code_hash, deprecated|
// |0x02 |full version with hash_type = "Data", deprecated |
// |0x04 |full version with hash_type = "Type", deprecated |
const CKB2019_ADDRESS_FORMAT_TYPE_DATA = 0x02;
const CKB2019_ADDRESS_FORMAT_TYPE_TYPE = 0x04;
/**

@@ -134,3 +153,9 @@ * @deprecated please migrate to {@link encodeToAddress}, the short format address will be removed in the future

} else {
if (script.hashType === "type") data.push(0x04);else if (script.hashType === "data") data.push(0x02);else throw new Error(`Invalid hashType ${script.hashType}`);
if (script.hashType === "type") {
data.push(CKB2019_ADDRESS_FORMAT_TYPE_TYPE);
} else if (script.hashType === "data") {
data.push(CKB2019_ADDRESS_FORMAT_TYPE_DATA);
} else {
throw new Error(`Invalid hashType ${script.hashType}`);
}
data.push(...(0, _utils.hexToByteArray)(script.codeHash));

@@ -145,3 +170,3 @@ data.push(...(0, _utils.hexToByteArray)(script.args));

* @deprecated please migrate to {@link encodeToAddress}, the short format address will be removed in the future */
const scriptToAddress = generateAddress;
const scriptToAddress = exports.scriptToAddress = generateAddress;

@@ -155,3 +180,2 @@ /**

*/
exports.scriptToAddress = scriptToAddress;
function generatePredefinedAddress(args, scriptType, {

@@ -216,3 +240,3 @@ config = undefined

}
const addressToScript = parseAddress;
const addressToScript = exports.addressToScript = parseAddress;

@@ -224,3 +248,2 @@ /**

*/
exports.addressToScript = addressToScript;
function encodeToAddress(script, {

@@ -231,15 +254,7 @@ config = undefined

config = config || (0, _configManager.getConfig)();
const data = [];
const hashType = (() => {
if (script.hashType === "data") return 0;
if (script.hashType === "type") return 1;
if (script.hashType === "data1") return 2;
// https://github.com/nervosnetwork/rfcs/blob/9aef152a5123c8972de1aefc11794cf84d1762ed/rfcs/0021-ckb-address-format/0021-ckb-address-format.md#full-payload-format
// Full payload format directly encodes all data fields of lock script. The encode rule of full payload format is Bech32m.
// payload = 0x00 | code_hash | hash_type | args
/* c8 ignore next */
throw new Error(`Invalid hashType ${script.hashType}`);
})();
data.push(0x00);
data.push(...(0, _utils.hexToByteArray)(script.codeHash));
data.push(hashType);
data.push(...(0, _utils.hexToByteArray)(script.args));
const data = _codec.bytes.concat([0x00], script.codeHash, _blockchain.HashType.pack(script.hashType), script.args);
return _bech.bech32m.encode(config.PREFIX, _bech.bech32m.toWords(data), BECH32_LIMIT);

@@ -283,3 +298,3 @@ }

}
const TransactionSkeleton = (0, _immutable.Record)({
const TransactionSkeleton = exports.TransactionSkeleton = (0, _immutable.Record)({
cellProvider: null,

@@ -295,3 +310,2 @@ cellDeps: (0, _immutable.List)(),

});
exports.TransactionSkeleton = TransactionSkeleton;
function createTransactionFromSkeleton(txSkeleton, {

@@ -298,0 +312,0 @@ validate = true

import { HexString } from "@ckb-lumos/base";
export declare function hexToByteArray(h: HexString): number[];
export declare function byteArrayToHex(a: number[]): HexString;
//# sourceMappingURL=utils.d.ts.map

@@ -6,3 +6,2 @@ "use strict";

});
exports.byteArrayToHex = byteArrayToHex;
exports.hexToByteArray = hexToByteArray;

@@ -23,5 +22,2 @@ function hexToByteArray(h) {

}
function byteArrayToHex(a) {
return "0x" + a.map(i => ("00" + i.toString(16)).slice(-2)).join("");
}
//# sourceMappingURL=utils.js.map
{
"name": "@ckb-lumos/helpers",
"version": "0.0.0-canary-6bb442c-20230724120406",
"version": "0.0.0-canary-6e0d0e2-20240521064506",
"description": "Helper functions for working with CKB",

@@ -29,7 +29,7 @@ "author": "Xuejie Xiao <xxuejie@gmail.com>",

"dependencies": {
"@ckb-lumos/base": "0.0.0-canary-6bb442c-20230724120406",
"@ckb-lumos/bi": "0.0.0-canary-6bb442c-20230724120406",
"@ckb-lumos/codec": "0.0.0-canary-6bb442c-20230724120406",
"@ckb-lumos/config-manager": "0.0.0-canary-6bb442c-20230724120406",
"@ckb-lumos/toolkit": "0.0.0-canary-6bb442c-20230724120406",
"@ckb-lumos/base": "0.0.0-canary-6e0d0e2-20240521064506",
"@ckb-lumos/bi": "0.0.0-canary-6e0d0e2-20240521064506",
"@ckb-lumos/codec": "0.0.0-canary-6e0d0e2-20240521064506",
"@ckb-lumos/config-manager": "0.0.0-canary-6e0d0e2-20240521064506",
"@ckb-lumos/toolkit": "0.0.0-canary-6e0d0e2-20240521064506",
"bech32": "^2.0.0",

@@ -36,0 +36,0 @@ "immutable": "^4.3.0"

@@ -9,7 +9,7 @@ // https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md

import { Address, Script } from "@ckb-lumos/base";
import { Address, Script, blockchain } from "@ckb-lumos/base";
import { bytes } from "@ckb-lumos/codec";
import { getConfig } from "@ckb-lumos/config-manager";
import { bech32, bech32m } from "bech32";
import { Options } from "./";
import { byteArrayToHex } from "./utils";

@@ -66,14 +66,6 @@ const BECH32_LIMIT = 1023;

const codeHash = byteArrayToHex(body.slice(0, 32));
const hashType = (() => {
const serializedHashType = body[32];
const codeHash = bytes.hexify(body.slice(0, 32));
const hashType = blockchain.HashType.unpack(body.slice(32, 33));
const args = bytes.hexify(body.slice(33));
if (serializedHashType === 0) return "data";
if (serializedHashType === 1) return "type";
if (serializedHashType === 2) return "data1";
throw new Error(`Invalid hashType ${serializedHashType}`);
})();
const args = byteArrayToHex(body.slice(33));
return { codeHash, hashType, args };

@@ -117,3 +109,3 @@ }

hashType: scriptTemplate.HASH_TYPE,
args: byteArrayToHex(argsBytes),
args: bytes.hexify(argsBytes),
};

@@ -127,5 +119,5 @@ }

return {
codeHash: byteArrayToHex(body.slice(0, 32)),
codeHash: bytes.hexify(body.slice(0, 32)),
hashType: "data",
args: byteArrayToHex(body.slice(32)),
args: bytes.hexify(body.slice(32)),
};

@@ -139,5 +131,5 @@ }

return {
codeHash: byteArrayToHex(body.slice(0, 32)),
codeHash: bytes.hexify(body.slice(0, 32)),
hashType: "type",
args: byteArrayToHex(body.slice(32)),
args: bytes.hexify(body.slice(32)),
};

@@ -144,0 +136,0 @@ }

@@ -26,2 +26,3 @@ import { bytes } from "@ckb-lumos/codec";

import { validators } from "@ckb-lumos/toolkit";
import { HashType } from "@ckb-lumos/base/lib/blockchain";

@@ -43,2 +44,4 @@ const { bytify, hexify } = bytes;

const ONE_CKB = 100_000_000;
export function minimalScriptCapacityCompatible(

@@ -58,3 +61,3 @@ script: Script,

return BI.from(bytes).mul(100000000);
return BI.from(bytes).mul(ONE_CKB);
}

@@ -91,3 +94,3 @@

}
return BI.from(bytes).mul(100000000);
return BI.from(bytes).mul(ONE_CKB);
}

@@ -119,2 +122,12 @@

// |format type|description |
// |-----------|----------------------------------------------------------|
// |0x00 |full version identifies the hash_type |
// |0x01 |short version for locks with popular code_hash, deprecated|
// |0x02 |full version with hash_type = "Data", deprecated |
// |0x04 |full version with hash_type = "Type", deprecated |
const CKB2019_ADDRESS_FORMAT_TYPE_DATA = 0x02;
const CKB2019_ADDRESS_FORMAT_TYPE_TYPE = 0x04;
/**

@@ -148,5 +161,9 @@ * @deprecated please migrate to {@link encodeToAddress}, the short format address will be removed in the future

} else {
if (script.hashType === "type") data.push(0x04);
else if (script.hashType === "data") data.push(0x02);
else throw new Error(`Invalid hashType ${script.hashType}`);
if (script.hashType === "type") {
data.push(CKB2019_ADDRESS_FORMAT_TYPE_TYPE);
} else if (script.hashType === "data") {
data.push(CKB2019_ADDRESS_FORMAT_TYPE_DATA);
} else {
throw new Error(`Invalid hashType ${script.hashType}`);
}

@@ -246,19 +263,13 @@ data.push(...hexToByteArray(script.codeHash));

config = config || getConfig();
// https://github.com/nervosnetwork/rfcs/blob/9aef152a5123c8972de1aefc11794cf84d1762ed/rfcs/0021-ckb-address-format/0021-ckb-address-format.md#full-payload-format
// Full payload format directly encodes all data fields of lock script. The encode rule of full payload format is Bech32m.
// payload = 0x00 | code_hash | hash_type | args
const data: number[] = [];
const data = bytes.concat(
[0x00],
script.codeHash,
HashType.pack(script.hashType),
script.args
);
const hashType = (() => {
if (script.hashType === "data") return 0;
if (script.hashType === "type") return 1;
if (script.hashType === "data1") return 2;
/* c8 ignore next */
throw new Error(`Invalid hashType ${script.hashType}`);
})();
data.push(0x00);
data.push(...hexToByteArray(script.codeHash));
data.push(hashType);
data.push(...hexToByteArray(script.args));
return bech32m.encode(config.PREFIX, bech32m.toWords(data), BECH32_LIMIT);

@@ -529,1 +540,3 @@ }

}
export { refreshTypeIdCellDeps } from "./refresh";

@@ -17,5 +17,1 @@ import { HexString } from "@ckb-lumos/base";

}
export function byteArrayToHex(a: number[]): HexString {
return "0x" + a.map((i) => ("00" + i.toString(16)).slice(-2)).join("");
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc