@ckb-ccc/core 2.0.0-next.0 → 2.0.0-next.1
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/CHANGELOG.md +133 -1
- package/README.md +3 -3
- package/dist/advanced.d.mts +2 -2
- package/dist/advanced.mjs +1 -1
- package/{dist.commonjs/advancedBarrel-DNdhwiU0.d.ts → dist/advancedBarrel-DfFMFhdl.d.mts} +2790 -2237
- package/dist/advancedBarrel-DfFMFhdl.d.mts.map +1 -0
- package/dist/advancedBarrel.d.mts +2 -2
- package/dist/advancedBarrel.mjs +1 -1
- package/dist/advancedBarrel.mjs.map +1 -1
- package/dist/barrel-ONYEMVg5.mjs +7 -0
- package/dist/barrel-ONYEMVg5.mjs.map +1 -0
- package/dist/barrel.d.mts +2 -2
- package/dist/barrel.mjs +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/transformers-CduZ1Js5.mjs +2 -0
- package/dist/transformers-CduZ1Js5.mjs.map +1 -0
- package/dist.commonjs/advanced.d.ts +2 -2
- package/dist.commonjs/advanced.js +1 -1
- package/{dist/advancedBarrel-BHwnMJqR.d.mts → dist.commonjs/advancedBarrel-Dl0mM9JO.d.ts} +2791 -2236
- package/dist.commonjs/advancedBarrel-Dl0mM9JO.d.ts.map +1 -0
- package/dist.commonjs/advancedBarrel.d.ts +2 -2
- package/dist.commonjs/advancedBarrel.js +1 -1
- package/dist.commonjs/advancedBarrel.js.map +1 -1
- package/dist.commonjs/barrel-HfgYMxP_.js +23 -0
- package/dist.commonjs/barrel-HfgYMxP_.js.map +1 -0
- package/dist.commonjs/barrel.d.ts +2 -2
- package/dist.commonjs/barrel.js +1 -1
- package/dist.commonjs/index.d.ts +2 -2
- package/dist.commonjs/index.js +1 -1
- package/dist.commonjs/{rolldown-runtime-DWNI8pZO.js → rolldown-runtime-Chgba0Kb.js} +1 -1
- package/dist.commonjs/transformers-BUlLwiyt.js +2 -0
- package/dist.commonjs/transformers-BUlLwiyt.js.map +1 -0
- package/package.json +8 -7
- package/src/advancedBarrel.ts +1 -0
- package/src/bytes/advanced.ts +1 -6
- package/src/bytes/index.ts +37 -10
- package/src/ckb/transaction.ts +7 -5
- package/src/client/client.ts +83 -21
- package/src/client/clientPublicMainnet.advanced.ts +9 -0
- package/src/client/clientPublicMainnet.ts +75 -36
- package/src/client/clientPublicTestnet.advanced.ts +9 -0
- package/src/client/clientPublicTestnet.ts +75 -36
- package/src/client/jsonRpc/client.ts +77 -30
- package/src/client/jsonRpc/transformers.ts +4 -4
- package/src/jsonRpc/index.ts +1 -0
- package/src/jsonRpc/requestor.ts +106 -29
- package/src/jsonRpc/transports/advanced.ts +0 -4
- package/src/jsonRpc/transports/factory.ts +12 -5
- package/src/jsonRpc/transports/fallback.ts +14 -6
- package/src/jsonRpc/transports/http.ts +19 -12
- package/src/jsonRpc/transports/index.ts +4 -0
- package/src/jsonRpc/transports/transport.ts +42 -6
- package/src/jsonRpc/transports/webSocket.ts +145 -40
- package/src/keystore/index.ts +3 -3
- package/src/molecule/codec.ts +20 -17
- package/src/signer/advanced.ts +1 -0
- package/src/signer/btc/psbt.ts +4 -2
- package/src/signer/btc/verify.ts +2 -2
- package/src/signer/ckb/secp256k1Signing.ts +3 -3
- package/src/signer/doge/signerDoge.ts +1 -1
- package/src/signer/doge/signerDogePrivateKey.ts +1 -1
- package/src/signer/index.ts +1 -0
- package/src/signer/jsonRpc/handler.ts +478 -0
- package/src/signer/jsonRpc/index.ts +2 -0
- package/src/signer/jsonRpc/network.ts +15 -0
- package/src/signer/jsonRpc/signer.ts +378 -0
- package/src/signer/jsonRpc/transformers.ts +71 -0
- package/src/signer/signer/index.ts +5 -13
- package/src/utils/abortSignal.ts +56 -0
- package/src/utils/constructor.ts +11 -0
- package/src/utils/index.ts +172 -5
- package/src/utils/owner/aggregated.ts +56 -0
- package/src/utils/owner/index.ts +4 -0
- package/src/utils/owner/owner.ts +141 -0
- package/src/utils/owner/refCount.ts +78 -0
- package/src/utils/owner/unique.ts +30 -0
- package/src/utils/proxy.ts +165 -0
- package/tsdown.config.mts +1 -0
- package/dist/address.advanced-LxntWbev.mjs +0 -2
- package/dist/address.advanced-LxntWbev.mjs.map +0 -1
- package/dist/advancedBarrel-BHwnMJqR.d.mts.map +0 -1
- package/dist/barrel-C-BaV9Pe.mjs +0 -7
- package/dist/barrel-C-BaV9Pe.mjs.map +0 -1
- package/dist.commonjs/address.advanced-BqcYOpZn.js +0 -2
- package/dist.commonjs/address.advanced-BqcYOpZn.js.map +0 -1
- package/dist.commonjs/advancedBarrel-DNdhwiU0.d.ts.map +0 -1
- package/dist.commonjs/barrel-BBOmj4RJ.js +0 -21
- package/dist.commonjs/barrel-BBOmj4RJ.js.map +0 -1
|
@@ -1,63 +1,108 @@
|
|
|
1
1
|
import WebSocket from "isomorphic-ws";
|
|
2
|
-
import {
|
|
2
|
+
import { OwnerUnique } from "../../utils/owner/unique.js";
|
|
3
|
+
import {
|
|
4
|
+
JsonRpcId,
|
|
5
|
+
JsonRpcPayload,
|
|
6
|
+
JsonRpcResponse,
|
|
7
|
+
JsonRpcTransport,
|
|
8
|
+
JsonRpcTransportRequestOptions,
|
|
9
|
+
} from "./transport.js";
|
|
3
10
|
|
|
4
|
-
|
|
11
|
+
const SOCKET_TIMEOUT_GRACE_PERIOD = 10_000;
|
|
12
|
+
|
|
13
|
+
export class JsonRpcTransportWebSocket implements JsonRpcTransport {
|
|
5
14
|
private ongoing: Map<
|
|
6
|
-
|
|
15
|
+
JsonRpcId,
|
|
7
16
|
[
|
|
8
|
-
(response:
|
|
17
|
+
(response: JsonRpcResponse) => unknown,
|
|
9
18
|
(error: unknown) => unknown,
|
|
10
|
-
|
|
19
|
+
WebSocket,
|
|
11
20
|
]
|
|
12
21
|
> = new Map();
|
|
22
|
+
private firstTimeout?: { socket: WebSocket; at: number };
|
|
23
|
+
private disposed = false;
|
|
13
24
|
private socket?: WebSocket;
|
|
14
25
|
private openSocket?: Promise<WebSocket>;
|
|
15
26
|
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated Use {@link JsonRpcTransportWebSocket.open} to make lifecycle
|
|
29
|
+
* ownership explicit. This constructor will become private in a future
|
|
30
|
+
* release.
|
|
31
|
+
*/
|
|
16
32
|
constructor(
|
|
17
33
|
private readonly url: string,
|
|
18
34
|
private readonly timeout = 30000,
|
|
19
35
|
) {}
|
|
20
36
|
|
|
21
|
-
|
|
22
|
-
|
|
37
|
+
/** Opens an owned WebSocket transport. */
|
|
38
|
+
static open(
|
|
39
|
+
url: string,
|
|
40
|
+
timeout = 30000,
|
|
41
|
+
): OwnerUnique<JsonRpcTransportWebSocket> {
|
|
42
|
+
const transport = new JsonRpcTransportWebSocket(url, timeout);
|
|
43
|
+
return new OwnerUnique(transport, (transport) => transport.dispose());
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
request(
|
|
47
|
+
data: JsonRpcPayload,
|
|
48
|
+
options?: JsonRpcTransportRequestOptions,
|
|
49
|
+
): Promise<JsonRpcResponse> {
|
|
50
|
+
if (this.disposed) {
|
|
51
|
+
return Promise.reject(
|
|
52
|
+
new Error("Cannot use a disposed JsonRpcTransportWebSocket"),
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
if (options?.signal?.aborted) {
|
|
56
|
+
return Promise.reject(
|
|
57
|
+
options.signal.reason ?? new Error("Request aborted"),
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const [socketUnsafe, socket] = (() => {
|
|
23
62
|
if (
|
|
24
63
|
this.socket &&
|
|
25
64
|
this.socket.readyState !== this.socket.CLOSING &&
|
|
26
65
|
this.socket.readyState !== this.socket.CLOSED &&
|
|
27
66
|
this.openSocket
|
|
28
67
|
) {
|
|
29
|
-
return this.openSocket;
|
|
68
|
+
return [this.socket, this.openSocket] as const;
|
|
30
69
|
}
|
|
31
70
|
const socket = new WebSocket(this.url);
|
|
32
71
|
const onMessage = ({ data }: WebSocket.MessageEvent) => {
|
|
33
|
-
|
|
34
|
-
|
|
72
|
+
let res: JsonRpcResponse;
|
|
73
|
+
try {
|
|
74
|
+
res = JSON.parse(data as string) as JsonRpcResponse;
|
|
75
|
+
} catch (_) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
35
78
|
if (
|
|
36
79
|
typeof res !== "object" ||
|
|
37
80
|
res === null ||
|
|
38
|
-
typeof res.id !== "number"
|
|
81
|
+
(typeof res.id !== "number" && typeof res.id !== "string")
|
|
39
82
|
) {
|
|
40
|
-
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const id = res.id;
|
|
86
|
+
if (this.firstTimeout?.socket === socket) {
|
|
87
|
+
this.firstTimeout = undefined;
|
|
41
88
|
}
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
43
|
-
const id: number = res.id;
|
|
44
89
|
|
|
45
90
|
const req = this.ongoing.get(id);
|
|
46
|
-
if (!req) {
|
|
91
|
+
if (!req || req[2] !== socket) {
|
|
47
92
|
return;
|
|
48
93
|
}
|
|
49
|
-
const [resolve
|
|
50
|
-
clearTimeout(timeout);
|
|
51
|
-
this.ongoing.delete(id);
|
|
52
|
-
|
|
94
|
+
const [resolve] = req;
|
|
53
95
|
resolve(res);
|
|
54
96
|
};
|
|
55
97
|
const onClose = () => {
|
|
56
|
-
this.
|
|
57
|
-
|
|
58
|
-
|
|
98
|
+
if (this.firstTimeout?.socket === socket) {
|
|
99
|
+
this.firstTimeout = undefined;
|
|
100
|
+
}
|
|
101
|
+
this.ongoing.forEach(([_, reject, requestSocket]) => {
|
|
102
|
+
if (requestSocket === socket) {
|
|
103
|
+
reject(new Error("Connection closed"));
|
|
104
|
+
}
|
|
59
105
|
});
|
|
60
|
-
this.ongoing.clear();
|
|
61
106
|
};
|
|
62
107
|
|
|
63
108
|
socket.onclose = onClose;
|
|
@@ -74,41 +119,101 @@ export class TransportWebSocket implements Transport {
|
|
|
74
119
|
};
|
|
75
120
|
}
|
|
76
121
|
});
|
|
77
|
-
return this.openSocket;
|
|
122
|
+
return [socket, this.openSocket] as const;
|
|
78
123
|
})();
|
|
79
124
|
|
|
80
|
-
return new Promise((resolve, reject) => {
|
|
125
|
+
return new Promise<JsonRpcResponse>((resolve, reject) => {
|
|
126
|
+
const abortSignal = options?.signal;
|
|
127
|
+
let timeout: ReturnType<typeof setTimeout>;
|
|
81
128
|
const req: [
|
|
82
|
-
(res:
|
|
129
|
+
(res: JsonRpcResponse) => unknown,
|
|
83
130
|
(err: unknown) => unknown,
|
|
84
|
-
|
|
131
|
+
WebSocket,
|
|
85
132
|
] = [
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
133
|
+
(response) => {
|
|
134
|
+
if (cleanup()) {
|
|
135
|
+
resolve(response);
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
(error) => {
|
|
139
|
+
if (cleanup()) {
|
|
140
|
+
reject(error);
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
socketUnsafe,
|
|
95
144
|
];
|
|
145
|
+
const cleanup = () => {
|
|
146
|
+
if (this.ongoing.get(data.id) !== req) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
this.ongoing.delete(data.id);
|
|
150
|
+
clearTimeout(timeout);
|
|
151
|
+
abortSignal?.removeEventListener("abort", onAbort);
|
|
152
|
+
return true;
|
|
153
|
+
};
|
|
154
|
+
const onAbort = () => {
|
|
155
|
+
req[1](abortSignal?.reason ?? new Error("Request aborted"));
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
timeout = setTimeout(() => {
|
|
159
|
+
if (this.ongoing.get(data.id) === req) {
|
|
160
|
+
req[1](new Error("Request timeout"));
|
|
161
|
+
const hasPending = [...this.ongoing.values()].some(
|
|
162
|
+
([, , requestSocket]) => requestSocket === socketUnsafe,
|
|
163
|
+
);
|
|
164
|
+
if (!hasPending) {
|
|
165
|
+
socketUnsafe.close();
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const firstTimeout = this.firstTimeout;
|
|
170
|
+
if (firstTimeout?.socket !== socketUnsafe) {
|
|
171
|
+
this.firstTimeout = { socket: socketUnsafe, at: Date.now() };
|
|
172
|
+
} else if (
|
|
173
|
+
Date.now() - firstTimeout.at >=
|
|
174
|
+
SOCKET_TIMEOUT_GRACE_PERIOD
|
|
175
|
+
) {
|
|
176
|
+
socketUnsafe.close();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}, options?.timeout ?? this.timeout);
|
|
96
180
|
this.ongoing.set(data.id, req);
|
|
97
181
|
|
|
182
|
+
abortSignal?.addEventListener("abort", onAbort, { once: true });
|
|
183
|
+
if (abortSignal?.aborted) {
|
|
184
|
+
onAbort();
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
98
188
|
void socket
|
|
99
189
|
.then((socket) => {
|
|
190
|
+
if (this.ongoing.get(data.id) !== req) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
100
193
|
if (
|
|
101
194
|
socket.readyState === socket.CLOSED ||
|
|
102
195
|
socket.readyState === socket.CLOSING
|
|
103
196
|
) {
|
|
104
|
-
|
|
105
|
-
this.ongoing.delete(data.id);
|
|
106
|
-
reject(new Error("Connection closed"));
|
|
197
|
+
req[1](new Error("Connection closed"));
|
|
107
198
|
} else {
|
|
108
199
|
socket.send(JSON.stringify(data));
|
|
109
200
|
}
|
|
110
201
|
})
|
|
111
|
-
.catch((err) =>
|
|
202
|
+
.catch((err) => {
|
|
203
|
+
req[1](err);
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
private async dispose(): Promise<void> {
|
|
209
|
+
this.disposed = true;
|
|
210
|
+
const socket = this.socket;
|
|
211
|
+
|
|
212
|
+
if (!socket || socket.readyState === socket.CLOSED) return;
|
|
213
|
+
|
|
214
|
+
await new Promise<void>((resolve) => {
|
|
215
|
+
socket.addEventListener("close", () => resolve(), { once: true });
|
|
216
|
+
socket.close();
|
|
112
217
|
});
|
|
113
218
|
}
|
|
114
219
|
}
|
package/src/keystore/index.ts
CHANGED
|
@@ -14,7 +14,7 @@ const DEFAULT_SCRYPT_PARAM_N = 262144;
|
|
|
14
14
|
|
|
15
15
|
function mac(derivedKey: Bytes, cipherText: Bytes) {
|
|
16
16
|
return hexFrom(
|
|
17
|
-
keccak_256(bytesConcat(derivedKey.
|
|
17
|
+
keccak_256(bytesConcat(derivedKey.subarray(16, 32), cipherText)),
|
|
18
18
|
).slice(2);
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -60,7 +60,7 @@ export async function keystoreEncrypt(
|
|
|
60
60
|
dkLen: kdfparams.dklen,
|
|
61
61
|
});
|
|
62
62
|
const cipher = ctr(
|
|
63
|
-
derivedKey.
|
|
63
|
+
derivedKey.subarray(0, 16),
|
|
64
64
|
iv.map((v) => v),
|
|
65
65
|
);
|
|
66
66
|
const ciphertext = cipher.encrypt(
|
|
@@ -151,7 +151,7 @@ export async function keystoreDecrypt(
|
|
|
151
151
|
throw Error("Invalid password");
|
|
152
152
|
}
|
|
153
153
|
const cipher = ctr(
|
|
154
|
-
derivedKey.
|
|
154
|
+
derivedKey.subarray(0, 16),
|
|
155
155
|
bytesFrom(crypto.cipherparams.iv),
|
|
156
156
|
);
|
|
157
157
|
const result = cipher.decrypt(ciphertext);
|
package/src/molecule/codec.ts
CHANGED
|
@@ -86,7 +86,7 @@ export function fixedItemVec<Encodable, Decoded>(
|
|
|
86
86
|
`fixedItemVec: too short buffer, expected at least 4 bytes, but got ${value.byteLength}`,
|
|
87
87
|
);
|
|
88
88
|
}
|
|
89
|
-
const itemCount = uint32From(value.
|
|
89
|
+
const itemCount = uint32From(value.subarray(0, 4));
|
|
90
90
|
const byteLength = 4 + itemCount * itemByteLength;
|
|
91
91
|
if (value.byteLength !== byteLength) {
|
|
92
92
|
throw new Error(
|
|
@@ -99,7 +99,7 @@ export function fixedItemVec<Encodable, Decoded>(
|
|
|
99
99
|
for (let offset = 4; offset < byteLength; offset += itemByteLength) {
|
|
100
100
|
decodedArray.push(
|
|
101
101
|
itemCodec.decode(
|
|
102
|
-
value.
|
|
102
|
+
value.subarray(offset, offset + itemByteLength),
|
|
103
103
|
config,
|
|
104
104
|
),
|
|
105
105
|
);
|
|
@@ -155,7 +155,7 @@ export function dynItemVec<Encodable, Decoded>(
|
|
|
155
155
|
`dynItemVec: too short buffer, expected at least 4 bytes, but got ${value.byteLength}`,
|
|
156
156
|
);
|
|
157
157
|
}
|
|
158
|
-
const byteLength = uint32From(value.
|
|
158
|
+
const byteLength = uint32From(value.subarray(0, 4));
|
|
159
159
|
if (byteLength !== value.byteLength) {
|
|
160
160
|
throw new Error(
|
|
161
161
|
`dynItemVec: invalid buffer size, expected ${byteLength}, but got ${value.byteLength}`,
|
|
@@ -166,10 +166,10 @@ export function dynItemVec<Encodable, Decoded>(
|
|
|
166
166
|
return [];
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
const offset = uint32From(value.
|
|
169
|
+
const offset = uint32From(value.subarray(4, 8));
|
|
170
170
|
const itemCount = (offset - 4) / 4;
|
|
171
171
|
const offsets = Array.from(new Array(itemCount), (_, index) =>
|
|
172
|
-
uint32From(value.
|
|
172
|
+
uint32From(value.subarray(4 + index * 4, 8 + index * 4)),
|
|
173
173
|
);
|
|
174
174
|
offsets.push(byteLength);
|
|
175
175
|
try {
|
|
@@ -177,7 +177,7 @@ export function dynItemVec<Encodable, Decoded>(
|
|
|
177
177
|
for (let index = 0; index < offsets.length - 1; index++) {
|
|
178
178
|
const start = offsets[index];
|
|
179
179
|
const end = offsets[index + 1];
|
|
180
|
-
const itemBuffer = value.
|
|
180
|
+
const itemBuffer = value.subarray(start, end);
|
|
181
181
|
decodedArray.push(itemCodec.decode(itemBuffer, config));
|
|
182
182
|
}
|
|
183
183
|
return decodedArray;
|
|
@@ -281,14 +281,14 @@ export function byteVec<Encodable, Decoded>(
|
|
|
281
281
|
`byteVec: too short buffer, expected at least 4 bytes, but got ${value.byteLength}`,
|
|
282
282
|
);
|
|
283
283
|
}
|
|
284
|
-
const byteLength = uint32From(value.
|
|
284
|
+
const byteLength = uint32From(value.subarray(0, 4));
|
|
285
285
|
if (byteLength !== value.byteLength - 4) {
|
|
286
286
|
throw new Error(
|
|
287
287
|
`byteVec: invalid buffer size, expected ${byteLength}, but got ${value.byteLength}`,
|
|
288
288
|
);
|
|
289
289
|
}
|
|
290
290
|
try {
|
|
291
|
-
return codec.decode(value.
|
|
291
|
+
return codec.decode(value.subarray(4), config);
|
|
292
292
|
} catch (e: unknown) {
|
|
293
293
|
throw new Error(`byteVec - ${getMessage(e)}`, { cause: e });
|
|
294
294
|
}
|
|
@@ -375,8 +375,8 @@ export function table<
|
|
|
375
375
|
`table: too short buffer, expected at least 4 bytes, but got ${value.byteLength}`,
|
|
376
376
|
);
|
|
377
377
|
}
|
|
378
|
-
const byteLength = uint32From(value.
|
|
379
|
-
const headerLength = uint32From(value.
|
|
378
|
+
const byteLength = uint32From(value.subarray(0, 4));
|
|
379
|
+
const headerLength = uint32From(value.subarray(4, 8));
|
|
380
380
|
const actualFieldCount = (headerLength - 4) / 4;
|
|
381
381
|
|
|
382
382
|
if (byteLength !== value.byteLength) {
|
|
@@ -397,12 +397,12 @@ export function table<
|
|
|
397
397
|
);
|
|
398
398
|
}
|
|
399
399
|
const offsets = keys.map((_, index) =>
|
|
400
|
-
uint32From(value.
|
|
400
|
+
uint32From(value.subarray(4 + index * 4, 8 + index * 4)),
|
|
401
401
|
);
|
|
402
402
|
// If there are extra fields, add the last offset to the offsets array
|
|
403
403
|
if (actualFieldCount > keys.length) {
|
|
404
404
|
offsets.push(
|
|
405
|
-
uint32From(value.
|
|
405
|
+
uint32From(value.subarray(4 + keys.length * 4, 8 + keys.length * 4)),
|
|
406
406
|
);
|
|
407
407
|
} else {
|
|
408
408
|
// If there are no extra fields, add the byte length to the offsets array
|
|
@@ -414,7 +414,7 @@ export function table<
|
|
|
414
414
|
const end = offsets[i + 1];
|
|
415
415
|
const field = keys[i];
|
|
416
416
|
const codec = codecLayout[field];
|
|
417
|
-
const payload = value.
|
|
417
|
+
const payload = value.subarray(start, end);
|
|
418
418
|
try {
|
|
419
419
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
420
420
|
Object.assign(object, { [field]: codec.decode(payload, config) });
|
|
@@ -563,7 +563,7 @@ export function union<T extends Record<string, CodecLike<any, any>>>(
|
|
|
563
563
|
},
|
|
564
564
|
decode(buffer, config) {
|
|
565
565
|
const value = bytesFrom(buffer);
|
|
566
|
-
const fieldIndex = uint32From(value.
|
|
566
|
+
const fieldIndex = uint32From(value.subarray(0, 4));
|
|
567
567
|
const keys = Object.keys(codecLayout);
|
|
568
568
|
|
|
569
569
|
const field = (() => {
|
|
@@ -591,7 +591,7 @@ export function union<T extends Record<string, CodecLike<any, any>>>(
|
|
|
591
591
|
return {
|
|
592
592
|
type: field,
|
|
593
593
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
594
|
-
value: codecLayout[field].decode(value.
|
|
594
|
+
value: codecLayout[field].decode(value.subarray(4), config),
|
|
595
595
|
} as UnionDecoded<T>;
|
|
596
596
|
},
|
|
597
597
|
from(encodable) {
|
|
@@ -660,7 +660,7 @@ export function struct<
|
|
|
660
660
|
const object = {};
|
|
661
661
|
let offset = 0;
|
|
662
662
|
Object.entries(codecLayout).forEach(([key, codec]) => {
|
|
663
|
-
const payload = value.
|
|
663
|
+
const payload = value.subarray(offset, offset + codec.byteLength!);
|
|
664
664
|
try {
|
|
665
665
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
666
666
|
Object.assign(object, { [key]: codec.decode(payload, config) });
|
|
@@ -728,7 +728,10 @@ export function array<Encodable, Decoded>(
|
|
|
728
728
|
const result: Array<Decoded> = [];
|
|
729
729
|
for (let i = 0; i < value.byteLength; i += itemCodec.byteLength!) {
|
|
730
730
|
result.push(
|
|
731
|
-
itemCodec.decode(
|
|
731
|
+
itemCodec.decode(
|
|
732
|
+
value.subarray(i, i + itemCodec.byteLength!),
|
|
733
|
+
config,
|
|
734
|
+
),
|
|
732
735
|
);
|
|
733
736
|
}
|
|
734
737
|
return result;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./jsonRpc/transformers.js";
|
package/src/signer/btc/psbt.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { Hex, HexLike, hexFrom } from "../../hex/index.js";
|
|
|
5
5
|
*/
|
|
6
6
|
export type SignPsbtOptionsLike = {
|
|
7
7
|
/**
|
|
8
|
-
* Whether to finalize the
|
|
8
|
+
* Whether to attempt to finalize the signed inputs after signing.
|
|
9
9
|
* Default is true.
|
|
10
10
|
*/
|
|
11
11
|
autoFinalized?: boolean;
|
|
@@ -21,7 +21,9 @@ export class SignPsbtOptions {
|
|
|
21
21
|
public inputsToSign: InputToSign[],
|
|
22
22
|
) {}
|
|
23
23
|
|
|
24
|
-
static from(
|
|
24
|
+
static from(
|
|
25
|
+
options?: SignPsbtOptionsLike | SignPsbtOptions,
|
|
26
|
+
): SignPsbtOptions {
|
|
25
27
|
if (options instanceof SignPsbtOptions) {
|
|
26
28
|
return options;
|
|
27
29
|
}
|
package/src/signer/btc/verify.ts
CHANGED
|
@@ -78,7 +78,7 @@ export function btcP2pkhAddressFromPublicKey(
|
|
|
78
78
|
* @public
|
|
79
79
|
*/
|
|
80
80
|
export function btcPublicKeyFromP2pkhAddress(address: string): Hex {
|
|
81
|
-
return hexFrom(bs58check.decode(address).
|
|
81
|
+
return hexFrom(bs58check.decode(address).subarray(1));
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
/**
|
|
@@ -92,7 +92,7 @@ export function verifyMessageBtcEcdsa(
|
|
|
92
92
|
const challenge =
|
|
93
93
|
typeof message === "string" ? message : hexFrom(message).slice(2);
|
|
94
94
|
|
|
95
|
-
const rawSign = bytesFrom(signature, "base64").
|
|
95
|
+
const rawSign = bytesFrom(signature, "base64").subarray(1);
|
|
96
96
|
|
|
97
97
|
return secp256k1.verify(
|
|
98
98
|
bytesFrom(rawSign),
|
|
@@ -21,7 +21,7 @@ export function signMessageSecp256k1(
|
|
|
21
21
|
format: "recovered",
|
|
22
22
|
prehash: false,
|
|
23
23
|
});
|
|
24
|
-
return hexFrom(bytesConcat(signature.
|
|
24
|
+
return hexFrom(bytesConcat(signature.subarray(1), signature.subarray(0, 1)));
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
@@ -40,7 +40,7 @@ export function verifyMessageSecp256k1(
|
|
|
40
40
|
): boolean {
|
|
41
41
|
const signatureBytes = bytesFrom(signature);
|
|
42
42
|
return secp256k1.verify(
|
|
43
|
-
bytesConcat(signatureBytes.
|
|
43
|
+
bytesConcat(signatureBytes.subarray(64), signatureBytes.subarray(0, 64)),
|
|
44
44
|
bytesFrom(message),
|
|
45
45
|
bytesFrom(publicKey),
|
|
46
46
|
{ format: "recovered", prehash: false },
|
|
@@ -62,7 +62,7 @@ export function recoverMessageSecp256k1(
|
|
|
62
62
|
const signatureBytes = bytesFrom(signature);
|
|
63
63
|
return hexFrom(
|
|
64
64
|
secp256k1.recoverPublicKey(
|
|
65
|
-
bytesConcat(signatureBytes.
|
|
65
|
+
bytesConcat(signatureBytes.subarray(64), signatureBytes.subarray(0, 64)),
|
|
66
66
|
bytesFrom(message),
|
|
67
67
|
{ prehash: false },
|
|
68
68
|
),
|
|
@@ -53,7 +53,7 @@ export abstract class SignerDoge extends Signer {
|
|
|
53
53
|
* @returns A promise that resolves to an array of Address objects.
|
|
54
54
|
*/
|
|
55
55
|
async getAddressObjs(): Promise<Address[]> {
|
|
56
|
-
const hash = bs58check.decode(await this.getDogeAddress()).
|
|
56
|
+
const hash = bs58check.decode(await this.getDogeAddress()).subarray(1);
|
|
57
57
|
|
|
58
58
|
return [
|
|
59
59
|
await Address.fromKnownScript(
|
package/src/signer/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ export * from "./ckb/index.js";
|
|
|
3
3
|
export * from "./doge/index.js";
|
|
4
4
|
export * from "./dummy/index.js";
|
|
5
5
|
export * from "./evm/index.js";
|
|
6
|
+
export * from "./jsonRpc/index.js";
|
|
6
7
|
export * from "./nostr/index.js";
|
|
7
8
|
export * from "./signer/index.js";
|
|
8
9
|
export * from "./signerFromSignature.js";
|