@intent-engine/client 0.1.37 → 0.1.39
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/src/confirm-release.d.ts +26 -0
- package/dist/src/confirm-release.js +61 -0
- package/dist/src/confirm-release.js.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +3 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/job-specs.d.ts +4 -1
- package/dist/src/job-specs.js +17 -1
- package/dist/src/job-specs.js.map +1 -1
- package/dist/src/ledger.d.ts +35 -0
- package/dist/src/ledger.js +161 -0
- package/dist/src/ledger.js.map +1 -0
- package/dist/src/public-host.d.ts +4 -0
- package/dist/src/public-host.js +98 -0
- package/dist/src/public-host.js.map +1 -0
- package/package.json +12 -2
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Address } from "@solana/kit";
|
|
2
|
+
import type { Transport } from "./transport.js";
|
|
3
|
+
export type ConfirmTarget = {
|
|
4
|
+
intent: Address;
|
|
5
|
+
attestor: Address;
|
|
6
|
+
sha256?: string | undefined;
|
|
7
|
+
pages?: number | undefined;
|
|
8
|
+
payees?: readonly Address[] | undefined;
|
|
9
|
+
};
|
|
10
|
+
export type NodeView = {
|
|
11
|
+
genesis: string;
|
|
12
|
+
intent: string;
|
|
13
|
+
announcer: string | undefined;
|
|
14
|
+
};
|
|
15
|
+
export type ConfirmField = "genesis hash" | "intent account" | "earliest announcer" | "payee" | "second node";
|
|
16
|
+
export declare const NO_ACCOUNT = "no account";
|
|
17
|
+
export declare const NO_ANNOUNCER = "nobody";
|
|
18
|
+
export declare const INCOMPLETE_RECORD = "an incomplete delivery record";
|
|
19
|
+
export declare class ConfirmMismatch extends Error {
|
|
20
|
+
readonly field: ConfirmField;
|
|
21
|
+
readonly first: string;
|
|
22
|
+
readonly second: string;
|
|
23
|
+
constructor(field: ConfirmField, first: string, second: string);
|
|
24
|
+
}
|
|
25
|
+
export declare function nodeView(transport: Transport, target: ConfirmTarget): Promise<NodeView>;
|
|
26
|
+
export declare function confirmOnBoth(first: Transport, second: Transport, target: ConfirmTarget): Promise<NodeView>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { deliveryRecord, firstDelivery } from "./job-deliveries.js";
|
|
2
|
+
export const NO_ACCOUNT = "no account";
|
|
3
|
+
export const NO_ANNOUNCER = "nobody";
|
|
4
|
+
export const INCOMPLETE_RECORD = "an incomplete delivery record";
|
|
5
|
+
export class ConfirmMismatch extends Error {
|
|
6
|
+
field;
|
|
7
|
+
first;
|
|
8
|
+
second;
|
|
9
|
+
constructor(field, first, second) {
|
|
10
|
+
super(field === "second node"
|
|
11
|
+
? `the second RPC node could not be read (${second}), so the release is not confirmed; nothing was signed or sent`
|
|
12
|
+
: field === "payee"
|
|
13
|
+
? `both RPC nodes report the earliest announcer ${second}, which is not the payee ${first}; nothing was signed or sent`
|
|
14
|
+
: `the two RPC nodes report a different ${field}: the first ${first}, the second ${second}; nothing was signed or sent`);
|
|
15
|
+
this.name = "ConfirmMismatch";
|
|
16
|
+
this.field = field;
|
|
17
|
+
this.first = first;
|
|
18
|
+
this.second = second;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const hex = (bytes) => Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
22
|
+
const digestOf = async (bytes) => hex(new Uint8Array(await crypto.subtle.digest("SHA-256", bytes.slice())));
|
|
23
|
+
async function announcerOf(transport, target) {
|
|
24
|
+
if (target.sha256 === undefined) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
const record = await deliveryRecord(transport, target.attestor, target.intent, target.pages);
|
|
28
|
+
if (!record.complete) {
|
|
29
|
+
return INCOMPLETE_RECORD;
|
|
30
|
+
}
|
|
31
|
+
const first = firstDelivery(record.deliveries, target.sha256);
|
|
32
|
+
return first === null ? NO_ANNOUNCER : `${first.worker} in ${first.signature}`;
|
|
33
|
+
}
|
|
34
|
+
export async function nodeView(transport, target) {
|
|
35
|
+
const [genesis, account, announcer] = await Promise.all([transport.genesisHash(), transport.getAccount(target.intent), announcerOf(transport, target)]);
|
|
36
|
+
return { genesis, intent: account === null ? NO_ACCOUNT : `sha256 ${await digestOf(account.data)}`, announcer };
|
|
37
|
+
}
|
|
38
|
+
const reasonOf = (error) => (error instanceof Error ? error.message : String(error));
|
|
39
|
+
export async function confirmOnBoth(first, second, target) {
|
|
40
|
+
const [own, other] = await Promise.all([
|
|
41
|
+
nodeView(first, target),
|
|
42
|
+
nodeView(second, target).catch((error) => {
|
|
43
|
+
throw new ConfirmMismatch("second node", "read", `unreadable: ${reasonOf(error)}`);
|
|
44
|
+
}),
|
|
45
|
+
]);
|
|
46
|
+
if (own.genesis !== other.genesis) {
|
|
47
|
+
throw new ConfirmMismatch("genesis hash", own.genesis, other.genesis);
|
|
48
|
+
}
|
|
49
|
+
if (own.intent !== other.intent) {
|
|
50
|
+
throw new ConfirmMismatch("intent account", own.intent, other.intent);
|
|
51
|
+
}
|
|
52
|
+
if (own.announcer !== other.announcer || own.announcer === INCOMPLETE_RECORD) {
|
|
53
|
+
throw new ConfirmMismatch("earliest announcer", own.announcer ?? NO_ANNOUNCER, other.announcer ?? NO_ANNOUNCER);
|
|
54
|
+
}
|
|
55
|
+
const worker = own.announcer?.split(" ")[0];
|
|
56
|
+
if (target.payees !== undefined && own.announcer !== undefined && !target.payees.some((payee) => payee === worker)) {
|
|
57
|
+
throw new ConfirmMismatch("payee", target.payees.join(", "), own.announcer);
|
|
58
|
+
}
|
|
59
|
+
return own;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=confirm-release.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confirm-release.js","sourceRoot":"","sources":["../../src/confirm-release.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AASpE,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAC;AA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eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
export * from "./accounts.js";
|
|
2
2
|
export * from "./budget.js";
|
|
3
3
|
export * from "./client.js";
|
|
4
|
+
export * from "./confirm-release.js";
|
|
4
5
|
export * from "./errors.js";
|
|
5
6
|
export * from "./jobs.js";
|
|
7
|
+
export * from "./ledger.js";
|
|
8
|
+
export * from "./public-host.js";
|
|
6
9
|
export * from "./reputation.js";
|
|
7
10
|
export * from "./setup.js";
|
|
8
11
|
export * from "./simple.js";
|
package/dist/src/index.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
export * from "./accounts.js";
|
|
2
2
|
export * from "./budget.js";
|
|
3
3
|
export * from "./client.js";
|
|
4
|
+
export * from "./confirm-release.js";
|
|
4
5
|
export * from "./errors.js";
|
|
5
6
|
export * from "./jobs.js";
|
|
7
|
+
export * from "./ledger.js";
|
|
8
|
+
export * from "./public-host.js";
|
|
6
9
|
export * from "./reputation.js";
|
|
7
10
|
export * from "./setup.js";
|
|
8
11
|
export * from "./simple.js";
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC"}
|
package/dist/src/job-specs.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Address } from "@solana/kit";
|
|
2
|
+
import { type Lookup } from "./public-host.js";
|
|
2
3
|
import { type Transport } from "./transport.js";
|
|
3
4
|
export declare const SPEC_SCAN = 10;
|
|
4
5
|
export declare const MAINNET_GENESIS_HASH = "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d";
|
|
@@ -8,6 +9,8 @@ export declare const PUBLIC_GENESIS_HASHES: ReadonlySet<string>;
|
|
|
8
9
|
export declare const MAX_SPEC_BYTES = 1048576;
|
|
9
10
|
export declare const SPEC_TIMEOUT_MS = 10000;
|
|
10
11
|
export declare const PLAIN_HTTP_ON_PUBLIC = "is a plain http url, which a public cluster may not use";
|
|
12
|
+
export declare const NOT_HTTP = "is not an http or https url";
|
|
13
|
+
export declare const NOT_PUBLIC_SPEC = "points to a private, loopback or local network address, which a public cluster does not fetch";
|
|
11
14
|
export declare function plainHttpOnPublic(transport: Transport, url: string): Promise<boolean>;
|
|
12
15
|
export type Job = {
|
|
13
16
|
intent: Address;
|
|
@@ -44,4 +47,4 @@ export declare class SpecUnreadable extends Error {
|
|
|
44
47
|
}
|
|
45
48
|
export declare function specUrlOf(transport: Transport, intent: Address, createdAt?: bigint): Promise<string | null>;
|
|
46
49
|
export declare function jobsOf(transport: Transport, attestor?: Address): Promise<Job[]>;
|
|
47
|
-
export declare function readSpec(transport: Transport, get: SpecFetch, intent: Address, keypair?: Uint8Array): Promise<Spec | null>;
|
|
50
|
+
export declare function readSpec(transport: Transport, get: SpecFetch, intent: Address, keypair?: Uint8Array, lookup?: Lookup): Promise<Spec | null>;
|
package/dist/src/job-specs.js
CHANGED
|
@@ -2,6 +2,7 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { isSealed, NotInvited, parseSpecMemo, remainingOf, SPEC_MEMO_PREFIX, sealedTo, unseal } from "@intent-engine/core";
|
|
3
3
|
import { createdIn, hex, openProofEscrows, proofAt } from "./job-proofs.js";
|
|
4
4
|
import { MEMOS_PER_TRANSACTION, scan } from "./job-scan.js";
|
|
5
|
+
import { publicHost, systemLookup } from "./public-host.js";
|
|
5
6
|
import { TRANSACTION_FETCHES } from "./transport.js";
|
|
6
7
|
export const SPEC_SCAN = 10;
|
|
7
8
|
export const MAINNET_GENESIS_HASH = "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d";
|
|
@@ -11,6 +12,8 @@ export const PUBLIC_GENESIS_HASHES = new Set([MAINNET_GENESIS_HASH, DEVNET_GENES
|
|
|
11
12
|
export const MAX_SPEC_BYTES = 1_048_576;
|
|
12
13
|
export const SPEC_TIMEOUT_MS = 10_000;
|
|
13
14
|
export const PLAIN_HTTP_ON_PUBLIC = "is a plain http url, which a public cluster may not use";
|
|
15
|
+
export const NOT_HTTP = "is not an http or https url";
|
|
16
|
+
export const NOT_PUBLIC_SPEC = "points to a private, loopback or local network address, which a public cluster does not fetch";
|
|
14
17
|
export async function plainHttpOnPublic(transport, url) {
|
|
15
18
|
let protocol;
|
|
16
19
|
try {
|
|
@@ -100,7 +103,7 @@ async function bounded(response, url) {
|
|
|
100
103
|
}
|
|
101
104
|
return Buffer.concat(chunks);
|
|
102
105
|
}
|
|
103
|
-
export async function readSpec(transport, get, intent, keypair) {
|
|
106
|
+
export async function readSpec(transport, get, intent, keypair, lookup = systemLookup) {
|
|
104
107
|
const proof = await proofAt(transport, intent);
|
|
105
108
|
if (proof === null) {
|
|
106
109
|
return null;
|
|
@@ -109,9 +112,22 @@ export async function readSpec(transport, get, intent, keypair) {
|
|
|
109
112
|
if (url === null) {
|
|
110
113
|
return null;
|
|
111
114
|
}
|
|
115
|
+
let parsed;
|
|
116
|
+
try {
|
|
117
|
+
parsed = new URL(url);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
throw new SpecUnreadable(url, "is not a url");
|
|
121
|
+
}
|
|
122
|
+
if (parsed.protocol !== "https:" && parsed.protocol !== "http:") {
|
|
123
|
+
throw new SpecUnreadable(url, NOT_HTTP);
|
|
124
|
+
}
|
|
112
125
|
if (await plainHttpOnPublic(transport, url)) {
|
|
113
126
|
throw new SpecUnreadable(url, PLAIN_HTTP_ON_PUBLIC);
|
|
114
127
|
}
|
|
128
|
+
if (PUBLIC_GENESIS_HASHES.has(await transport.genesisHash()) && !(await publicHost(parsed.hostname, lookup))) {
|
|
129
|
+
throw new SpecUnreadable(url, NOT_PUBLIC_SPEC);
|
|
130
|
+
}
|
|
115
131
|
const fetched = await bounded(await get(url, { redirect: "error", signal: AbortSignal.timeout(SPEC_TIMEOUT_MS) }), url);
|
|
116
132
|
let bytes = fetched;
|
|
117
133
|
let to = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"job-specs.js","sourceRoot":"","sources":["../../src/job-specs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC3H,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAA0B,mBAAmB,EAAkB,MA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AAM,EAAE,OAAO,EAAE,MAAM,KAAK,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;AAC1J,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type TransactionPartialSigner } from "@solana/kit";
|
|
2
|
+
export declare const LEDGER_FORMS: string[];
|
|
3
|
+
export declare const LEDGER_ERRORS: {
|
|
4
|
+
readonly notFound: "no Ledger was found: plug it in, unlock it, open the Solana app and run the command again; nothing was sent";
|
|
5
|
+
readonly locked: "the Ledger is locked: unlock it with its PIN, open the Solana app and run the command again; nothing was sent";
|
|
6
|
+
readonly noApp: "the Solana app is not open on the Ledger: open it and run the command again; nothing was sent";
|
|
7
|
+
readonly blindSigning: "blind signing is disabled in the Ledger's Solana app: enable it in the app's settings, since Squads instructions need it, and run the command again; nothing was sent";
|
|
8
|
+
readonly rejected: "the transaction was rejected on the Ledger; nothing was sent";
|
|
9
|
+
readonly missing: "signing with a Ledger needs @ledgerhq/hw-app-solana@7.12.0 and @ledgerhq/hw-transport-node-hid-noevents@6.36.0, which are not installed: install both where intent-engine is installed and run the command again; nothing was sent";
|
|
10
|
+
readonly driver: "the USB driver node-hid is not built in this checkout: build it as docs/maintainers/operations.md shows under Signing with a Ledger and run the command again; nothing was sent";
|
|
11
|
+
};
|
|
12
|
+
export declare class LedgerPathError extends Error {
|
|
13
|
+
}
|
|
14
|
+
export declare class LedgerError extends Error {
|
|
15
|
+
}
|
|
16
|
+
export type LedgerPath = {
|
|
17
|
+
account?: number;
|
|
18
|
+
change?: number;
|
|
19
|
+
derivation: string;
|
|
20
|
+
};
|
|
21
|
+
export type LedgerTransport = {
|
|
22
|
+
close(): Promise<void>;
|
|
23
|
+
};
|
|
24
|
+
export type OpenTransport = () => Promise<LedgerTransport>;
|
|
25
|
+
export type DeviceSigner = TransactionPartialSigner & {
|
|
26
|
+
readonly device: string;
|
|
27
|
+
};
|
|
28
|
+
export declare function ledgerModule(name: string, resolve?: (name: string) => unknown): unknown;
|
|
29
|
+
export declare const isLedgerPath: (text: string) => boolean;
|
|
30
|
+
export declare const isDevice: (signer: TransactionPartialSigner) => signer is DeviceSigner;
|
|
31
|
+
export declare const messageHash: (message: Uint8Array) => string;
|
|
32
|
+
export declare function parseLedgerPath(text: string): LedgerPath;
|
|
33
|
+
export declare const openUsb: OpenTransport;
|
|
34
|
+
export declare function plainLedgerError(error: unknown): LedgerError;
|
|
35
|
+
export declare function ledgerSigner(text: string, open?: OpenTransport): Promise<DeviceSigner>;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { getAddressDecoder, getBase58Decoder, getPublicKeyFromAddress, verifySignature, } from "@solana/kit";
|
|
4
|
+
export const LEDGER_FORMS = ["usb://ledger", "usb://ledger?key=<account>", "usb://ledger?key=<account>/<change>"];
|
|
5
|
+
export const LEDGER_ERRORS = {
|
|
6
|
+
notFound: "no Ledger was found: plug it in, unlock it, open the Solana app and run the command again; nothing was sent",
|
|
7
|
+
locked: "the Ledger is locked: unlock it with its PIN, open the Solana app and run the command again; nothing was sent",
|
|
8
|
+
noApp: "the Solana app is not open on the Ledger: open it and run the command again; nothing was sent",
|
|
9
|
+
blindSigning: "blind signing is disabled in the Ledger's Solana app: enable it in the app's settings, since Squads instructions need it, and run the command again; nothing was sent",
|
|
10
|
+
rejected: "the transaction was rejected on the Ledger; nothing was sent",
|
|
11
|
+
missing: "signing with a Ledger needs @ledgerhq/hw-app-solana@7.12.0 and @ledgerhq/hw-transport-node-hid-noevents@6.36.0, which are not installed: install both where intent-engine is installed and run the command again; nothing was sent",
|
|
12
|
+
driver: "the USB driver node-hid is not built in this checkout: build it as docs/maintainers/operations.md shows under Signing with a Ledger and run the command again; nothing was sent",
|
|
13
|
+
};
|
|
14
|
+
const LOCKED = new Set([0x5515, 0x6982]);
|
|
15
|
+
const NO_APP = new Set([0x6e00, 0x6e01, 0x6d00, 0x6d02, 0x6511, 0x650f]);
|
|
16
|
+
const REJECTED = 0x6985;
|
|
17
|
+
const BLIND_SIGNING = 0x6808;
|
|
18
|
+
const MAX_INDEX = 2 ** 31 - 1;
|
|
19
|
+
const ADDRESS_BYTES = 32;
|
|
20
|
+
const SIGNATURE_BYTES = 64;
|
|
21
|
+
export class LedgerPathError extends Error {
|
|
22
|
+
}
|
|
23
|
+
export class LedgerError extends Error {
|
|
24
|
+
}
|
|
25
|
+
const required = createRequire(import.meta.url);
|
|
26
|
+
export function ledgerModule(name, resolve = required) {
|
|
27
|
+
try {
|
|
28
|
+
return resolve(name);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (error.code === "MODULE_NOT_FOUND") {
|
|
32
|
+
throw new LedgerError(LEDGER_ERRORS.missing);
|
|
33
|
+
}
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const load = (name) => ledgerModule(name);
|
|
38
|
+
export const isLedgerPath = (text) => text.startsWith("usb://");
|
|
39
|
+
export const isDevice = (signer) => "device" in signer && typeof signer.device === "string";
|
|
40
|
+
export const messageHash = (message) => getBase58Decoder().decode(createHash("sha256").update(message).digest());
|
|
41
|
+
function index(text, path) {
|
|
42
|
+
if (text === undefined) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
const value = Number(text);
|
|
46
|
+
if (value > MAX_INDEX) {
|
|
47
|
+
throw new LedgerPathError(`${path} names an index above ${MAX_INDEX}; use ${LEDGER_FORMS.join(", ")}`);
|
|
48
|
+
}
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
export function parseLedgerPath(text) {
|
|
52
|
+
const match = /^usb:\/\/ledger(?:\?key=(0|[1-9]\d{0,9})(?:\/(0|[1-9]\d{0,9}))?)?$/.exec(text);
|
|
53
|
+
if (match === null) {
|
|
54
|
+
throw new LedgerPathError(`${text} is not a Ledger path; use ${LEDGER_FORMS.join(", ")}`);
|
|
55
|
+
}
|
|
56
|
+
const account = index(match[1], text);
|
|
57
|
+
const change = index(match[2], text);
|
|
58
|
+
const levels = ["44'", "501'", ...[account, change].filter((n) => n !== undefined).map((n) => `${n}'`)];
|
|
59
|
+
return { ...(account === undefined ? {} : { account }), ...(change === undefined ? {} : { change }), derivation: levels.join("/") };
|
|
60
|
+
}
|
|
61
|
+
export const openUsb = async () => {
|
|
62
|
+
const hid = load("@ledgerhq/hw-transport-node-hid-noevents");
|
|
63
|
+
return hid.default.open("");
|
|
64
|
+
};
|
|
65
|
+
const appOn = (transport) => {
|
|
66
|
+
const Solana = load("@ledgerhq/hw-app-solana").default;
|
|
67
|
+
return new Solana(transport);
|
|
68
|
+
};
|
|
69
|
+
const detail = (error) => {
|
|
70
|
+
const found = (error ?? {});
|
|
71
|
+
return {
|
|
72
|
+
...(typeof found.statusCode === "number" ? { status: found.statusCode } : {}),
|
|
73
|
+
...(typeof found.id === "string" ? { id: found.id } : {}),
|
|
74
|
+
message: typeof found.message === "string" ? found.message : String(error),
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
export function plainLedgerError(error) {
|
|
78
|
+
if (error instanceof LedgerError) {
|
|
79
|
+
return error;
|
|
80
|
+
}
|
|
81
|
+
const { status, id, message } = detail(error);
|
|
82
|
+
if (status === REJECTED) {
|
|
83
|
+
return new LedgerError(LEDGER_ERRORS.rejected);
|
|
84
|
+
}
|
|
85
|
+
if (status === BLIND_SIGNING || /blind signature/i.test(message)) {
|
|
86
|
+
return new LedgerError(LEDGER_ERRORS.blindSigning);
|
|
87
|
+
}
|
|
88
|
+
if (status !== undefined && LOCKED.has(status)) {
|
|
89
|
+
return new LedgerError(LEDGER_ERRORS.locked);
|
|
90
|
+
}
|
|
91
|
+
if (status !== undefined && NO_APP.has(status)) {
|
|
92
|
+
return new LedgerError(LEDGER_ERRORS.noApp);
|
|
93
|
+
}
|
|
94
|
+
if (/bindings file|HID_hidraw|HID\.node/.test(message)) {
|
|
95
|
+
return new LedgerError(LEDGER_ERRORS.driver);
|
|
96
|
+
}
|
|
97
|
+
if (id === "NoDevice" || /no ?device|could not open|cannot open device/i.test(message)) {
|
|
98
|
+
return new LedgerError(LEDGER_ERRORS.notFound);
|
|
99
|
+
}
|
|
100
|
+
if (status !== undefined) {
|
|
101
|
+
return new LedgerError(`the Ledger answered with status 0x${status.toString(16).padStart(4, "0")}; nothing was sent`);
|
|
102
|
+
}
|
|
103
|
+
return new LedgerError(`the Ledger could not be used: ${message}; nothing was sent`);
|
|
104
|
+
}
|
|
105
|
+
async function session(open, use) {
|
|
106
|
+
let transport;
|
|
107
|
+
try {
|
|
108
|
+
transport = await open();
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
throw plainLedgerError(error);
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
return await use(appOn(transport));
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
throw plainLedgerError(error);
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
await transport.close().catch(() => undefined);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async function signed(signer, signature, message) {
|
|
124
|
+
const bytes = new Uint8Array(signature);
|
|
125
|
+
const valid = bytes.length === SIGNATURE_BYTES && (await verifySignature(await getPublicKeyFromAddress(signer), bytes, message));
|
|
126
|
+
if (!valid) {
|
|
127
|
+
throw new LedgerError(`the Ledger returned a signature that does not verify for ${signer}; nothing was sent`);
|
|
128
|
+
}
|
|
129
|
+
return bytes;
|
|
130
|
+
}
|
|
131
|
+
export async function ledgerSigner(text, open = openUsb) {
|
|
132
|
+
const { derivation } = parseLedgerPath(text);
|
|
133
|
+
const key = await session(open, async (app) => {
|
|
134
|
+
await app.getAppConfiguration();
|
|
135
|
+
return new Uint8Array((await app.getAddress(derivation)).address);
|
|
136
|
+
});
|
|
137
|
+
if (key.length !== ADDRESS_BYTES) {
|
|
138
|
+
throw new LedgerError(`the Ledger returned no ${ADDRESS_BYTES} byte address for ${text}; nothing was sent`);
|
|
139
|
+
}
|
|
140
|
+
const address = getAddressDecoder().decode(key);
|
|
141
|
+
const signer = {
|
|
142
|
+
address,
|
|
143
|
+
device: text,
|
|
144
|
+
signTransactions: async (transactions) => {
|
|
145
|
+
const out = [];
|
|
146
|
+
for (const transaction of transactions) {
|
|
147
|
+
const message = new Uint8Array(transaction.messageBytes);
|
|
148
|
+
const signature = await session(open, async (app) => {
|
|
149
|
+
if (!(await app.getAppConfiguration()).blindSigningEnabled) {
|
|
150
|
+
throw new LedgerError(LEDGER_ERRORS.blindSigning);
|
|
151
|
+
}
|
|
152
|
+
return (await app.signTransaction(derivation, Buffer.from(message))).signature;
|
|
153
|
+
});
|
|
154
|
+
out.push(Object.freeze({ [address]: await signed(address, signature, message) }));
|
|
155
|
+
}
|
|
156
|
+
return out;
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
return Object.freeze(signer);
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=ledger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger.js","sourceRoot":"","sources":["../../src/ledger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAEL,iBAAiB,EACjB,gBAAgB,EAChB,uBAAuB,EAIvB,eAAe,GAChB,MAAM,aAAa,CAAC;AAErB,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,cAAc,EAAE,4BAA4B,EAAE,qCAAqC,CAAC,CAAC;AAElH,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,QAAQ,EAAE,6GAA6G;IACvH,MAAM,EAAE,+GAA+G;IACvH,KAAK,EAAE,+FAA+F;IACtG,YAAY,EA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AAC,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;gBACjF,CAAC,CAAC,CAAC;gBACH,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,MAAM,MAAM,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;YACpF,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC;KACF,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { lookup as dnsLookup } from "node:dns/promises";
|
|
2
|
+
import { isIP } from "node:net";
|
|
3
|
+
export const systemLookup = async (host) => (await dnsLookup(host, { all: true, verbatim: true })).map((found) => found.address);
|
|
4
|
+
const V4_PRIVATE = [
|
|
5
|
+
[0x00000000, 8],
|
|
6
|
+
[0x0a000000, 8],
|
|
7
|
+
[0x64400000, 10],
|
|
8
|
+
[0x7f000000, 8],
|
|
9
|
+
[0xa9fe0000, 16],
|
|
10
|
+
[0xac100000, 12],
|
|
11
|
+
[0xc0000000, 24],
|
|
12
|
+
[0xc0000200, 24],
|
|
13
|
+
[0xc0a80000, 16],
|
|
14
|
+
[0xc6120000, 15],
|
|
15
|
+
[0xc6336400, 24],
|
|
16
|
+
[0xcb007100, 24],
|
|
17
|
+
[0xe0000000, 4],
|
|
18
|
+
[0xf0000000, 4],
|
|
19
|
+
];
|
|
20
|
+
function v4Number(ip) {
|
|
21
|
+
const parts = ip.split(".").map(Number);
|
|
22
|
+
if (parts.length !== 4 || parts.some((p) => !Number.isInteger(p) || p < 0 || p > 255)) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
return parts.reduce((n, p) => n * 256 + p, 0);
|
|
26
|
+
}
|
|
27
|
+
function privateV4(ip) {
|
|
28
|
+
const n = v4Number(ip);
|
|
29
|
+
if (n === null) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
return V4_PRIVATE.some(([base, bits]) => Math.floor(n / 2 ** (32 - bits)) === Math.floor(base / 2 ** (32 - bits)));
|
|
33
|
+
}
|
|
34
|
+
function v6Groups(ip) {
|
|
35
|
+
let text = ip.toLowerCase();
|
|
36
|
+
const tail = /(\d+\.\d+\.\d+\.\d+)$/.exec(text);
|
|
37
|
+
let extra = [];
|
|
38
|
+
if (tail !== null) {
|
|
39
|
+
const n = v4Number(tail[1] ?? "");
|
|
40
|
+
if (n === null) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
extra = [Math.floor(n / 65536), n % 65536];
|
|
44
|
+
text = text.slice(0, -(tail[1] ?? "").length);
|
|
45
|
+
if (!text.endsWith("::")) {
|
|
46
|
+
text = text.replace(/:$/, "");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const halves = text.split("::");
|
|
50
|
+
if (halves.length > 2) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const parse = (part) => (part === "" ? [] : part.split(":").map((g) => Number.parseInt(g, 16)));
|
|
54
|
+
const head = parse(halves[0] ?? "");
|
|
55
|
+
const rest = halves.length === 2 ? parse(halves[1] ?? "") : [];
|
|
56
|
+
const known = head.length + rest.length + extra.length;
|
|
57
|
+
if (halves.length === 1 && known !== 8) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
const groups = [...head, ...new Array(halves.length === 2 ? 8 - known : 0).fill(0), ...rest, ...extra];
|
|
61
|
+
return groups.length === 8 && groups.every((g) => Number.isInteger(g) && g >= 0 && g <= 0xffff) ? groups : null;
|
|
62
|
+
}
|
|
63
|
+
function privateV6(ip) {
|
|
64
|
+
const g = v6Groups(ip);
|
|
65
|
+
if (g === null) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
const [a = 0, b = 0, , , , f = 0, x = 0, y = 0] = g;
|
|
69
|
+
if (g.slice(0, 5).every((v) => v === 0) && f === 0xffff) {
|
|
70
|
+
return privateV4(`${x >> 8}.${x & 255}.${y >> 8}.${y & 255}`);
|
|
71
|
+
}
|
|
72
|
+
if (g.every((v) => v === 0) || (g.slice(0, 7).every((v) => v === 0) && y === 1)) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
return (a & 0xfe00) === 0xfc00 || (a & 0xffc0) === 0xfe80 || (a & 0xff00) === 0xff00 || (a === 0x2001 && b === 0x0db8) || (a === 0x0064 && b === 0xff9b);
|
|
76
|
+
}
|
|
77
|
+
export function privateAddress(ip) {
|
|
78
|
+
const family = isIP(ip);
|
|
79
|
+
if (family === 4) {
|
|
80
|
+
return privateV4(ip);
|
|
81
|
+
}
|
|
82
|
+
if (family === 6) {
|
|
83
|
+
return privateV6(ip);
|
|
84
|
+
}
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
export async function publicHost(hostname, lookup) {
|
|
88
|
+
const host = hostname.replace(/^\[/, "").replace(/\]$/, "");
|
|
89
|
+
let addresses;
|
|
90
|
+
try {
|
|
91
|
+
addresses = isIP(host) === 0 ? await lookup(host) : [host];
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
return addresses.length > 0 && !addresses.some(privateAddress);
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=public-host.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public-host.js","sourceRoot":"","sources":["../../src/public-host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAIhC,MAAM,CAAC,MAAM,YAAY,GAAW,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,MAAM,SAAS,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ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AAC,KAAK,MAAM,IAAI,CAAC,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,MAAM,IAAI,CAAC,KAAK,MAAM,CAAC,CAAC;AAC3J,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,EAAU;IACvC,MAAM,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;IACxB,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC;QACjB,OAAO,SAAS,CAAC,EAAE,CAAC,CAAC;IACvB,CAAC;IACD,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC;QACjB,OAAO,SAAS,CAAC,EAAE,CAAC,CAAC;IACvB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,QAAgB,EAAE,MAAc;IAC/D,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC5D,IAAI,SAAmB,CAAC;IACxB,IAAI,CAAC;QACH,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAC7D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;AACjE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intent-engine/client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.39",
|
|
4
4
|
"description": "Runtime client for the intent engine on Solana: transport, confirmation, account readers and intent notifications",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -38,17 +38,27 @@
|
|
|
38
38
|
"@solana-program/system": "0.14.1",
|
|
39
39
|
"@solana-program/token": "0.16.1",
|
|
40
40
|
"@solana/kit": "8.4.0",
|
|
41
|
-
"@intent-engine/core": "0.1.
|
|
41
|
+
"@intent-engine/core": "0.1.39"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
+
"@ledgerhq/hw-app-solana": "7.12.0",
|
|
45
|
+
"@ledgerhq/hw-transport-node-hid-noevents": "6.36.0",
|
|
44
46
|
"litesvm": "^1.5.0"
|
|
45
47
|
},
|
|
46
48
|
"peerDependenciesMeta": {
|
|
49
|
+
"@ledgerhq/hw-app-solana": {
|
|
50
|
+
"optional": true
|
|
51
|
+
},
|
|
52
|
+
"@ledgerhq/hw-transport-node-hid-noevents": {
|
|
53
|
+
"optional": true
|
|
54
|
+
},
|
|
47
55
|
"litesvm": {
|
|
48
56
|
"optional": true
|
|
49
57
|
}
|
|
50
58
|
},
|
|
51
59
|
"devDependencies": {
|
|
60
|
+
"@ledgerhq/hw-app-solana": "7.12.0",
|
|
61
|
+
"@ledgerhq/hw-transport-node-hid-noevents": "6.36.0",
|
|
52
62
|
"@types/node": "26.6.4",
|
|
53
63
|
"litesvm": "1.5.0",
|
|
54
64
|
"typescript": "7.0.2",
|