Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(website): remove unnecessary webpack config #720

Merged
merged 7 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/angry-rabbits-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ckb-lumos/base": minor
---

**BREAKING CHANGE**: remove unused `isDeepEqual` function to reduce the package size
5 changes: 5 additions & 0 deletions .changeset/calm-crews-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ckb-lumos/common-scripts": minor
---

**BREAKING CHANGE**: default `generateDeployWithDataTx` to `data1` since `data2` is not active
5 changes: 5 additions & 0 deletions .changeset/green-pumpkins-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ckb-lumos/common-scripts": minor
---

**BREAKING CHANGE**: `createOmnilockScript` uses the `allows` option to restrict allowed btc addresses
6 changes: 6 additions & 0 deletions .changeset/lemon-tomatoes-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@ckb-lumos/common-scripts": minor
"@ckb-lumos/lumos": minor
---

feat: support eth displaying auth mode for omnilock
6 changes: 3 additions & 3 deletions packages/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@
"@types/blake2b": "^2.1.0",
"@types/lodash.isequal": "^4.5.5",
"blake2b": "^2.1.3",
"js-xxhash": "^1.0.4",
"lodash.isequal": "^4.5.0"
"js-xxhash": "^1.0.4"
},
"devDependencies": {
"jsbi": "^4.1.0"
"jsbi": "^4.1.0",
"lodash.isequal": "^4.5.0"
},
"publishConfig": {
"access": "public"
Expand Down
6 changes: 0 additions & 6 deletions packages/base/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import blake2b, { Blake2b } from "blake2b";
import isEqual from "lodash.isequal";
import { xxHash32 } from "js-xxhash";
import { bytes, number, BytesLike } from "@ckb-lumos/codec";
import { BI, BIish } from "@ckb-lumos/bi";
Expand Down Expand Up @@ -149,10 +148,6 @@ function assertHexadecimal(debugPath: string, str: string): void {
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
function isDeepEqual(a: any, b: any): boolean {
return isEqual(a, b);
}
// Buffer.from('TYPE_ID')
const TYPE_ID_CODE_HASH =
"0x00000000000000000000000000000000000000000000000000545950455f4944";
Expand Down Expand Up @@ -272,6 +267,5 @@ export {
hashCode,
assertHexString,
assertHexadecimal,
isDeepEqual,
generateTypeIdScript,
};
5 changes: 3 additions & 2 deletions packages/base/tests/since.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const test = require("ava");
const isEqual = require("lodash.isequal");
const { BI } = require("@ckb-lumos/bi");

const { since, utils } = require("../src");
const { since } = require("../src");

const {
parseSinceCompatible,
Expand Down Expand Up @@ -91,7 +92,7 @@ test.before(() => {
test("parsedSince", (t) => {
fixtrues.forEach((v) => {
const parsed = parseSinceCompatible(v.since);
t.true(utils.isDeepEqual(parsed, v.parsed));
t.true(isEqual(parsed, v.parsed));
});
});

Expand Down
3 changes: 2 additions & 1 deletion packages/common-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"@ckb-lumos/helpers": "0.23.0",
"@ckb-lumos/rpc": "0.23.0",
"@ckb-lumos/toolkit": "0.23.0",
"bs58": "^5.0.0",
"bech32": "^2.0.0",
"bs58": "^5.0.0",
"immutable": "^4.3.0"
},
"repository": {
Expand Down Expand Up @@ -59,6 +59,7 @@
"@ckb-lumos/crypto": "0.23.0",
"@ckb-lumos/debugger": "0.23.0",
"@ckb-lumos/hd": "0.23.0",
"@ethereumjs/util": "^9.0.3",
"@unisat/wallet-sdk": "^1.1.2",
"tweetnacl": "^1.0.3"
},
Expand Down
68 changes: 26 additions & 42 deletions packages/common-scripts/src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
blockchain,
} from "@ckb-lumos/base";
import { bytes } from "@ckb-lumos/codec";
import { getConfig, Config, helpers } from "@ckb-lumos/config-manager";
import {
getConfig,
Config,
helpers,
ScriptConfig,
} from "@ckb-lumos/config-manager";
import {
TransactionSkeletonType,
TransactionSkeleton,
Expand All @@ -21,18 +26,10 @@
} from "@ckb-lumos/helpers";
import { Set } from "immutable";
import { FromInfo, parseFromInfo, MultisigScript } from "./from_info";
import { BI, BIish } from "@ckb-lumos/bi";
import { BI, BIish, parseUnit } from "@ckb-lumos/bi";
import { RPC } from "@ckb-lumos/rpc";
const { ScriptValue } = values;

function bytesToHex(bytes: Uint8Array): string {
let res = "0x";
for (let i = 0; i < bytes.length; i++) {
res += bytes[i].toString(16).padStart(2, "0");
}
return res;
}

async function findCellsByLock(
lockScript: Script,
cellProvider: CellProvider
Expand Down Expand Up @@ -127,6 +124,8 @@
return txSkeleton;
}

const ONE_CKB = parseUnit("1", "ckb");

async function injectCapacity(
txSkeleton: TransactionSkeletonType,
fromInfo: FromInfo,
Expand All @@ -140,8 +139,8 @@
const _feeRate = feeRate || 1000;
let _amount = BI.from(amount);
const { fromScript, multisigScript } = parseFromInfo(fromInfo, { config });
_amount = _amount.add(BI.from(10).pow(8));
let changeCapacity = BI.from(10).pow(8);
_amount = _amount.add(ONE_CKB);
let changeCapacity = ONE_CKB;
const changeCell: Cell = {
cellOutput: {
capacity: "0x0",
Expand All @@ -152,7 +151,7 @@
};
const minimalChangeCapacity: BI = BI.from(
minimalCellCapacityCompatible(changeCell)
).add(BI.from(10).pow(8));
).add(ONE_CKB);

if (_amount.lt(0)) {
changeCapacity = changeCapacity.sub(_amount);
Expand All @@ -170,14 +169,14 @@
let previousInputs = Set<string>();
for (const input of txSkeleton.get("inputs")) {
previousInputs = previousInputs.add(
`${input.outPoint!.txHash}_${input.outPoint!.index}`

Check warning on line 172 in packages/common-scripts/src/deploy.ts

View workflow job for this annotation

GitHub Actions / lint-staged

Forbidden non-null assertion

Check warning on line 172 in packages/common-scripts/src/deploy.ts

View workflow job for this annotation

GitHub Actions / lint-staged

Forbidden non-null assertion

Check warning on line 172 in packages/common-scripts/src/deploy.ts

View workflow job for this annotation

GitHub Actions / lint-staged

Forbidden non-null assertion

Check warning on line 172 in packages/common-scripts/src/deploy.ts

View workflow job for this annotation

GitHub Actions / lint-staged

Forbidden non-null assertion
);
}

for await (const inputCell of cellCollector.collect()) {
if (
previousInputs.has(
`${inputCell.outPoint!.txHash}_${inputCell.outPoint!.index}`

Check warning on line 179 in packages/common-scripts/src/deploy.ts

View workflow job for this annotation

GitHub Actions / lint-staged

Forbidden non-null assertion

Check warning on line 179 in packages/common-scripts/src/deploy.ts

View workflow job for this annotation

GitHub Actions / lint-staged

Forbidden non-null assertion

Check warning on line 179 in packages/common-scripts/src/deploy.ts

View workflow job for this annotation

GitHub Actions / lint-staged

Forbidden non-null assertion

Check warning on line 179 in packages/common-scripts/src/deploy.ts

View workflow job for this annotation

GitHub Actions / lint-staged

Forbidden non-null assertion
)
)
continue;
Expand Down Expand Up @@ -229,19 +228,21 @@
witnesses.push("0x")
);
}
let witness: string = txSkeleton.get("witnesses").get(firstIndex)!;

Check warning on line 231 in packages/common-scripts/src/deploy.ts

View workflow job for this annotation

GitHub Actions / lint-staged

Forbidden non-null assertion

Check warning on line 231 in packages/common-scripts/src/deploy.ts

View workflow job for this annotation

GitHub Actions / lint-staged

Forbidden non-null assertion
let newWitnessArgs: WitnessArgs;
const SECP_SIGNATURE_PLACEHOLDER =
"0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";

if (typeof fromInfo !== "string") {
newWitnessArgs = {
lock:
"0x" +
multisigScript!.slice(2) +
SECP_SIGNATURE_PLACEHOLDER.slice(2).repeat(
(fromInfo as MultisigScript).M
),
lock: bytes.hexify(
bytes.concat(
multisigScript!,

Check warning on line 240 in packages/common-scripts/src/deploy.ts

View workflow job for this annotation

GitHub Actions / lint-staged

Forbidden non-null assertion

Check warning on line 240 in packages/common-scripts/src/deploy.ts

View workflow job for this annotation

GitHub Actions / lint-staged

Forbidden non-null assertion
...new Array((fromInfo as MultisigScript).M).fill(
SECP_SIGNATURE_PLACEHOLDER
)
)
),
};
} else {
newWitnessArgs = { lock: SECP_SIGNATURE_PLACEHOLDER };
Expand Down Expand Up @@ -298,7 +299,8 @@
function getTransactionSizeByTx(tx: Transaction): number {
const serializedTx = blockchain.Transaction.pack(tx);
// 4 is serialized offset bytesize
const size = serializedTx.byteLength + 4;
const MOLECULE_TABLE_OFFSET = 4;
const size = serializedTx.byteLength + MOLECULE_TABLE_OFFSET;
return size;
}

Expand Down Expand Up @@ -341,24 +343,6 @@
return new utils.CKBHasher().update(bytes.bytify(outputData)).digestHex();
}

interface ScriptConfig {
// if hashType is type, codeHash is ckbHash(type_script)
// if hashType is data, codeHash is ckbHash(data)
CODE_HASH: string;

HASH_TYPE: "type" | "data2";

TX_HASH: string;
// the deploy cell can be found at index of tx's outputs
INDEX: string;

// now deployWithX only supportted `code `
DEP_TYPE: "depGroup" | "code";

// empty
SHORT_ID?: number;
}

function calculateTxHash(txSkeleton: TransactionSkeletonType): string {
const tx = createTransactionFromSkeleton(txSkeleton);
const txHash = utils.ckbHash(blockchain.RawTransaction.pack(tx));
Expand All @@ -369,12 +353,12 @@
txSkeleton: TransactionSkeletonType,
outputIndex: number
): ScriptConfig {
const data = txSkeleton.outputs.get(outputIndex)!.data;

Check warning on line 356 in packages/common-scripts/src/deploy.ts

View workflow job for this annotation

GitHub Actions / lint-staged

Forbidden non-null assertion

Check warning on line 356 in packages/common-scripts/src/deploy.ts

View workflow job for this annotation

GitHub Actions / lint-staged

Forbidden non-null assertion
const codeHash = utils.ckbHash(bytes.bytify(data));
const txHash = calculateTxHash(txSkeleton);
const scriptConfig: ScriptConfig = {
CODE_HASH: codeHash,
HASH_TYPE: "data2",
HASH_TYPE: "data1",
TX_HASH: txHash,
INDEX: "0x0",
DEP_TYPE: "code",
Expand All @@ -386,7 +370,7 @@
txSkeleton: TransactionSkeletonType,
outputIndex: number
): ScriptConfig {
const typeScript = txSkeleton.outputs.get(outputIndex)!.cellOutput.type!;

Check warning on line 373 in packages/common-scripts/src/deploy.ts

View workflow job for this annotation

GitHub Actions / lint-staged

Forbidden non-null assertion

Check warning on line 373 in packages/common-scripts/src/deploy.ts

View workflow job for this annotation

GitHub Actions / lint-staged

Forbidden non-null assertion

Check warning on line 373 in packages/common-scripts/src/deploy.ts

View workflow job for this annotation

GitHub Actions / lint-staged

Forbidden non-null assertion

Check warning on line 373 in packages/common-scripts/src/deploy.ts

View workflow job for this annotation

GitHub Actions / lint-staged

Forbidden non-null assertion
const codeHash = utils.computeScriptHash(typeScript);
const txHash = calculateTxHash(txSkeleton);
const scriptConfig: ScriptConfig = {
Expand Down Expand Up @@ -485,7 +469,7 @@
capacity: "0x0",
lock: fromScript,
},
data: bytesToHex(options.scriptBinary),
data: bytes.hexify(options.scriptBinary),
};

txSkeleton = updateOutputs(txSkeleton, output);
Expand Down Expand Up @@ -526,7 +510,7 @@
if (!resolved) throw new Error(`fromAddress has no live ckb`);

const typeId = utils.generateTypeIdScript(
{ previousOutput: resolved.outPoint!, since: "0x0" },

Check warning on line 513 in packages/common-scripts/src/deploy.ts

View workflow job for this annotation

GitHub Actions / lint-staged

Forbidden non-null assertion

Check warning on line 513 in packages/common-scripts/src/deploy.ts

View workflow job for this annotation

GitHub Actions / lint-staged

Forbidden non-null assertion
"0x0"
);
const output: Cell = {
Expand All @@ -535,7 +519,7 @@
lock: fromScript,
type: typeId,
},
data: bytesToHex(options.scriptBinary),
data: bytes.hexify(options.scriptBinary),
};

txSkeleton = updateOutputs(txSkeleton, output);
Expand Down Expand Up @@ -584,7 +568,7 @@
lock: fromScript,
type: options.typeId,
},
data: bytesToHex(options.scriptBinary),
data: bytes.hexify(options.scriptBinary),
};

txSkeleton = updateOutputs(txSkeleton, output);
Expand Down
Loading
Loading