@inversealtruism/csd-client 0.1.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/LICENSE +21 -0
- package/dist/index.cjs +115 -0
- package/dist/index.d.cts +115 -0
- package/dist/index.d.ts +115 -0
- package/dist/index.js +88 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 InverseAltruism
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
CsdClient: () => CsdClient,
|
|
24
|
+
rpcHeaderToHeader: () => rpcHeaderToHeader,
|
|
25
|
+
rpcTxToTx: () => rpcTxToTx
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
var CsdClient = class {
|
|
29
|
+
base;
|
|
30
|
+
f;
|
|
31
|
+
timeoutMs;
|
|
32
|
+
constructor(opts) {
|
|
33
|
+
this.base = opts.baseUrl.replace(/\/+$/, "");
|
|
34
|
+
this.f = opts.fetch ?? globalThis.fetch;
|
|
35
|
+
this.timeoutMs = opts.timeoutMs ?? 1e4;
|
|
36
|
+
if (!this.f) throw new Error("no fetch available \u2014 pass opts.fetch");
|
|
37
|
+
}
|
|
38
|
+
async get(path) {
|
|
39
|
+
const r = await this.f(`${this.base}${path}`, { signal: AbortSignal.timeout(this.timeoutMs) });
|
|
40
|
+
if (!r.ok) throw new Error(`GET ${path} \u2192 HTTP ${r.status}`);
|
|
41
|
+
return r.json();
|
|
42
|
+
}
|
|
43
|
+
async post(path, body) {
|
|
44
|
+
const r = await this.f(`${this.base}${path}`, {
|
|
45
|
+
method: "POST",
|
|
46
|
+
headers: { "content-type": "application/json" },
|
|
47
|
+
body: JSON.stringify(body),
|
|
48
|
+
signal: AbortSignal.timeout(this.timeoutMs)
|
|
49
|
+
});
|
|
50
|
+
if (!r.ok) throw new Error(`POST ${path} \u2192 HTTP ${r.status}`);
|
|
51
|
+
return r.json();
|
|
52
|
+
}
|
|
53
|
+
tip() {
|
|
54
|
+
return this.get("/tip");
|
|
55
|
+
}
|
|
56
|
+
health() {
|
|
57
|
+
return this.get("/health");
|
|
58
|
+
}
|
|
59
|
+
blockByHeight(h) {
|
|
60
|
+
return this.get(`/block/height/${h}`);
|
|
61
|
+
}
|
|
62
|
+
blockByHash(hash) {
|
|
63
|
+
return this.get(`/block/${hash}`);
|
|
64
|
+
}
|
|
65
|
+
tx(id) {
|
|
66
|
+
return this.get(`/tx/${id}`);
|
|
67
|
+
}
|
|
68
|
+
utxos(addr) {
|
|
69
|
+
return this.get(`/utxos/${addr}`);
|
|
70
|
+
}
|
|
71
|
+
proposal(id) {
|
|
72
|
+
return this.get(`/proposal/${id}`);
|
|
73
|
+
}
|
|
74
|
+
proposals(domain, limit = 40) {
|
|
75
|
+
return this.get(`/proposals/${encodeURIComponent(domain)}/${limit}`);
|
|
76
|
+
}
|
|
77
|
+
topDomain(domain, epoch) {
|
|
78
|
+
return this.get(epoch == null ? `/top/${encodeURIComponent(domain)}` : `/top/${encodeURIComponent(domain)}/${epoch}`);
|
|
79
|
+
}
|
|
80
|
+
domains() {
|
|
81
|
+
return this.get("/domains");
|
|
82
|
+
}
|
|
83
|
+
mempool() {
|
|
84
|
+
return this.get("/mempool");
|
|
85
|
+
}
|
|
86
|
+
/** Broadcast a node-JSON tx (from @inversealtruism/csd-tx `txToNodeJson`). */
|
|
87
|
+
submit(nodeJsonTx) {
|
|
88
|
+
return this.post("/tx/submit", { tx: nodeJsonTx });
|
|
89
|
+
}
|
|
90
|
+
templatePropose(body) {
|
|
91
|
+
return this.post("/tx/template/propose", body);
|
|
92
|
+
}
|
|
93
|
+
templateAttest(body) {
|
|
94
|
+
return this.post("/tx/template/attest", body);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
function rpcTxToTx(j) {
|
|
98
|
+
const app = j.app.type === "None" ? { type: "None" } : j.app.type === "Propose" ? { type: "Propose", domain: j.app.domain, payloadHash: j.app.payload_hash, uri: j.app.uri, expiresEpoch: j.app.expires_epoch } : { type: "Attest", proposalId: j.app.proposal_id, score: j.app.score, confidence: j.app.confidence };
|
|
99
|
+
return {
|
|
100
|
+
version: j.version,
|
|
101
|
+
locktime: j.locktime,
|
|
102
|
+
app,
|
|
103
|
+
inputs: j.inputs.map((i) => ({ prevTxid: i.prev_txid, vout: i.vout, scriptSig: i.script_sig })),
|
|
104
|
+
outputs: j.outputs.map((o) => ({ value: o.value, scriptPubkey: o.script_pubkey }))
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function rpcHeaderToHeader(h) {
|
|
108
|
+
return { version: h.version, prev: h.prev, merkle: h.merkle, time: h.time, bits: h.bits, nonce: h.nonce };
|
|
109
|
+
}
|
|
110
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
111
|
+
0 && (module.exports = {
|
|
112
|
+
CsdClient,
|
|
113
|
+
rpcHeaderToHeader,
|
|
114
|
+
rpcTxToTx
|
|
115
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { BlockHeader, Tx } from '@inversealtruism/csd-codec';
|
|
2
|
+
|
|
3
|
+
interface RpcHeaderJson {
|
|
4
|
+
version: number;
|
|
5
|
+
prev: string;
|
|
6
|
+
merkle: string;
|
|
7
|
+
time: number;
|
|
8
|
+
bits: number;
|
|
9
|
+
nonce: number;
|
|
10
|
+
}
|
|
11
|
+
interface RpcTxJson {
|
|
12
|
+
txid: string;
|
|
13
|
+
version: number;
|
|
14
|
+
inputs: {
|
|
15
|
+
prev_txid: string;
|
|
16
|
+
vout: number;
|
|
17
|
+
script_sig: string;
|
|
18
|
+
script_sig_text?: string | null;
|
|
19
|
+
}[];
|
|
20
|
+
outputs: {
|
|
21
|
+
value: number;
|
|
22
|
+
script_pubkey: string;
|
|
23
|
+
}[];
|
|
24
|
+
locktime: number;
|
|
25
|
+
app: {
|
|
26
|
+
type: "None";
|
|
27
|
+
} | {
|
|
28
|
+
type: "Propose";
|
|
29
|
+
domain: string;
|
|
30
|
+
payload_hash: string;
|
|
31
|
+
uri: string;
|
|
32
|
+
expires_epoch: number;
|
|
33
|
+
} | {
|
|
34
|
+
type: "Attest";
|
|
35
|
+
proposal_id: string;
|
|
36
|
+
score: number;
|
|
37
|
+
confidence: number;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
interface RpcBlock {
|
|
41
|
+
ok: boolean;
|
|
42
|
+
hash: string;
|
|
43
|
+
height?: number;
|
|
44
|
+
chainwork?: string;
|
|
45
|
+
header: RpcHeaderJson;
|
|
46
|
+
txs: RpcTxJson[];
|
|
47
|
+
}
|
|
48
|
+
interface RpcTip {
|
|
49
|
+
tip: string;
|
|
50
|
+
height: number;
|
|
51
|
+
chainwork: string;
|
|
52
|
+
}
|
|
53
|
+
interface RpcUtxo {
|
|
54
|
+
txid: string;
|
|
55
|
+
vout: number;
|
|
56
|
+
value: number;
|
|
57
|
+
height: number;
|
|
58
|
+
confirmations: number;
|
|
59
|
+
coinbase: boolean;
|
|
60
|
+
}
|
|
61
|
+
interface RpcUtxos {
|
|
62
|
+
ok: boolean;
|
|
63
|
+
addr20: string;
|
|
64
|
+
count: number;
|
|
65
|
+
confirmed_balance: number;
|
|
66
|
+
utxos: RpcUtxo[];
|
|
67
|
+
}
|
|
68
|
+
interface RpcSubmit {
|
|
69
|
+
ok: boolean;
|
|
70
|
+
txid: string;
|
|
71
|
+
mempool_len?: number;
|
|
72
|
+
err?: string | null;
|
|
73
|
+
}
|
|
74
|
+
interface ClientOptions {
|
|
75
|
+
baseUrl: string;
|
|
76
|
+
fetch?: typeof fetch;
|
|
77
|
+
timeoutMs?: number;
|
|
78
|
+
}
|
|
79
|
+
declare class CsdClient {
|
|
80
|
+
private readonly base;
|
|
81
|
+
private readonly f;
|
|
82
|
+
private readonly timeoutMs;
|
|
83
|
+
constructor(opts: ClientOptions);
|
|
84
|
+
private get;
|
|
85
|
+
private post;
|
|
86
|
+
tip(): Promise<RpcTip>;
|
|
87
|
+
health(): Promise<any>;
|
|
88
|
+
blockByHeight(h: number): Promise<RpcBlock>;
|
|
89
|
+
blockByHash(hash: string): Promise<RpcBlock>;
|
|
90
|
+
tx(id: string): Promise<{
|
|
91
|
+
ok: boolean;
|
|
92
|
+
txid: string;
|
|
93
|
+
block_hash?: string;
|
|
94
|
+
height?: number;
|
|
95
|
+
time?: number;
|
|
96
|
+
tx?: RpcTxJson;
|
|
97
|
+
err?: string;
|
|
98
|
+
}>;
|
|
99
|
+
utxos(addr: string): Promise<RpcUtxos>;
|
|
100
|
+
proposal(id: string): Promise<any>;
|
|
101
|
+
proposals(domain: string, limit?: number): Promise<any>;
|
|
102
|
+
topDomain(domain: string, epoch?: number): Promise<any>;
|
|
103
|
+
domains(): Promise<any>;
|
|
104
|
+
mempool(): Promise<any>;
|
|
105
|
+
/** Broadcast a node-JSON tx (from @inversealtruism/csd-tx `txToNodeJson`). */
|
|
106
|
+
submit(nodeJsonTx: unknown): Promise<RpcSubmit>;
|
|
107
|
+
templatePropose(body: unknown): Promise<any>;
|
|
108
|
+
templateAttest(body: unknown): Promise<any>;
|
|
109
|
+
}
|
|
110
|
+
/** Convert a node /tx or /block tx JSON back into the codec's Tx struct (for re-verification). */
|
|
111
|
+
declare function rpcTxToTx(j: RpcTxJson): Tx;
|
|
112
|
+
/** Convert a node /block header JSON into the codec's BlockHeader. */
|
|
113
|
+
declare function rpcHeaderToHeader(h: RpcHeaderJson): BlockHeader;
|
|
114
|
+
|
|
115
|
+
export { type ClientOptions, CsdClient, type RpcBlock, type RpcHeaderJson, type RpcSubmit, type RpcTip, type RpcTxJson, type RpcUtxo, type RpcUtxos, rpcHeaderToHeader, rpcTxToTx };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { BlockHeader, Tx } from '@inversealtruism/csd-codec';
|
|
2
|
+
|
|
3
|
+
interface RpcHeaderJson {
|
|
4
|
+
version: number;
|
|
5
|
+
prev: string;
|
|
6
|
+
merkle: string;
|
|
7
|
+
time: number;
|
|
8
|
+
bits: number;
|
|
9
|
+
nonce: number;
|
|
10
|
+
}
|
|
11
|
+
interface RpcTxJson {
|
|
12
|
+
txid: string;
|
|
13
|
+
version: number;
|
|
14
|
+
inputs: {
|
|
15
|
+
prev_txid: string;
|
|
16
|
+
vout: number;
|
|
17
|
+
script_sig: string;
|
|
18
|
+
script_sig_text?: string | null;
|
|
19
|
+
}[];
|
|
20
|
+
outputs: {
|
|
21
|
+
value: number;
|
|
22
|
+
script_pubkey: string;
|
|
23
|
+
}[];
|
|
24
|
+
locktime: number;
|
|
25
|
+
app: {
|
|
26
|
+
type: "None";
|
|
27
|
+
} | {
|
|
28
|
+
type: "Propose";
|
|
29
|
+
domain: string;
|
|
30
|
+
payload_hash: string;
|
|
31
|
+
uri: string;
|
|
32
|
+
expires_epoch: number;
|
|
33
|
+
} | {
|
|
34
|
+
type: "Attest";
|
|
35
|
+
proposal_id: string;
|
|
36
|
+
score: number;
|
|
37
|
+
confidence: number;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
interface RpcBlock {
|
|
41
|
+
ok: boolean;
|
|
42
|
+
hash: string;
|
|
43
|
+
height?: number;
|
|
44
|
+
chainwork?: string;
|
|
45
|
+
header: RpcHeaderJson;
|
|
46
|
+
txs: RpcTxJson[];
|
|
47
|
+
}
|
|
48
|
+
interface RpcTip {
|
|
49
|
+
tip: string;
|
|
50
|
+
height: number;
|
|
51
|
+
chainwork: string;
|
|
52
|
+
}
|
|
53
|
+
interface RpcUtxo {
|
|
54
|
+
txid: string;
|
|
55
|
+
vout: number;
|
|
56
|
+
value: number;
|
|
57
|
+
height: number;
|
|
58
|
+
confirmations: number;
|
|
59
|
+
coinbase: boolean;
|
|
60
|
+
}
|
|
61
|
+
interface RpcUtxos {
|
|
62
|
+
ok: boolean;
|
|
63
|
+
addr20: string;
|
|
64
|
+
count: number;
|
|
65
|
+
confirmed_balance: number;
|
|
66
|
+
utxos: RpcUtxo[];
|
|
67
|
+
}
|
|
68
|
+
interface RpcSubmit {
|
|
69
|
+
ok: boolean;
|
|
70
|
+
txid: string;
|
|
71
|
+
mempool_len?: number;
|
|
72
|
+
err?: string | null;
|
|
73
|
+
}
|
|
74
|
+
interface ClientOptions {
|
|
75
|
+
baseUrl: string;
|
|
76
|
+
fetch?: typeof fetch;
|
|
77
|
+
timeoutMs?: number;
|
|
78
|
+
}
|
|
79
|
+
declare class CsdClient {
|
|
80
|
+
private readonly base;
|
|
81
|
+
private readonly f;
|
|
82
|
+
private readonly timeoutMs;
|
|
83
|
+
constructor(opts: ClientOptions);
|
|
84
|
+
private get;
|
|
85
|
+
private post;
|
|
86
|
+
tip(): Promise<RpcTip>;
|
|
87
|
+
health(): Promise<any>;
|
|
88
|
+
blockByHeight(h: number): Promise<RpcBlock>;
|
|
89
|
+
blockByHash(hash: string): Promise<RpcBlock>;
|
|
90
|
+
tx(id: string): Promise<{
|
|
91
|
+
ok: boolean;
|
|
92
|
+
txid: string;
|
|
93
|
+
block_hash?: string;
|
|
94
|
+
height?: number;
|
|
95
|
+
time?: number;
|
|
96
|
+
tx?: RpcTxJson;
|
|
97
|
+
err?: string;
|
|
98
|
+
}>;
|
|
99
|
+
utxos(addr: string): Promise<RpcUtxos>;
|
|
100
|
+
proposal(id: string): Promise<any>;
|
|
101
|
+
proposals(domain: string, limit?: number): Promise<any>;
|
|
102
|
+
topDomain(domain: string, epoch?: number): Promise<any>;
|
|
103
|
+
domains(): Promise<any>;
|
|
104
|
+
mempool(): Promise<any>;
|
|
105
|
+
/** Broadcast a node-JSON tx (from @inversealtruism/csd-tx `txToNodeJson`). */
|
|
106
|
+
submit(nodeJsonTx: unknown): Promise<RpcSubmit>;
|
|
107
|
+
templatePropose(body: unknown): Promise<any>;
|
|
108
|
+
templateAttest(body: unknown): Promise<any>;
|
|
109
|
+
}
|
|
110
|
+
/** Convert a node /tx or /block tx JSON back into the codec's Tx struct (for re-verification). */
|
|
111
|
+
declare function rpcTxToTx(j: RpcTxJson): Tx;
|
|
112
|
+
/** Convert a node /block header JSON into the codec's BlockHeader. */
|
|
113
|
+
declare function rpcHeaderToHeader(h: RpcHeaderJson): BlockHeader;
|
|
114
|
+
|
|
115
|
+
export { type ClientOptions, CsdClient, type RpcBlock, type RpcHeaderJson, type RpcSubmit, type RpcTip, type RpcTxJson, type RpcUtxo, type RpcUtxos, rpcHeaderToHeader, rpcTxToTx };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var CsdClient = class {
|
|
3
|
+
base;
|
|
4
|
+
f;
|
|
5
|
+
timeoutMs;
|
|
6
|
+
constructor(opts) {
|
|
7
|
+
this.base = opts.baseUrl.replace(/\/+$/, "");
|
|
8
|
+
this.f = opts.fetch ?? globalThis.fetch;
|
|
9
|
+
this.timeoutMs = opts.timeoutMs ?? 1e4;
|
|
10
|
+
if (!this.f) throw new Error("no fetch available \u2014 pass opts.fetch");
|
|
11
|
+
}
|
|
12
|
+
async get(path) {
|
|
13
|
+
const r = await this.f(`${this.base}${path}`, { signal: AbortSignal.timeout(this.timeoutMs) });
|
|
14
|
+
if (!r.ok) throw new Error(`GET ${path} \u2192 HTTP ${r.status}`);
|
|
15
|
+
return r.json();
|
|
16
|
+
}
|
|
17
|
+
async post(path, body) {
|
|
18
|
+
const r = await this.f(`${this.base}${path}`, {
|
|
19
|
+
method: "POST",
|
|
20
|
+
headers: { "content-type": "application/json" },
|
|
21
|
+
body: JSON.stringify(body),
|
|
22
|
+
signal: AbortSignal.timeout(this.timeoutMs)
|
|
23
|
+
});
|
|
24
|
+
if (!r.ok) throw new Error(`POST ${path} \u2192 HTTP ${r.status}`);
|
|
25
|
+
return r.json();
|
|
26
|
+
}
|
|
27
|
+
tip() {
|
|
28
|
+
return this.get("/tip");
|
|
29
|
+
}
|
|
30
|
+
health() {
|
|
31
|
+
return this.get("/health");
|
|
32
|
+
}
|
|
33
|
+
blockByHeight(h) {
|
|
34
|
+
return this.get(`/block/height/${h}`);
|
|
35
|
+
}
|
|
36
|
+
blockByHash(hash) {
|
|
37
|
+
return this.get(`/block/${hash}`);
|
|
38
|
+
}
|
|
39
|
+
tx(id) {
|
|
40
|
+
return this.get(`/tx/${id}`);
|
|
41
|
+
}
|
|
42
|
+
utxos(addr) {
|
|
43
|
+
return this.get(`/utxos/${addr}`);
|
|
44
|
+
}
|
|
45
|
+
proposal(id) {
|
|
46
|
+
return this.get(`/proposal/${id}`);
|
|
47
|
+
}
|
|
48
|
+
proposals(domain, limit = 40) {
|
|
49
|
+
return this.get(`/proposals/${encodeURIComponent(domain)}/${limit}`);
|
|
50
|
+
}
|
|
51
|
+
topDomain(domain, epoch) {
|
|
52
|
+
return this.get(epoch == null ? `/top/${encodeURIComponent(domain)}` : `/top/${encodeURIComponent(domain)}/${epoch}`);
|
|
53
|
+
}
|
|
54
|
+
domains() {
|
|
55
|
+
return this.get("/domains");
|
|
56
|
+
}
|
|
57
|
+
mempool() {
|
|
58
|
+
return this.get("/mempool");
|
|
59
|
+
}
|
|
60
|
+
/** Broadcast a node-JSON tx (from @inversealtruism/csd-tx `txToNodeJson`). */
|
|
61
|
+
submit(nodeJsonTx) {
|
|
62
|
+
return this.post("/tx/submit", { tx: nodeJsonTx });
|
|
63
|
+
}
|
|
64
|
+
templatePropose(body) {
|
|
65
|
+
return this.post("/tx/template/propose", body);
|
|
66
|
+
}
|
|
67
|
+
templateAttest(body) {
|
|
68
|
+
return this.post("/tx/template/attest", body);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
function rpcTxToTx(j) {
|
|
72
|
+
const app = j.app.type === "None" ? { type: "None" } : j.app.type === "Propose" ? { type: "Propose", domain: j.app.domain, payloadHash: j.app.payload_hash, uri: j.app.uri, expiresEpoch: j.app.expires_epoch } : { type: "Attest", proposalId: j.app.proposal_id, score: j.app.score, confidence: j.app.confidence };
|
|
73
|
+
return {
|
|
74
|
+
version: j.version,
|
|
75
|
+
locktime: j.locktime,
|
|
76
|
+
app,
|
|
77
|
+
inputs: j.inputs.map((i) => ({ prevTxid: i.prev_txid, vout: i.vout, scriptSig: i.script_sig })),
|
|
78
|
+
outputs: j.outputs.map((o) => ({ value: o.value, scriptPubkey: o.script_pubkey }))
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function rpcHeaderToHeader(h) {
|
|
82
|
+
return { version: h.version, prev: h.prev, merkle: h.merkle, time: h.time, bits: h.bits, nonce: h.nonce };
|
|
83
|
+
}
|
|
84
|
+
export {
|
|
85
|
+
CsdClient,
|
|
86
|
+
rpcHeaderToHeader,
|
|
87
|
+
rpcTxToTx
|
|
88
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@inversealtruism/csd-client",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Typed HTTP RPC client for a Compute Substrate node (or the Cairn proxy / a discovered gateway) — tip/block/tx/utxos/proposals/top/domains/mempool/submit/templates.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@inversealtruism/csd-codec": "0.1.0"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@inversealtruism/csd-vectors": "0.1.0"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/InverseAltruism/csd-sdk.git",
|
|
34
|
+
"directory": "packages/client"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://cairn-substrate.com",
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
39
|
+
"test": "tsx test/client.test.ts"
|
|
40
|
+
}
|
|
41
|
+
}
|