@ckb-ccc/uni-sat 0.0.3 → 0.0.4-alpha.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/signer.d.ts +3 -6
- package/dist/signer.d.ts.map +1 -1
- package/dist/signer.js +3 -29
- package/package.json +3 -4
- package/src/signer.ts +3 -56
package/dist/signer.d.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
2
|
import { Provider } from "./uni-sat.advanced";
|
|
3
|
-
export declare class Signer extends ccc.
|
|
3
|
+
export declare class Signer extends ccc.SignerBtc {
|
|
4
4
|
readonly provider: Provider;
|
|
5
5
|
constructor(client: ccc.Client, provider: Provider);
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
getInternalAddress(): Promise<string>;
|
|
9
|
-
getAddressObjs(): Promise<ccc.Address[]>;
|
|
6
|
+
getBtcAccount(): Promise<string>;
|
|
7
|
+
getBtcPublicKey(): Promise<ccc.Hex>;
|
|
10
8
|
connect(): Promise<void>;
|
|
11
9
|
signMessage(message: string | ccc.BytesLike): Promise<string>;
|
|
12
|
-
signOnlyTransaction(tx: ccc.Transaction): Promise<ccc.Transaction>;
|
|
13
10
|
}
|
|
14
11
|
//# sourceMappingURL=signer.d.ts.map
|
package/dist/signer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,qBAAa,MAAO,SAAQ,GAAG,CAAC,SAAS;aAGrB,QAAQ,EAAE,QAAQ;gBADlC,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,QAAQ,EAAE,QAAQ;IAK9B,aAAa;IAIb,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAInC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;CAMpE"}
|
package/dist/signer.js
CHANGED
|
@@ -1,27 +1,15 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
|
-
|
|
3
|
-
import { sha256 } from "@noble/hashes/sha256";
|
|
4
|
-
export class Signer extends ccc.Signer {
|
|
2
|
+
export class Signer extends ccc.SignerBtc {
|
|
5
3
|
constructor(client, provider) {
|
|
6
4
|
super(client);
|
|
7
5
|
this.provider = provider;
|
|
8
6
|
}
|
|
9
|
-
async
|
|
7
|
+
async getBtcAccount() {
|
|
10
8
|
return (await this.provider.getAccounts())[0];
|
|
11
9
|
}
|
|
12
|
-
async
|
|
10
|
+
async getBtcPublicKey() {
|
|
13
11
|
return ccc.hexFrom(await this.provider.getPublicKey());
|
|
14
12
|
}
|
|
15
|
-
async getInternalAddress() {
|
|
16
|
-
return this.getBTCAccount();
|
|
17
|
-
}
|
|
18
|
-
async getAddressObjs() {
|
|
19
|
-
const publicKey = await this.getBTCPublicKey();
|
|
20
|
-
const hash = ripemd160(sha256(ccc.bytesFrom(publicKey)));
|
|
21
|
-
return [
|
|
22
|
-
await ccc.Address.fromKnownScript(ccc.KnownScript.OmniLock, ccc.hexFrom([0x04, ...hash, 0x00]), this.client),
|
|
23
|
-
];
|
|
24
|
-
}
|
|
25
13
|
async connect() {
|
|
26
14
|
await this.provider.requestAccounts();
|
|
27
15
|
}
|
|
@@ -29,18 +17,4 @@ export class Signer extends ccc.Signer {
|
|
|
29
17
|
const challenge = typeof message === "string" ? message : ccc.hexFrom(message).slice(2);
|
|
30
18
|
return this.provider.signMessage(challenge, "ecdsa");
|
|
31
19
|
}
|
|
32
|
-
async signOnlyTransaction(tx) {
|
|
33
|
-
const { script } = await this.getRecommendedAddressObj();
|
|
34
|
-
const info = await ccc.getSignHashInfo(tx, script);
|
|
35
|
-
if (!info) {
|
|
36
|
-
return tx;
|
|
37
|
-
}
|
|
38
|
-
const signature = ccc.bytesFrom(await this.signMessage(`CKB (Bitcoin Layer) transaction: ${info.message}`), "base64");
|
|
39
|
-
signature[0] = 31 + ((signature[0] - 27) % 4);
|
|
40
|
-
console.log(ccc.hexFrom(signature));
|
|
41
|
-
const witness = ccc.WitnessArgs.fromBytes(tx.witnesses[info.position]);
|
|
42
|
-
witness.lock = ccc.hexFrom(ccc.bytesConcat(ccc.numToBytes(5 * 4 + signature.length, 4), ccc.numToBytes(4 * 4, 4), ccc.numToBytes(5 * 4 + signature.length, 4), ccc.numToBytes(5 * 4 + signature.length, 4), ccc.numToBytes(signature.length, 4), signature));
|
|
43
|
-
tx.witnesses[info.position] = ccc.hexFrom(witness.toBytes());
|
|
44
|
-
return tx;
|
|
45
|
-
}
|
|
46
20
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/uni-sat",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4-alpha.0",
|
|
4
4
|
"description": "Common Chains Connector's support for UniSat",
|
|
5
5
|
"author": "Hanssen0 <hanssen0@hanssen0.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,8 +35,7 @@
|
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@ckb-ccc/core": "0.0.
|
|
39
|
-
"@noble/hashes": "^1.4.0"
|
|
38
|
+
"@ckb-ccc/core": "0.0.4-alpha.0"
|
|
40
39
|
},
|
|
41
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "e49045ed4b2778c92d6f49b79c17125245141a21"
|
|
42
41
|
}
|
package/src/signer.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
|
-
import { ripemd160 } from "@noble/hashes/ripemd160";
|
|
3
|
-
import { sha256 } from "@noble/hashes/sha256";
|
|
4
2
|
import { Provider } from "./uni-sat.advanced";
|
|
5
3
|
|
|
6
|
-
export class Signer extends ccc.
|
|
4
|
+
export class Signer extends ccc.SignerBtc {
|
|
7
5
|
constructor(
|
|
8
6
|
client: ccc.Client,
|
|
9
7
|
public readonly provider: Provider,
|
|
@@ -11,31 +9,14 @@ export class Signer extends ccc.Signer {
|
|
|
11
9
|
super(client);
|
|
12
10
|
}
|
|
13
11
|
|
|
14
|
-
async
|
|
12
|
+
async getBtcAccount() {
|
|
15
13
|
return (await this.provider.getAccounts())[0];
|
|
16
14
|
}
|
|
17
15
|
|
|
18
|
-
async
|
|
16
|
+
async getBtcPublicKey(): Promise<ccc.Hex> {
|
|
19
17
|
return ccc.hexFrom(await this.provider.getPublicKey());
|
|
20
18
|
}
|
|
21
19
|
|
|
22
|
-
async getInternalAddress(): Promise<string> {
|
|
23
|
-
return this.getBTCAccount();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async getAddressObjs(): Promise<ccc.Address[]> {
|
|
27
|
-
const publicKey = await this.getBTCPublicKey();
|
|
28
|
-
const hash = ripemd160(sha256(ccc.bytesFrom(publicKey)));
|
|
29
|
-
|
|
30
|
-
return [
|
|
31
|
-
await ccc.Address.fromKnownScript(
|
|
32
|
-
ccc.KnownScript.OmniLock,
|
|
33
|
-
ccc.hexFrom([0x04, ...hash, 0x00]),
|
|
34
|
-
this.client,
|
|
35
|
-
),
|
|
36
|
-
];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
20
|
async connect(): Promise<void> {
|
|
40
21
|
await this.provider.requestAccounts();
|
|
41
22
|
}
|
|
@@ -46,38 +27,4 @@ export class Signer extends ccc.Signer {
|
|
|
46
27
|
|
|
47
28
|
return this.provider.signMessage(challenge, "ecdsa");
|
|
48
29
|
}
|
|
49
|
-
|
|
50
|
-
async signOnlyTransaction(tx: ccc.Transaction): Promise<ccc.Transaction> {
|
|
51
|
-
const { script } = await this.getRecommendedAddressObj();
|
|
52
|
-
const info = await ccc.getSignHashInfo(tx, script);
|
|
53
|
-
if (!info) {
|
|
54
|
-
return tx;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const signature = ccc.bytesFrom(
|
|
58
|
-
await this.signMessage(
|
|
59
|
-
`CKB (Bitcoin Layer) transaction: ${info.message}`,
|
|
60
|
-
),
|
|
61
|
-
"base64",
|
|
62
|
-
);
|
|
63
|
-
signature[0] = 31 + ((signature[0] - 27) % 4);
|
|
64
|
-
|
|
65
|
-
console.log(ccc.hexFrom(signature));
|
|
66
|
-
|
|
67
|
-
const witness = ccc.WitnessArgs.fromBytes(tx.witnesses[info.position]);
|
|
68
|
-
witness.lock = ccc.hexFrom(
|
|
69
|
-
ccc.bytesConcat(
|
|
70
|
-
ccc.numToBytes(5 * 4 + signature.length, 4),
|
|
71
|
-
ccc.numToBytes(4 * 4, 4),
|
|
72
|
-
ccc.numToBytes(5 * 4 + signature.length, 4),
|
|
73
|
-
ccc.numToBytes(5 * 4 + signature.length, 4),
|
|
74
|
-
ccc.numToBytes(signature.length, 4),
|
|
75
|
-
signature,
|
|
76
|
-
),
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
tx.witnesses[info.position] = ccc.hexFrom(witness.toBytes());
|
|
80
|
-
|
|
81
|
-
return tx;
|
|
82
|
-
}
|
|
83
30
|
}
|