liqproof 0.0.0-stage → 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/README.md +536 -2
- package/bugs/README.md +144 -0
- package/bugs/coin-gecko-liquidity-report.md +283 -0
- package/bugs/collect-ds-aggregate.mjs +213 -0
- package/bugs/collect-evidence.mjs +458 -0
- package/bugs/collect-gt-aggregate.mjs +215 -0
- package/bugs/collect-raw-rpc.mjs +165 -0
- package/bugs/collect-sweep-context.mjs +162 -0
- package/bugs/dexscreener-fake-liquidity-report.md +310 -0
- package/bugs/evidence/aggregator-liquidity-claims.json +648 -0
- package/bugs/evidence/aggregator-liquidity-claims.md +103 -0
- package/bugs/evidence/bat-native-pool-drained.json +136 -0
- package/bugs/evidence/bat-native-pool-drained.md +51 -0
- package/bugs/evidence/chz-impersonator-pool-drained.json +136 -0
- package/bugs/evidence/chz-impersonator-pool-drained.md +51 -0
- package/bugs/evidence/gt-stale-reserve-after-drain.json +141 -0
- package/bugs/evidence/gt-stale-reserve-after-drain.md +31 -0
- package/bugs/evidence/raw-rpc-transcript.json +683 -0
- package/bugs/evidence/raw-rpc-transcript.md +308 -0
- package/bugs/evidence/sweep-context.json +325 -0
- package/bugs/evidence/sweep-context.md +55 -0
- package/bugs/evidence/verified-aggregate.json +526 -0
- package/bugs/evidence/verified-aggregate.md +24 -0
- package/bugs/evidence/verified-ds-liquidity-usd.json +1197 -0
- package/bugs/evidence/verified-ds-liquidity-usd.md +250 -0
- package/bugs/evidence/verified-gt-reserve-in-usd.json +1002 -0
- package/bugs/evidence/verified-gt-reserve-in-usd.md +218 -0
- package/bugs/fix-bundle-titles.mjs +72 -0
- package/bugs/geckoterminal-stale-reserve-after-drain.md +137 -0
- package/data/dataset-summary.md +103 -0
- package/data/impersonators.json +12888 -0
- package/data/verified-impersonators.json +725 -0
- package/data/wallets.json +23 -0
- package/dist/base58.js +70 -0
- package/dist/base58.js.map +1 -0
- package/dist/canonical.js +372 -0
- package/dist/canonical.js.map +1 -0
- package/dist/cli.js +830 -0
- package/dist/cli.js.map +1 -0
- package/dist/curve.js +255 -0
- package/dist/curve.js.map +1 -0
- package/dist/dashboard.js +485 -0
- package/dist/dashboard.js.map +1 -0
- package/dist/keccak.js +197 -0
- package/dist/keccak.js.map +1 -0
- package/dist/mcp.js +604 -0
- package/dist/mcp.js.map +1 -0
- package/dist/operator.js +180 -0
- package/dist/operator.js.map +1 -0
- package/dist/pda.js +86 -0
- package/dist/pda.js.map +1 -0
- package/dist/receipt.js +897 -0
- package/dist/receipt.js.map +1 -0
- package/dist/render.js +335 -0
- package/dist/render.js.map +1 -0
- package/dist/rpc.js +377 -0
- package/dist/rpc.js.map +1 -0
- package/dist/sources.js +599 -0
- package/dist/sources.js.map +1 -0
- package/dist/store.js +330 -0
- package/dist/store.js.map +1 -0
- package/dist/tokenmeta.js +424 -0
- package/dist/tokenmeta.js.map +1 -0
- package/dist/util.js +273 -0
- package/dist/util.js.map +1 -0
- package/dist/vaults.js +510 -0
- package/dist/vaults.js.map +1 -0
- package/dist/wallet.js +404 -0
- package/dist/wallet.js.map +1 -0
- package/dist/warnings.js +41 -0
- package/dist/warnings.js.map +1 -0
- package/dist/worker.js +857 -0
- package/dist/worker.js.map +1 -0
- package/dist/x402.js +549 -0
- package/dist/x402.js.map +1 -0
- package/docs/HACKATHON-SUBMISSION.md +264 -0
- package/docs/liqproof-plan.md +221 -0
- package/docs/llms.txt +32 -0
- package/docs/mcp-registry.md +165 -0
- package/docs/screenshots/01-dashboard.png +0 -0
- package/docs/screenshots/02-receipt-drained.png +0 -0
- package/docs/screenshots/03-receipt-impersonator.png +0 -0
- package/docs/screenshots/04-receipt-canonical.png +0 -0
- package/docs/x402-pricing.md +171 -0
- package/docs/zero-xyz.md +250 -0
- package/out/6eftxVbSAunVEoxUWdGhPdxg5UdsJ8Wkwy5w5YFuxouw.json +1171 -0
- package/out/6eftxVbSAunVEoxUWdGhPdxg5UdsJ8Wkwy5w5YFuxouw.md +52 -0
- package/out/6eftxVbSAunVEoxUWdGhPdxg5UdsJ8Wkwy5w5YFuxouw.svg +25 -0
- package/out/BTNiaZb6HaEFWeEtND4SXtZ7T6mgtDwSryHTAj6PuPyp.json +3975 -0
- package/out/BTNiaZb6HaEFWeEtND4SXtZ7T6mgtDwSryHTAj6PuPyp.md +90 -0
- package/out/BTNiaZb6HaEFWeEtND4SXtZ7T6mgtDwSryHTAj6PuPyp.svg +25 -0
- package/out/ENGkoidj2jNs73A7GZuseVmnkRg6EVF9tDtViwPz8o85.json +1446 -0
- package/out/ENGkoidj2jNs73A7GZuseVmnkRg6EVF9tDtViwPz8o85.md +66 -0
- package/out/ENGkoidj2jNs73A7GZuseVmnkRg6EVF9tDtViwPz8o85.svg +25 -0
- package/out/dataset.csv +67 -0
- package/out/impersonation-table.md +156 -0
- package/out/index.html +1179 -0
- package/package.json +78 -4
- package/scripts/assert-no-canonical-accusations.mjs +193 -0
- package/scripts/backfill.mjs +1063 -0
- package/scripts/bundle-evidence.mjs +237 -0
- package/scripts/bundle-stale-claim.mjs +417 -0
- package/scripts/capture-bch-evidence.mjs +58 -0
- package/scripts/check-orientation-fix.mjs +40 -0
- package/scripts/check-wallet.mjs +54 -0
- package/scripts/daily-refresh.mjs +451 -0
- package/scripts/decode-clmm-vaults.mjs +180 -0
- package/scripts/falsifiability.mjs +263 -0
- package/scripts/impersonator-mining.mjs +156 -0
- package/scripts/inspect-matches.mjs +73 -0
- package/scripts/operator-sweep.mjs +252 -0
- package/scripts/publish-release.mjs +248 -0
- package/scripts/refresh-store.mjs +78 -0
- package/scripts/survival-miner.mjs +951 -0
- package/scripts/test-keccak.mjs +103 -0
- package/scripts/verify-bch-1p95b.mjs +124 -0
- package/scripts/verify-clmm-1p95b.mjs +127 -0
- package/scripts/verify-clmm-control.mjs +84 -0
- package/scripts/verify-impersonators.mjs +138 -0
- package/scripts/verify-raw.mjs +110 -0
- package/scripts/verify-raw2.mjs +99 -0
- package/server.json +34 -0
- package/src/base58.ts +68 -0
- package/src/canonical.ts +447 -0
- package/src/cli.ts +941 -0
- package/src/curve.ts +349 -0
- package/src/dashboard.ts +504 -0
- package/src/keccak.ts +228 -0
- package/src/mcp.ts +735 -0
- package/src/operator.ts +219 -0
- package/src/receipt.ts +1219 -0
- package/src/render.ts +396 -0
- package/src/rpc.ts +435 -0
- package/src/sources.ts +714 -0
- package/src/store.ts +428 -0
- package/src/tokenmeta.ts +460 -0
- package/src/util.ts +276 -0
- package/src/vaults.ts +574 -0
- package/src/wallet.ts +459 -0
- package/src/warnings.ts +40 -0
- package/src/worker.ts +1086 -0
- package/src/x402.ts +717 -0
package/dist/operator.js
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* operator.ts — link tokens to the wallet that deployed them.
|
|
3
|
+
*
|
|
4
|
+
* ── WHAT THIS IS, AND WHAT IT IS NOT ───────────────────────────────────────
|
|
5
|
+
*
|
|
6
|
+
* Metaplex metadata records who created a token: a list of creator wallets
|
|
7
|
+
* with a share and a "verified" flag. For an honest project that list is
|
|
8
|
+
* whatever the team decided. But when the SAME creator wallet appears on
|
|
9
|
+
* many tokens, the list stops being a credit and becomes a lineage.
|
|
10
|
+
*
|
|
11
|
+
* We scanned 9,053 Solana mints and found 212 creator clusters. The largest
|
|
12
|
+
* ones look like this:
|
|
13
|
+
*
|
|
14
|
+
* JARrYgBJt2bL… 1,243 tokens Aave, Arcium, AgriDex, Access Protocol…
|
|
15
|
+
* 7jMmecogKC9… 531 tokens BAT impostor, "Litecoin" impostor,…
|
|
16
|
+
* 7jMmrEsTS6… 141 tokens AC Milan, Arsenal FC, Atlético Madrid…
|
|
17
|
+
*
|
|
18
|
+
* ── THE HONEST READING ─────────────────────────────────────────────────────
|
|
19
|
+
*
|
|
20
|
+
* The first and third rows are LEGITIMATE. A token launchpad deploys
|
|
21
|
+
* hundreds of tokens with one creator wallet; a bridge sets itself as
|
|
22
|
+
* creator; Chiliz issues football-club fan tokens from a single deployer.
|
|
23
|
+
* In the 9,053-mint sweep, the "Aave" token in the JARrYg cluster, the
|
|
24
|
+
* "Arcium" token and the "AgriDex" token are three unrelated, real
|
|
25
|
+
* projects sharing one creator.
|
|
26
|
+
*
|
|
27
|
+
* **A shared creator wallet is therefore NOT evidence of a fraud ring.** We
|
|
28
|
+
* measured this and we were about to publish the opposite. Any tool that
|
|
29
|
+
* claims otherwise would be crying wolf on every launchpad in the market.
|
|
30
|
+
*
|
|
31
|
+
* So this module NEVER makes an accusation. It produces a LINEAGE: "this
|
|
32
|
+
* token was deployed by the same wallet as these N other tokens". The
|
|
33
|
+
* accusation, when there is one, comes from the canonical resolver
|
|
34
|
+
* (src/canonical.ts) — which cites the genuine mint — combined with the
|
|
35
|
+
* on-chain liquidity evidence (src/receipt.ts). The lineage only ever
|
|
36
|
+
* says: these tokens share a deployer.
|
|
37
|
+
*
|
|
38
|
+
* The combination is what is strong. "This mint claims to be Chiliz, and
|
|
39
|
+
* here is Chiliz's official mint from their own documentation" is a proof.
|
|
40
|
+
* "This mint claims to be Chiliz, the official Chiliz mint is X, and both
|
|
41
|
+
* were deployed by wallet W" is a proof plus an attribution — and the
|
|
42
|
+
* attribution is what turns a list of tokens into a case.
|
|
43
|
+
*
|
|
44
|
+
* ── REPRODUCIBILITY ─────────────────────────────────────────────────────────
|
|
45
|
+
*
|
|
46
|
+
* The registry this module reads is generated by `scripts/operator-sweep.mjs`
|
|
47
|
+
* and is reproducible: same universe → same clusters → same file.
|
|
48
|
+
*/
|
|
49
|
+
import { readFileSync } from 'node:fs';
|
|
50
|
+
import { join } from 'node:path';
|
|
51
|
+
/**
|
|
52
|
+
* How many members of a cluster are independently proven impersonators.
|
|
53
|
+
*
|
|
54
|
+
* A cluster of 1,243 tokens is a launchpad. A cluster of 1,243 tokens that
|
|
55
|
+
* contains six proven bluechip impersonators is something else. The count
|
|
56
|
+
* is what distinguishes them — so we compute it, and we never let the raw
|
|
57
|
+
* cluster size stand in for evidence.
|
|
58
|
+
*/
|
|
59
|
+
export function countImpersonators(cluster, isImpersonator) {
|
|
60
|
+
let n = 0;
|
|
61
|
+
for (const m of cluster.members)
|
|
62
|
+
if (isImpersonator(m.mint))
|
|
63
|
+
n++;
|
|
64
|
+
return n;
|
|
65
|
+
}
|
|
66
|
+
let registryCache = null;
|
|
67
|
+
/** Read the operator registry generated by the sweep. Null if not built yet. */
|
|
68
|
+
export function loadOperatorRegistry(root = process.cwd()) {
|
|
69
|
+
if (registryCache)
|
|
70
|
+
return registryCache;
|
|
71
|
+
try {
|
|
72
|
+
const raw = readFileSync(join(root, 'data', 'operator-registry.json'), 'utf8');
|
|
73
|
+
const parsed = JSON.parse(raw);
|
|
74
|
+
if (!parsed?.clusters?.length)
|
|
75
|
+
return null;
|
|
76
|
+
registryCache = parsed;
|
|
77
|
+
return registryCache;
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Find the operator cluster this mint belongs to, if any.
|
|
85
|
+
*
|
|
86
|
+
* `creators` is the mint's metadata creator list (Metaplex order). We test
|
|
87
|
+
* every creator against every cluster, exact match first.
|
|
88
|
+
*/
|
|
89
|
+
export function findOperatorLink(registry, mint, creators) {
|
|
90
|
+
if (!registry || !creators.length)
|
|
91
|
+
return null;
|
|
92
|
+
const addresses = creators.map((c) => c.address).filter(Boolean);
|
|
93
|
+
// exact creator-wallet clusters first — strongest link
|
|
94
|
+
for (const cluster of registry.clusters) {
|
|
95
|
+
if (cluster.kind !== 'identical-creator' || !cluster.creator)
|
|
96
|
+
continue;
|
|
97
|
+
if (!addresses.includes(cluster.creator))
|
|
98
|
+
continue;
|
|
99
|
+
return {
|
|
100
|
+
cluster,
|
|
101
|
+
creator: cluster.creator,
|
|
102
|
+
link: 'identical',
|
|
103
|
+
peers: cluster.members.filter((m) => m.mint !== mint),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
// then vanity-prefix families
|
|
107
|
+
for (const cluster of registry.clusters) {
|
|
108
|
+
if (cluster.kind !== 'vanity-prefix' || !cluster.prefix)
|
|
109
|
+
continue;
|
|
110
|
+
const hit = addresses.find((a) => a.startsWith(cluster.prefix));
|
|
111
|
+
if (!hit)
|
|
112
|
+
continue;
|
|
113
|
+
return {
|
|
114
|
+
cluster,
|
|
115
|
+
creator: hit,
|
|
116
|
+
link: 'prefix',
|
|
117
|
+
peers: cluster.members.filter((m) => m.mint !== mint),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Cluster a set of tokens by their creator wallets, live.
|
|
124
|
+
*
|
|
125
|
+
* Used by the scan command: every candidate it audits already has its
|
|
126
|
+
* metadata loaded, so grouping is free. This is how a NEW factory gets
|
|
127
|
+
* discovered instead of only the ones we happened to hard-code.
|
|
128
|
+
*/
|
|
129
|
+
export function clusterByCreator(tokens) {
|
|
130
|
+
const byExact = new Map();
|
|
131
|
+
const byPrefix = new Map();
|
|
132
|
+
for (const t of tokens) {
|
|
133
|
+
const member = { mint: t.mint, name: t.name, symbol: t.symbol };
|
|
134
|
+
for (const c of t.creators ?? []) {
|
|
135
|
+
if (!c.address)
|
|
136
|
+
continue;
|
|
137
|
+
const list = byExact.get(c.address) ?? [];
|
|
138
|
+
list.push(member);
|
|
139
|
+
byExact.set(c.address, list);
|
|
140
|
+
const prefix = c.address.slice(0, 6);
|
|
141
|
+
const plist = byPrefix.get(prefix) ?? [];
|
|
142
|
+
plist.push(member);
|
|
143
|
+
byPrefix.set(prefix, plist);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const clusters = [];
|
|
147
|
+
for (const [creator, members] of byExact) {
|
|
148
|
+
if (members.length < 2)
|
|
149
|
+
continue;
|
|
150
|
+
clusters.push({
|
|
151
|
+
id: `creator:${creator.slice(0, 12)}…`,
|
|
152
|
+
creator,
|
|
153
|
+
kind: 'identical-creator',
|
|
154
|
+
members: dedupe(members),
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
for (const [prefix, members] of byPrefix) {
|
|
158
|
+
if (members.length < 2)
|
|
159
|
+
continue;
|
|
160
|
+
clusters.push({
|
|
161
|
+
id: `prefix:${prefix}`,
|
|
162
|
+
prefix,
|
|
163
|
+
kind: 'vanity-prefix',
|
|
164
|
+
members: dedupe(members),
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return clusters.sort((a, b) => b.members.length - a.members.length);
|
|
168
|
+
}
|
|
169
|
+
function dedupe(members) {
|
|
170
|
+
const seen = new Set();
|
|
171
|
+
const out = [];
|
|
172
|
+
for (const m of members) {
|
|
173
|
+
if (seen.has(m.mint))
|
|
174
|
+
continue;
|
|
175
|
+
seen.add(m.mint);
|
|
176
|
+
out.push(m);
|
|
177
|
+
}
|
|
178
|
+
return out;
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=operator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operator.js","sourceRoot":"","sources":["../src/operator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAmCjC;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAAwB,EACxB,cAAyC;IAEzC,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,KAAK,MAAM,CAAC,IAAI,OAAO,CAAC,OAAO;QAAE,IAAI,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC;YAAE,CAAC,EAAE,CAAC;IACjE,OAAO,CAAC,CAAC;AACX,CAAC;AAED,IAAI,aAAa,GAA4B,IAAI,CAAC;AAElD,gFAAgF;AAChF,MAAM,UAAU,oBAAoB,CAAC,IAAI,GAAG,OAAO,CAAC,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,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,MAAM,GAAG,GAAqB,EAAE,CAAC;IACjC,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;QACxB,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;YAAE,SAAS;QAC/B,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACjB,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACd,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/pda.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// On-chain token metadata for Solana mints.
|
|
2
|
+
//
|
|
3
|
+
// WHY THIS EXISTS IN-PRODUCT: an impersonation finding is only airtight if
|
|
4
|
+
// we can show what the token SAYS it is, read from its own Metaplex
|
|
5
|
+
// metadata account, next to the canonical token it is pretending to be.
|
|
6
|
+
//
|
|
7
|
+
// The hard part is finding the metadata account: it is a Program Derived
|
|
8
|
+
// Address, so we must derive it ourselves —
|
|
9
|
+
//
|
|
10
|
+
// pda = sha256("metadata" || metadata_program || mint || bump)
|
|
11
|
+
//
|
|
12
|
+
// and pick the bump whose hash is NOT a valid ed25519 curve point.
|
|
13
|
+
//
|
|
14
|
+
// The curve check is the real work. We do it with BigInt modular arithmetic
|
|
15
|
+
// (no dependencies):
|
|
16
|
+
//
|
|
17
|
+
// a point (x, y) is valid iff x² = (y² - 1) / (d·y² + 1) (mod p)
|
|
18
|
+
//
|
|
19
|
+
// with p = 2²⁵⁵ - 19 and d = -121665/121666.
|
|
20
|
+
import { createHash } from 'node:crypto';
|
|
21
|
+
const P = (1n << 255n) - 19n;
|
|
22
|
+
const D = 37095705934669439343138083508754565189542113879843219016388785533085940283555n;
|
|
23
|
+
function mod(a, m = P) {
|
|
24
|
+
const r = a % m;
|
|
25
|
+
return r >= 0n ? r : r + m;
|
|
26
|
+
}
|
|
27
|
+
function powMod(base, exp, m = P) {
|
|
28
|
+
let result = 1n;
|
|
29
|
+
let b = mod(base, m);
|
|
30
|
+
let e = exp;
|
|
31
|
+
while (e > 0n) {
|
|
32
|
+
if (e & 1n)
|
|
33
|
+
result = (result * b) % m;
|
|
34
|
+
b = (b * b) % m;
|
|
35
|
+
e >>= 1n;
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Is this 32-byte value a valid ed25519 public key (a point on the curve)?
|
|
41
|
+
*
|
|
42
|
+
* A valid compressed point encodes y in the low 255 bits and the sign of x
|
|
43
|
+
* in the top bit. We solve for x and check the curve equation.
|
|
44
|
+
*/
|
|
45
|
+
export function isOnEd25519Curve(bytes) {
|
|
46
|
+
if (bytes.length !== 32)
|
|
47
|
+
return false;
|
|
48
|
+
const le = Buffer.from(bytes);
|
|
49
|
+
const sign = (le[31] & 0x80) >> 7;
|
|
50
|
+
le[31] &= 0x7f;
|
|
51
|
+
const y = mod(BigInt('0x' + le.toString('hex')));
|
|
52
|
+
// x² = (y² - 1) / (d·y² + 1)
|
|
53
|
+
const y2 = mod(y * y);
|
|
54
|
+
const u = mod(y2 - 1n);
|
|
55
|
+
const v = mod(D * y2 + 1n);
|
|
56
|
+
if (v === 0n)
|
|
57
|
+
return false;
|
|
58
|
+
// x = u·v³·(u·v⁷)^((p-5)/8)
|
|
59
|
+
const v3 = mod(v * v * v);
|
|
60
|
+
const v7 = mod(v3 * v3 * v);
|
|
61
|
+
const x = mod(u * v3 * powMod(mod(u * v7), (P - 5n) / 8n));
|
|
62
|
+
// Check v·x² == u (mod p)
|
|
63
|
+
const check = mod(v * x * x);
|
|
64
|
+
if (check !== u) {
|
|
65
|
+
// One more possibility: x = x·√(-1) works when v·x² == -u
|
|
66
|
+
const negU = mod(-u);
|
|
67
|
+
if (check !== negU)
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
// If x == 0, the sign bit must be 0.
|
|
71
|
+
if (x === 0n && sign === 1)
|
|
72
|
+
return false;
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
/** Canonical Solana PDA derivation. */
|
|
76
|
+
export function findProgramAddress(seeds, programId) {
|
|
77
|
+
for (let bump = 255; bump >= 0; bump--) {
|
|
78
|
+
const h = createHash('sha256')
|
|
79
|
+
.update(Buffer.concat([...seeds, programId, Buffer.from([bump])]))
|
|
80
|
+
.digest();
|
|
81
|
+
if (!isOnEd25519Curve(h))
|
|
82
|
+
return h;
|
|
83
|
+
}
|
|
84
|
+
throw new Error('unable to find a viable program address bump');
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=pda.js.map
|
package/dist/pda.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pda.js","sourceRoot":"","sources":["../src/pda.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,EAAE;AACF,2EAA2E;AAC3E,oEAAoE;AACpE,wEAAwE;AACxE,EAAE;AACF,yEAAyE;AACzE,4CAA4C;AAC5C,EAAE;AACF,mEAAmE;AACnE,EAAE;AACF,mEAAmE;AACnE,EAAE;AACF,4EAA4E;AAC5E,qBAAqB;AACrB,EAAE;AACF,wEAAwE;AACxE,EAAE;AACF,6CAA6C;AAE7C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,CAAC,GAAG,CAAC,EAAE,IAAI,IAAI,CAAC,GAAG,GAAG,CAAC;AAC7B,MAAM,CAAC,GAAG,8EAA8E,CAAC;AAEzF,SAAS,GAAG,CAAC,CAAS,EAAE,IAAY,CAAC;IACnC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAChB,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAC7B,CAAC;AAED,SAAS,MAAM,CAAC,IAAY,EAAE,GAAW,EAAE,IAAY,CAAC;IACtD,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,I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