@ckb-ccc/core 0.0.16-alpha.3 → 0.1.0-alpha.4
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 +6 -0
- package/dist/bytes/index.d.ts +1 -1
- package/dist/bytes/index.d.ts.map +1 -1
- package/dist/bytes/index.js +14 -13
- package/dist/ckb/transaction.d.ts +6 -6
- package/dist/ckb/transaction.d.ts.map +1 -1
- package/dist/ckb/transaction.js +1 -0
- package/dist/client/client.d.ts +3 -46
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +3 -42
- package/dist/client/clientPublicMainnet.advanced.d.ts +2 -5
- package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.advanced.js +1 -1
- package/dist/client/clientPublicMainnet.d.ts +6 -11
- package/dist/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.js +2 -5
- package/dist/client/clientPublicTestnet.advanced.d.ts +2 -5
- package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.advanced.js +1 -1
- package/dist/client/clientPublicTestnet.d.ts +6 -11
- package/dist/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.js +2 -5
- package/dist/client/clientTypes.d.ts +60 -1
- package/dist/client/clientTypes.d.ts.map +1 -1
- package/dist/client/clientTypes.js +53 -1
- package/dist/client/jsonRpc/index.d.ts +9 -20
- package/dist/client/jsonRpc/index.d.ts.map +1 -1
- package/dist/client/jsonRpc/index.js +10 -3
- package/dist/client/transports/http.d.ts.map +1 -1
- package/dist/client/transports/http.js +2 -0
- package/dist/client/transports/webSocket.d.ts.map +1 -1
- package/dist/client/transports/webSocket.js +10 -5
- package/dist/signer/ckb/verifyJoyId.d.ts.map +1 -1
- package/dist/signer/ckb/verifyJoyId.js +1 -0
- package/dist/signer/nostr/signerNostr.js +1 -1
- package/dist/signer/nostr/verify.d.ts.map +1 -1
- package/dist/signer/nostr/verify.js +1 -0
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist.commonjs/address/address.advanced.js +3 -3
- package/dist.commonjs/bytes/index.d.ts +1 -1
- package/dist.commonjs/bytes/index.d.ts.map +1 -1
- package/dist.commonjs/bytes/index.js +17 -17
- package/dist.commonjs/ckb/molecule.advanced/generated.js +33 -34
- package/dist.commonjs/ckb/molecule.advanced/index.js +1 -2
- package/dist.commonjs/ckb/script.js +4 -4
- package/dist.commonjs/ckb/transaction.d.ts +6 -6
- package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
- package/dist.commonjs/ckb/transaction.js +9 -8
- package/dist.commonjs/client/cache/memory.advanced.js +5 -6
- package/dist.commonjs/client/client.d.ts +3 -46
- package/dist.commonjs/client/client.d.ts.map +1 -1
- package/dist.commonjs/client/client.js +2 -42
- package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +2 -5
- package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicMainnet.advanced.js +21 -21
- package/dist.commonjs/client/clientPublicMainnet.d.ts +6 -11
- package/dist.commonjs/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicMainnet.js +2 -5
- package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +2 -5
- package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicTestnet.advanced.js +21 -21
- package/dist.commonjs/client/clientPublicTestnet.d.ts +6 -11
- package/dist.commonjs/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicTestnet.js +2 -5
- package/dist.commonjs/client/clientTypes.advanced.js +1 -2
- package/dist.commonjs/client/clientTypes.d.ts +60 -1
- package/dist.commonjs/client/clientTypes.d.ts.map +1 -1
- package/dist.commonjs/client/clientTypes.js +55 -1
- package/dist.commonjs/client/jsonRpc/index.d.ts +9 -20
- package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -1
- package/dist.commonjs/client/jsonRpc/index.js +9 -2
- package/dist.commonjs/client/transports/advanced.js +1 -2
- package/dist.commonjs/client/transports/http.d.ts.map +1 -1
- package/dist.commonjs/client/transports/http.js +2 -0
- package/dist.commonjs/client/transports/webSocket.d.ts.map +1 -1
- package/dist.commonjs/client/transports/webSocket.js +10 -5
- package/dist.commonjs/fixedPoint/index.js +3 -3
- package/dist.commonjs/hasher/hasherCkb.js +3 -3
- package/dist.commonjs/hex/index.js +1 -2
- package/dist.commonjs/keystore/index.js +2 -3
- package/dist.commonjs/num/index.js +10 -11
- package/dist.commonjs/signer/btc/verify.js +1 -2
- package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.js +2 -3
- package/dist.commonjs/signer/ckb/verifyJoyId.d.ts.map +1 -1
- package/dist.commonjs/signer/ckb/verifyJoyId.js +2 -2
- package/dist.commonjs/signer/evm/verify.js +1 -2
- package/dist.commonjs/signer/nostr/signerNostr.js +1 -1
- package/dist.commonjs/signer/nostr/verify.d.ts.map +1 -1
- package/dist.commonjs/signer/nostr/verify.js +3 -3
- package/dist.commonjs/utils/index.d.ts +1 -1
- package/dist.commonjs/utils/index.d.ts.map +1 -1
- package/dist.commonjs/utils/index.js +4 -5
- package/package.json +4 -3
- package/src/bytes/index.ts +15 -14
- package/src/ckb/transaction.ts +1 -0
- package/src/client/client.ts +7 -62
- package/src/client/clientPublicMainnet.advanced.ts +329 -333
- package/src/client/clientPublicMainnet.ts +3 -11
- package/src/client/clientPublicTestnet.advanced.ts +341 -344
- package/src/client/clientPublicTestnet.ts +3 -11
- package/src/client/clientTypes.ts +87 -0
- package/src/client/jsonRpc/index.ts +29 -15
- package/src/client/transports/http.ts +2 -0
- package/src/client/transports/webSocket.ts +15 -8
- package/src/signer/ckb/verifyJoyId.ts +5 -1
- package/src/signer/nostr/signerNostr.ts +1 -1
- package/src/signer/nostr/verify.ts +2 -1
- package/src/utils/index.ts +1 -1
- package/dist/fixedPoint/index.test.d.ts +0 -2
- package/dist/fixedPoint/index.test.d.ts.map +0 -1
- package/dist/fixedPoint/index.test.js +0 -43
- package/dist.commonjs/fixedPoint/index.test.d.ts +0 -2
- package/dist.commonjs/fixedPoint/index.test.d.ts.map +0 -1
- package/dist.commonjs/fixedPoint/index.test.js +0 -45
- package/src/fixedPoint/index.test.ts +0 -55
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import WebSocket from "isomorphic-ws";
|
|
2
|
-
import { Script } from "../ckb/index.js";
|
|
3
2
|
import { ClientCache } from "./cache/index.js";
|
|
4
|
-
import { CellDepInfo, KnownScript } from "./client.js";
|
|
5
3
|
import { TESTNET_SCRIPTS } from "./clientPublicTestnet.advanced.js";
|
|
4
|
+
import { KnownScript, ScriptInfo } from "./clientTypes.js";
|
|
6
5
|
import { ClientJsonRpc } from "./jsonRpc/index.js";
|
|
7
6
|
|
|
8
7
|
/**
|
|
@@ -34,15 +33,8 @@ export class ClientPublicTestnet extends ClientJsonRpc {
|
|
|
34
33
|
return "ckt";
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
async getKnownScript(
|
|
38
|
-
script: KnownScript,
|
|
39
|
-
): Promise<
|
|
40
|
-
Pick<Script, "codeHash" | "hashType"> & { cellDeps: CellDepInfo[] }
|
|
41
|
-
> {
|
|
36
|
+
async getKnownScript(script: KnownScript): Promise<ScriptInfo> {
|
|
42
37
|
const found = this.scripts[script];
|
|
43
|
-
return
|
|
44
|
-
...found,
|
|
45
|
-
cellDeps: found.cellDeps.map((c) => CellDepInfo.from(c)),
|
|
46
|
-
};
|
|
38
|
+
return ScriptInfo.from(found);
|
|
47
39
|
}
|
|
48
40
|
}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Cell,
|
|
3
|
+
CellDep,
|
|
4
|
+
CellDepLike,
|
|
3
5
|
Epoch,
|
|
6
|
+
HashType,
|
|
7
|
+
HashTypeLike,
|
|
4
8
|
OutPoint,
|
|
5
9
|
OutPointLike,
|
|
6
10
|
Script,
|
|
11
|
+
ScriptLike,
|
|
7
12
|
Transaction,
|
|
13
|
+
hashTypeFrom,
|
|
8
14
|
} from "../ckb/index.js";
|
|
9
15
|
import { Hex, HexLike, hexFrom } from "../hex/index.js";
|
|
10
16
|
import { Num, NumLike, numFrom } from "../num/index.js";
|
|
@@ -15,6 +21,87 @@ import {
|
|
|
15
21
|
clientSearchKeyRangeFrom,
|
|
16
22
|
} from "./clientTypes.advanced.js";
|
|
17
23
|
|
|
24
|
+
/**
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
export enum KnownScript {
|
|
28
|
+
NervosDao = "NervosDao",
|
|
29
|
+
Secp256k1Blake160 = "Secp256k1Blake160",
|
|
30
|
+
Secp256k1Multisig = "Secp256k1Multisig",
|
|
31
|
+
AnyoneCanPay = "AnyoneCanPay",
|
|
32
|
+
TypeId = "TypeId",
|
|
33
|
+
XUdt = "XUdt",
|
|
34
|
+
JoyId = "JoyId",
|
|
35
|
+
COTA = "COTA",
|
|
36
|
+
PWLock = "PWLock",
|
|
37
|
+
OmniLock = "OmniLock",
|
|
38
|
+
NostrLock = "NostrLock",
|
|
39
|
+
UniqueType = "UniqueType",
|
|
40
|
+
|
|
41
|
+
// ckb-proxy-locks https://github.com/ckb-ecofund/ckb-proxy-locks
|
|
42
|
+
AlwaysSuccess = "AlwaysSuccess",
|
|
43
|
+
InputTypeProxyLock = "InputTypeProxyLock",
|
|
44
|
+
OutputTypeProxyLock = "OutputTypeProxyLock",
|
|
45
|
+
LockProxyLock = "LockProxyLock",
|
|
46
|
+
SingleUseLock = "SingleUseLock",
|
|
47
|
+
TypeBurnLock = "TypeBurnLock",
|
|
48
|
+
EasyToDiscoverType = "EasyToDiscoverType",
|
|
49
|
+
TimeLock = "TimeLock",
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
55
|
+
export type CellDepInfoLike = {
|
|
56
|
+
cellDep: CellDepLike;
|
|
57
|
+
type?: ScriptLike | null;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
export class CellDepInfo {
|
|
64
|
+
constructor(
|
|
65
|
+
public cellDep: CellDep,
|
|
66
|
+
public type?: Script,
|
|
67
|
+
) {}
|
|
68
|
+
|
|
69
|
+
static from(cellDepInfoLike: CellDepInfoLike): CellDepInfo {
|
|
70
|
+
return new CellDepInfo(
|
|
71
|
+
CellDep.from(cellDepInfoLike.cellDep),
|
|
72
|
+
apply(Script.from, cellDepInfoLike.type),
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @public
|
|
79
|
+
*/
|
|
80
|
+
export type ScriptInfoLike = {
|
|
81
|
+
codeHash: HexLike;
|
|
82
|
+
hashType: HashTypeLike;
|
|
83
|
+
cellDeps: CellDepInfoLike[];
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @public
|
|
88
|
+
*/
|
|
89
|
+
export class ScriptInfo {
|
|
90
|
+
constructor(
|
|
91
|
+
public codeHash: Hex,
|
|
92
|
+
public hashType: HashType,
|
|
93
|
+
public cellDeps: CellDepInfo[],
|
|
94
|
+
) {}
|
|
95
|
+
|
|
96
|
+
static from(scriptInfoLike: ScriptInfoLike): ScriptInfo {
|
|
97
|
+
return new ScriptInfo(
|
|
98
|
+
hexFrom(scriptInfoLike.codeHash),
|
|
99
|
+
hashTypeFrom(scriptInfoLike.hashType),
|
|
100
|
+
scriptInfoLike.cellDeps.map((c) => CellDepInfo.from(c)),
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
18
105
|
/**
|
|
19
106
|
* @public
|
|
20
107
|
*/
|
|
@@ -26,7 +26,12 @@ import {
|
|
|
26
26
|
Transport,
|
|
27
27
|
transportFromUri,
|
|
28
28
|
} from "../transports/advanced.js";
|
|
29
|
-
import {
|
|
29
|
+
import {
|
|
30
|
+
JsonRpcBlock,
|
|
31
|
+
JsonRpcBlockHeader,
|
|
32
|
+
JsonRpcCellOutput,
|
|
33
|
+
JsonRpcTransformers,
|
|
34
|
+
} from "./advanced.js";
|
|
30
35
|
|
|
31
36
|
/**
|
|
32
37
|
* Applies a transformation function to a value if the transformer is provided.
|
|
@@ -127,8 +132,11 @@ export abstract class ClientJsonRpc extends Client {
|
|
|
127
132
|
|
|
128
133
|
getFeeRateStatistics = this.buildSender(
|
|
129
134
|
"get_fee_rate_statistics",
|
|
130
|
-
[(n) => apply(numFrom, n)],
|
|
131
|
-
({ mean, median }
|
|
135
|
+
[(n: NumLike) => apply(numFrom, n)],
|
|
136
|
+
({ mean, median }: { mean: NumLike; median: NumLike }) => ({
|
|
137
|
+
mean: numFrom(mean),
|
|
138
|
+
median: numFrom(median),
|
|
139
|
+
}),
|
|
132
140
|
) as Client["getFeeRateStatistics"];
|
|
133
141
|
|
|
134
142
|
/**
|
|
@@ -149,8 +157,10 @@ export abstract class ClientJsonRpc extends Client {
|
|
|
149
157
|
* @param verbosity - result format which allows 0 and 1. (Optional, the default is 1.)
|
|
150
158
|
* @returns BlockHeader
|
|
151
159
|
*/
|
|
152
|
-
getTipHeader = this.buildSender(
|
|
153
|
-
|
|
160
|
+
getTipHeader = this.buildSender(
|
|
161
|
+
"get_tip_header",
|
|
162
|
+
[],
|
|
163
|
+
(b: JsonRpcBlockHeader) => apply(JsonRpcTransformers.blockHeaderTo, b),
|
|
154
164
|
) as Client["getTipHeader"];
|
|
155
165
|
|
|
156
166
|
/**
|
|
@@ -164,7 +174,7 @@ export abstract class ClientJsonRpc extends Client {
|
|
|
164
174
|
getBlockByNumber = this.buildSender(
|
|
165
175
|
"get_block_by_number",
|
|
166
176
|
[(v: NumLike) => numToHex(numFrom(v))],
|
|
167
|
-
(b) => apply(JsonRpcTransformers.blockTo, b),
|
|
177
|
+
(b: JsonRpcBlock) => apply(JsonRpcTransformers.blockTo, b),
|
|
168
178
|
) as Client["getBlockByNumber"];
|
|
169
179
|
|
|
170
180
|
/**
|
|
@@ -175,7 +185,7 @@ export abstract class ClientJsonRpc extends Client {
|
|
|
175
185
|
* @param withCycles - whether the return cycles of block transactions. (Optional, default false.)
|
|
176
186
|
* @returns Block
|
|
177
187
|
*/
|
|
178
|
-
getBlockByHash = this.buildSender("get_block", [hexFrom], (b) =>
|
|
188
|
+
getBlockByHash = this.buildSender("get_block", [hexFrom], (b: JsonRpcBlock) =>
|
|
179
189
|
apply(JsonRpcTransformers.blockTo, b),
|
|
180
190
|
) as Client["getBlockByHash"];
|
|
181
191
|
|
|
@@ -189,7 +199,7 @@ export abstract class ClientJsonRpc extends Client {
|
|
|
189
199
|
getHeaderByNumber = this.buildSender(
|
|
190
200
|
"get_header_by_number",
|
|
191
201
|
[(v: NumLike) => numToHex(numFrom(v))],
|
|
192
|
-
(b) => apply(JsonRpcTransformers.blockHeaderTo, b),
|
|
202
|
+
(b: JsonRpcBlockHeader) => apply(JsonRpcTransformers.blockHeaderTo, b),
|
|
193
203
|
) as Client["getHeaderByNumber"];
|
|
194
204
|
|
|
195
205
|
/**
|
|
@@ -199,8 +209,10 @@ export abstract class ClientJsonRpc extends Client {
|
|
|
199
209
|
* @param verbosity - result format which allows 0 and 1. (Optional, the default is 1.)
|
|
200
210
|
* @returns BlockHeader
|
|
201
211
|
*/
|
|
202
|
-
getHeaderByHash = this.buildSender(
|
|
203
|
-
|
|
212
|
+
getHeaderByHash = this.buildSender(
|
|
213
|
+
"get_header",
|
|
214
|
+
[hexFrom],
|
|
215
|
+
(b: JsonRpcBlockHeader) => apply(JsonRpcTransformers.blockHeaderTo, b),
|
|
204
216
|
) as Client["getHeaderByHash"];
|
|
205
217
|
|
|
206
218
|
/**
|
|
@@ -315,8 +327,8 @@ export abstract class ClientJsonRpc extends Client {
|
|
|
315
327
|
"get_cells",
|
|
316
328
|
[
|
|
317
329
|
JsonRpcTransformers.indexerSearchKeyFrom,
|
|
318
|
-
(order) => order ?? "asc",
|
|
319
|
-
(limit) => numToHex(limit ?? 10),
|
|
330
|
+
(order?: "asc" | "desc") => order ?? "asc",
|
|
331
|
+
(limit?: NumLike) => numToHex(limit ?? 10),
|
|
320
332
|
],
|
|
321
333
|
JsonRpcTransformers.findCellsResponseTo,
|
|
322
334
|
) as (
|
|
@@ -340,8 +352,8 @@ export abstract class ClientJsonRpc extends Client {
|
|
|
340
352
|
"get_transactions",
|
|
341
353
|
[
|
|
342
354
|
JsonRpcTransformers.indexerSearchKeyTransactionFrom,
|
|
343
|
-
(order) => order ?? "asc",
|
|
344
|
-
(limit) => numToHex(limit ?? 10),
|
|
355
|
+
(order?: "asc" | "desc") => order ?? "asc",
|
|
356
|
+
(limit?: NumLike) => numToHex(limit ?? 10),
|
|
345
357
|
],
|
|
346
358
|
JsonRpcTransformers.findTransactionsResponseTo,
|
|
347
359
|
) as Client["findTransactionsPaged"];
|
|
@@ -356,7 +368,7 @@ export abstract class ClientJsonRpc extends Client {
|
|
|
356
368
|
getCellsCapacity = this.buildSender(
|
|
357
369
|
"get_cells_capacity",
|
|
358
370
|
[JsonRpcTransformers.indexerSearchKeyFrom],
|
|
359
|
-
({ capacity }) => numFrom(capacity),
|
|
371
|
+
({ capacity }: { capacity: NumLike }) => numFrom(capacity),
|
|
360
372
|
) as (key: ClientIndexerSearchKeyLike) => Promise<Num>;
|
|
361
373
|
|
|
362
374
|
/**
|
|
@@ -370,7 +382,9 @@ export abstract class ClientJsonRpc extends Client {
|
|
|
370
382
|
|
|
371
383
|
buildSender(
|
|
372
384
|
rpcMethod: string,
|
|
385
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
373
386
|
inTransformers: (((_: any) => unknown) | undefined)[],
|
|
387
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
374
388
|
outTransformer?: (_: any) => unknown,
|
|
375
389
|
): (...req: unknown[]) => Promise<unknown> {
|
|
376
390
|
return async (...req: unknown[]) => {
|
|
@@ -10,6 +10,7 @@ export class TransportHttp implements Transport {
|
|
|
10
10
|
const aborter = new AbortController();
|
|
11
11
|
const abortTimer = setTimeout(() => aborter.abort(), this.timeout);
|
|
12
12
|
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
13
14
|
const raw = await (
|
|
14
15
|
await fetch(this.url, {
|
|
15
16
|
method: "POST",
|
|
@@ -21,6 +22,7 @@ export class TransportHttp implements Transport {
|
|
|
21
22
|
})
|
|
22
23
|
).json();
|
|
23
24
|
clearTimeout(abortTimer);
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
24
26
|
return raw;
|
|
25
27
|
}
|
|
26
28
|
}
|
|
@@ -29,19 +29,26 @@ export class TransportWebSocket implements Transport {
|
|
|
29
29
|
return this.openSocket;
|
|
30
30
|
}
|
|
31
31
|
const socket = new WebSocket(this.url);
|
|
32
|
-
const onMessage = ({ data }:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
const onMessage = ({ data }: WebSocket.MessageEvent) => {
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
34
|
+
const res = JSON.parse(data as string);
|
|
35
|
+
if (
|
|
36
|
+
typeof res !== "object" ||
|
|
37
|
+
res === null ||
|
|
38
|
+
typeof res.id !== "number"
|
|
39
|
+
) {
|
|
40
|
+
throw new Error(`Unknown response ${data as string}`);
|
|
36
41
|
}
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
43
|
+
const id: number = res.id;
|
|
37
44
|
|
|
38
|
-
const req = this.ongoing.get(
|
|
45
|
+
const req = this.ongoing.get(id);
|
|
39
46
|
if (!req) {
|
|
40
47
|
return;
|
|
41
48
|
}
|
|
42
49
|
const [resolve, _, timeout] = req;
|
|
43
50
|
clearTimeout(timeout);
|
|
44
|
-
this.ongoing.delete(
|
|
51
|
+
this.ongoing.delete(id);
|
|
45
52
|
|
|
46
53
|
resolve(res);
|
|
47
54
|
};
|
|
@@ -80,13 +87,13 @@ export class TransportWebSocket implements Transport {
|
|
|
80
87
|
reject,
|
|
81
88
|
setTimeout(() => {
|
|
82
89
|
this.ongoing.delete(data.id);
|
|
83
|
-
socket.then((socket) => socket.close());
|
|
90
|
+
void socket.then((socket) => socket.close());
|
|
84
91
|
reject(new Error("Request timeout"));
|
|
85
92
|
}, this.timeout),
|
|
86
93
|
];
|
|
87
94
|
this.ongoing.set(data.id, req);
|
|
88
95
|
|
|
89
|
-
socket.then((socket) => {
|
|
96
|
+
void socket.then((socket) => {
|
|
90
97
|
if (
|
|
91
98
|
socket.readyState === socket.CLOSED ||
|
|
92
99
|
socket.readyState === socket.CLOSING
|
|
@@ -12,8 +12,12 @@ export function verifyMessageJoyId(
|
|
|
12
12
|
): Promise<boolean> {
|
|
13
13
|
const challenge =
|
|
14
14
|
typeof message === "string" ? message : hexFrom(message).slice(2);
|
|
15
|
-
const { publicKey, keyType } = JSON.parse(identity)
|
|
15
|
+
const { publicKey, keyType } = JSON.parse(identity) as {
|
|
16
|
+
publicKey: string;
|
|
17
|
+
keyType: string;
|
|
18
|
+
};
|
|
16
19
|
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
17
21
|
return verifySignature({
|
|
18
22
|
challenge,
|
|
19
23
|
pubkey: publicKey,
|
|
@@ -112,7 +112,7 @@ export abstract class SignerNostr extends Signer {
|
|
|
112
112
|
* @returns A promise that resolves to a signed Transaction object.
|
|
113
113
|
*/
|
|
114
114
|
async signOnlyTransaction(txLike: TransactionLike): Promise<Transaction> {
|
|
115
|
-
|
|
115
|
+
const tx = Transaction.from(txLike);
|
|
116
116
|
const { script } = await this.getRecommendedAddressObj();
|
|
117
117
|
const info = await tx.getSignHashInfo(script, this.client);
|
|
118
118
|
if (!info) {
|
|
@@ -13,6 +13,7 @@ export function buildNostrEventFromMessage(
|
|
|
13
13
|
): NostrEvent {
|
|
14
14
|
if (typeof message === "string") {
|
|
15
15
|
try {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
16
17
|
const event = JSON.parse(message);
|
|
17
18
|
if (
|
|
18
19
|
typeof event === "object" &&
|
|
@@ -26,7 +27,7 @@ export function buildNostrEventFromMessage(
|
|
|
26
27
|
(tag as unknown[]).every((v) => typeof v === "string"),
|
|
27
28
|
)
|
|
28
29
|
) {
|
|
29
|
-
return event;
|
|
30
|
+
return event as NostrEvent;
|
|
30
31
|
}
|
|
31
32
|
} catch (_) {}
|
|
32
33
|
}
|
package/src/utils/index.ts
CHANGED
|
@@ -106,7 +106,7 @@ export function apply<T, R>(
|
|
|
106
106
|
* @param accumulator - A callback to be called for each value. If it returns null, the previous result will be kept.
|
|
107
107
|
* @returns The accumulated result.
|
|
108
108
|
*/
|
|
109
|
-
export async function reduceAsync<T
|
|
109
|
+
export async function reduceAsync<T>(
|
|
110
110
|
values: T[],
|
|
111
111
|
accumulator: (
|
|
112
112
|
a: T,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../src/fixedPoint/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { fixedPointFrom, fixedPointToString } from "./index.js";
|
|
2
|
-
describe("fixedPointToString", () => {
|
|
3
|
-
const cases = [
|
|
4
|
-
[0n, "0"],
|
|
5
|
-
[1n, "0.00000001"],
|
|
6
|
-
[100000000n, "1"],
|
|
7
|
-
[1000000000n, "10"],
|
|
8
|
-
[1010100000n, "10.101"],
|
|
9
|
-
[11n, "1.1", 1],
|
|
10
|
-
[0n, "0", 1],
|
|
11
|
-
[1n, "1", 0],
|
|
12
|
-
[0n, "0", 0],
|
|
13
|
-
];
|
|
14
|
-
cases.forEach(([i, o, decimals]) => test(`${i} with ${decimals ?? "default"} decimals = "${o}"`, () => {
|
|
15
|
-
expect(fixedPointToString(i, decimals)).toBe(o);
|
|
16
|
-
}));
|
|
17
|
-
});
|
|
18
|
-
describe("fixedPointFrom string", () => {
|
|
19
|
-
const cases = [
|
|
20
|
-
["0", 0n],
|
|
21
|
-
["0.00000001", 1n],
|
|
22
|
-
["1", 100000000n],
|
|
23
|
-
["10", 1000000000n],
|
|
24
|
-
["10.101", 1010100000n],
|
|
25
|
-
["1.1", 11n, 1],
|
|
26
|
-
["0", 0n, 1],
|
|
27
|
-
["1", 1n, 0],
|
|
28
|
-
["0", 0n, 0],
|
|
29
|
-
];
|
|
30
|
-
cases.forEach(([i, o, decimals]) => test(`"${i}" = ${o} with ${decimals ?? "default"} decimals `, () => {
|
|
31
|
-
expect(fixedPointFrom(i, decimals)).toBe(o);
|
|
32
|
-
}));
|
|
33
|
-
});
|
|
34
|
-
describe("fixedPointFrom number", () => {
|
|
35
|
-
const cases = [
|
|
36
|
-
[0.00000001, 1n],
|
|
37
|
-
[10.101, 1010100000n],
|
|
38
|
-
[1.1, 11n, 1],
|
|
39
|
-
];
|
|
40
|
-
cases.forEach(([i, o, decimals]) => test(`${i} = ${o} with ${decimals ?? "default"} decimals `, () => {
|
|
41
|
-
expect(fixedPointFrom(i, decimals)).toBe(o);
|
|
42
|
-
}));
|
|
43
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../src/fixedPoint/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const index_js_1 = require("./index.js");
|
|
4
|
-
describe("fixedPointToString", () => {
|
|
5
|
-
const cases = [
|
|
6
|
-
[0n, "0"],
|
|
7
|
-
[1n, "0.00000001"],
|
|
8
|
-
[100000000n, "1"],
|
|
9
|
-
[1000000000n, "10"],
|
|
10
|
-
[1010100000n, "10.101"],
|
|
11
|
-
[11n, "1.1", 1],
|
|
12
|
-
[0n, "0", 1],
|
|
13
|
-
[1n, "1", 0],
|
|
14
|
-
[0n, "0", 0],
|
|
15
|
-
];
|
|
16
|
-
cases.forEach(([i, o, decimals]) => test(`${i} with ${decimals ?? "default"} decimals = "${o}"`, () => {
|
|
17
|
-
expect((0, index_js_1.fixedPointToString)(i, decimals)).toBe(o);
|
|
18
|
-
}));
|
|
19
|
-
});
|
|
20
|
-
describe("fixedPointFrom string", () => {
|
|
21
|
-
const cases = [
|
|
22
|
-
["0", 0n],
|
|
23
|
-
["0.00000001", 1n],
|
|
24
|
-
["1", 100000000n],
|
|
25
|
-
["10", 1000000000n],
|
|
26
|
-
["10.101", 1010100000n],
|
|
27
|
-
["1.1", 11n, 1],
|
|
28
|
-
["0", 0n, 1],
|
|
29
|
-
["1", 1n, 0],
|
|
30
|
-
["0", 0n, 0],
|
|
31
|
-
];
|
|
32
|
-
cases.forEach(([i, o, decimals]) => test(`"${i}" = ${o} with ${decimals ?? "default"} decimals `, () => {
|
|
33
|
-
expect((0, index_js_1.fixedPointFrom)(i, decimals)).toBe(o);
|
|
34
|
-
}));
|
|
35
|
-
});
|
|
36
|
-
describe("fixedPointFrom number", () => {
|
|
37
|
-
const cases = [
|
|
38
|
-
[0.00000001, 1n],
|
|
39
|
-
[10.101, 1010100000n],
|
|
40
|
-
[1.1, 11n, 1],
|
|
41
|
-
];
|
|
42
|
-
cases.forEach(([i, o, decimals]) => test(`${i} = ${o} with ${decimals ?? "default"} decimals `, () => {
|
|
43
|
-
expect((0, index_js_1.fixedPointFrom)(i, decimals)).toBe(o);
|
|
44
|
-
}));
|
|
45
|
-
});
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { fixedPointFrom, fixedPointToString } from "./index.js";
|
|
2
|
-
|
|
3
|
-
describe("fixedPointToString", () => {
|
|
4
|
-
const cases: [bigint, string, number?][] = [
|
|
5
|
-
[0n, "0"],
|
|
6
|
-
[1n, "0.00000001"],
|
|
7
|
-
[100000000n, "1"],
|
|
8
|
-
[1000000000n, "10"],
|
|
9
|
-
[1010100000n, "10.101"],
|
|
10
|
-
[11n, "1.1", 1],
|
|
11
|
-
[0n, "0", 1],
|
|
12
|
-
[1n, "1", 0],
|
|
13
|
-
[0n, "0", 0],
|
|
14
|
-
];
|
|
15
|
-
|
|
16
|
-
cases.forEach(([i, o, decimals]) =>
|
|
17
|
-
test(`${i} with ${decimals ?? "default"} decimals = "${o}"`, () => {
|
|
18
|
-
expect(fixedPointToString(i, decimals)).toBe(o);
|
|
19
|
-
}),
|
|
20
|
-
);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
describe("fixedPointFrom string", () => {
|
|
24
|
-
const cases: [string, bigint, number?][] = [
|
|
25
|
-
["0", 0n],
|
|
26
|
-
["0.00000001", 1n],
|
|
27
|
-
["1", 100000000n],
|
|
28
|
-
["10", 1000000000n],
|
|
29
|
-
["10.101", 1010100000n],
|
|
30
|
-
["1.1", 11n, 1],
|
|
31
|
-
["0", 0n, 1],
|
|
32
|
-
["1", 1n, 0],
|
|
33
|
-
["0", 0n, 0],
|
|
34
|
-
];
|
|
35
|
-
|
|
36
|
-
cases.forEach(([i, o, decimals]) =>
|
|
37
|
-
test(`"${i}" = ${o} with ${decimals ?? "default"} decimals `, () => {
|
|
38
|
-
expect(fixedPointFrom(i, decimals)).toBe(o);
|
|
39
|
-
}),
|
|
40
|
-
);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
describe("fixedPointFrom number", () => {
|
|
44
|
-
const cases: [number, bigint, number?][] = [
|
|
45
|
-
[0.00000001, 1n],
|
|
46
|
-
[10.101, 1010100000n],
|
|
47
|
-
[1.1, 11n, 1],
|
|
48
|
-
];
|
|
49
|
-
|
|
50
|
-
cases.forEach(([i, o, decimals]) =>
|
|
51
|
-
test(`${i} = ${o} with ${decimals ?? "default"} decimals `, () => {
|
|
52
|
-
expect(fixedPointFrom(i, decimals)).toBe(o);
|
|
53
|
-
}),
|
|
54
|
-
);
|
|
55
|
-
});
|