@ercworldio/blockchain-shared 1.0.5-dev.7.PROJ-1464.0 → 1.0.5-dev.8
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/build/chains/networks_dev.json +10 -0
- package/build/chains/networks_prod-bu.json +0 -14
- package/build/chains/networks_prod-dz.json +22 -1
- package/build/errors/TransactionsErrors.d.ts +0 -1
- package/build/errors/TransactionsErrors.d.ts.map +1 -1
- package/build/errors/TransactionsErrors.js +0 -4
- package/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +4 -2
- package/build/services/ClaimJobService.d.ts.map +1 -1
- package/build/services/ClaimJobService.js +12 -5
- package/build/services/Redis.js +2 -2
- package/build/services/RedisPubSub.js +1 -1
- package/build/services/db/timelock/ScheduleTransactionService.d.ts +16 -2
- package/build/services/db/timelock/ScheduleTransactionService.d.ts.map +1 -1
- package/build/services/db/timelock/ScheduleTransactionService.js +265 -1
- package/build/services/rpc/RPC.d.ts +20 -0
- package/build/services/rpc/RPC.d.ts.map +1 -0
- package/build/services/rpc/RPC.js +49 -0
- package/build/services/solana/escrow/SolanaEscrowAdmin.d.ts +41 -1
- package/build/services/solana/escrow/SolanaEscrowAdmin.d.ts.map +1 -1
- package/build/services/solana/escrow/SolanaEscrowAdmin.js +35 -3
- package/build/services/solana/escrow/idl/escrow.json +4267 -988
- package/build/services/solana/escrow/services/EscrowAdminUtility.d.ts +116 -3
- package/build/services/solana/escrow/services/EscrowAdminUtility.d.ts.map +1 -1
- package/build/services/solana/escrow/services/EscrowAdminUtility.js +543 -55
- package/build/services/solana/escrow/services/TreasuryWithdrawalSignature.d.ts +58 -0
- package/build/services/solana/escrow/services/TreasuryWithdrawalSignature.d.ts.map +1 -0
- package/build/services/solana/escrow/services/TreasuryWithdrawalSignature.js +109 -0
- package/build/services/solana/escrow/types/escrow.d.ts +4262 -983
- package/build/services/solana/escrow/types/escrow.d.ts.map +1 -1
- package/build/services/solana/escrow/types/types.d.ts +17 -0
- package/build/services/solana/escrow/types/types.d.ts.map +1 -1
- package/build/services/types/claim.d.ts +1 -0
- package/build/services/types/claim.d.ts.map +1 -1
- package/build/services/types/db/timelock.d.ts +56 -0
- package/build/services/types/db/timelock.d.ts.map +1 -1
- package/build/utils/solana.d.ts.map +1 -1
- package/build/utils/solana.js +5 -3
- package/package.json +1 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
2
|
+
/**
|
|
3
|
+
* Treasury withdrawal approval message + Ed25519 assembly.
|
|
4
|
+
*
|
|
5
|
+
* Mirrors the escrow program's `build_withdrawal_message` and its Ed25519SigVerify layout so the
|
|
6
|
+
* batch-withdraw transaction the funding worker sends carries signatures the program accepts.
|
|
7
|
+
*/
|
|
8
|
+
/** One treasury manager/executive approval over a request's message. */
|
|
9
|
+
export interface TreasurySignatureInput {
|
|
10
|
+
/** Base58 signer pubkey — a current treasury manager/executive on-chain. */
|
|
11
|
+
signer: string;
|
|
12
|
+
/** 64-byte Ed25519 signature (base64/hex/base58). */
|
|
13
|
+
signature: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Builds the UTF-8 approval message a treasury signer approves. MUST match the program's
|
|
17
|
+
* `build_withdrawal_message` byte for byte, or verification fails.
|
|
18
|
+
*
|
|
19
|
+
* Withdrawal Approval
|
|
20
|
+
* Version: 1
|
|
21
|
+
* Chain: <chainId>
|
|
22
|
+
* Request: <requestId>
|
|
23
|
+
* Recipient: <recipient base58>
|
|
24
|
+
* Token: <mint base58>
|
|
25
|
+
* Amount: <committed amount, raw base units>
|
|
26
|
+
*
|
|
27
|
+
* `Amount` is the committed (approved) amount — the net paid out is chosen later by the backend
|
|
28
|
+
* and bounded on-chain by TreasuryConfig.max_fee_delta. The title + Version line domain-separate
|
|
29
|
+
* the signature; bump Version in lockstep with the program on any format change.
|
|
30
|
+
*/
|
|
31
|
+
export declare function buildWithdrawalApprovalMessage(params: {
|
|
32
|
+
recipient: PublicKey;
|
|
33
|
+
tokenMint: PublicKey;
|
|
34
|
+
committedAmount: bigint;
|
|
35
|
+
chainId: bigint;
|
|
36
|
+
requestId: bigint;
|
|
37
|
+
}): Buffer;
|
|
38
|
+
/** Decode a 64-byte Ed25519 signature from base64, hex (0x-optional), or base58. */
|
|
39
|
+
export declare function decodeEd25519Signature(s: string): Uint8Array;
|
|
40
|
+
/** One fully-decoded signature entry: pubkey + signature over `message`. */
|
|
41
|
+
export interface Ed25519Entry {
|
|
42
|
+
publicKey: Uint8Array;
|
|
43
|
+
signature: Uint8Array;
|
|
44
|
+
message: Uint8Array;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Builds a single Ed25519SigVerify instruction carrying `entries` self-contained signatures
|
|
48
|
+
* (each entry's pubkey, signature and message live in this instruction's own data). This is the
|
|
49
|
+
* compact layout the program scans in `verify_treasury_threshold`; one instruction for the whole
|
|
50
|
+
* batch keeps the transaction far smaller than one instruction per signature.
|
|
51
|
+
*
|
|
52
|
+
* Identical messages are stored ONCE and shared by every signature over them, since the offsets
|
|
53
|
+
* table lets multiple entries point at the same message region. This matters: the N signers who
|
|
54
|
+
* approve one withdrawal all sign the same ~194-byte payload, so without sharing, a 2-of-N
|
|
55
|
+
* approval would spend an extra ~194 bytes and overflow Solana's 1232-byte transaction limit.
|
|
56
|
+
*/
|
|
57
|
+
export declare function buildTreasuryEd25519Instruction(entries: Ed25519Entry[]): TransactionInstruction;
|
|
58
|
+
//# sourceMappingURL=TreasuryWithdrawalSignature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreasuryWithdrawalSignature.d.ts","sourceRoot":"","sources":["../../../../../src/services/solana/escrow/services/TreasuryWithdrawalSignature.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,SAAS,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAGpF;;;;;GAKG;AAEH,wEAAwE;AACxE,MAAM,WAAW,sBAAsB;IACnC,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAC;IACf,qDAAqD;IACrD,SAAS,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,8BAA8B,CAAC,MAAM,EAAE;IACnD,SAAS,EAAE,SAAS,CAAC;IACrB,SAAS,EAAE,SAAS,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACrB,GAAG,MAAM,CAUT;AAED,oFAAoF;AACpF,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,MAAM,GAAG,UAAU,CAU5D;AAED,4EAA4E;AAC5E,MAAM,WAAW,YAAY;IACzB,SAAS,EAAE,UAAU,CAAC;IACtB,SAAS,EAAE,UAAU,CAAC;IACtB,OAAO,EAAE,UAAU,CAAC;CACvB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,sBAAsB,CAoD/F"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.buildWithdrawalApprovalMessage = buildWithdrawalApprovalMessage;
|
|
7
|
+
exports.decodeEd25519Signature = decodeEd25519Signature;
|
|
8
|
+
exports.buildTreasuryEd25519Instruction = buildTreasuryEd25519Instruction;
|
|
9
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
10
|
+
const bs58_1 = __importDefault(require("bs58"));
|
|
11
|
+
/**
|
|
12
|
+
* Builds the UTF-8 approval message a treasury signer approves. MUST match the program's
|
|
13
|
+
* `build_withdrawal_message` byte for byte, or verification fails.
|
|
14
|
+
*
|
|
15
|
+
* Withdrawal Approval
|
|
16
|
+
* Version: 1
|
|
17
|
+
* Chain: <chainId>
|
|
18
|
+
* Request: <requestId>
|
|
19
|
+
* Recipient: <recipient base58>
|
|
20
|
+
* Token: <mint base58>
|
|
21
|
+
* Amount: <committed amount, raw base units>
|
|
22
|
+
*
|
|
23
|
+
* `Amount` is the committed (approved) amount — the net paid out is chosen later by the backend
|
|
24
|
+
* and bounded on-chain by TreasuryConfig.max_fee_delta. The title + Version line domain-separate
|
|
25
|
+
* the signature; bump Version in lockstep with the program on any format change.
|
|
26
|
+
*/
|
|
27
|
+
function buildWithdrawalApprovalMessage(params) {
|
|
28
|
+
const text = "Withdrawal Approval\n" +
|
|
29
|
+
"Version: 1\n" +
|
|
30
|
+
`Chain: ${params.chainId}\n` +
|
|
31
|
+
`Request: ${params.requestId}\n` +
|
|
32
|
+
`Recipient: ${params.recipient.toBase58()}\n` +
|
|
33
|
+
`Token: ${params.tokenMint.toBase58()}\n` +
|
|
34
|
+
`Amount: ${params.committedAmount}`;
|
|
35
|
+
return Buffer.from(text, "utf8");
|
|
36
|
+
}
|
|
37
|
+
/** Decode a 64-byte Ed25519 signature from base64, hex (0x-optional), or base58. */
|
|
38
|
+
function decodeEd25519Signature(s) {
|
|
39
|
+
const b64 = Buffer.from(s, "base64");
|
|
40
|
+
if (b64.length === 64)
|
|
41
|
+
return b64;
|
|
42
|
+
const hex = s.startsWith("0x") ? s.slice(2) : s;
|
|
43
|
+
if (/^[0-9a-fA-F]{128}$/.test(hex))
|
|
44
|
+
return Buffer.from(hex, "hex");
|
|
45
|
+
try {
|
|
46
|
+
const b58 = bs58_1.default.decode(s);
|
|
47
|
+
if (b58.length === 64)
|
|
48
|
+
return b58;
|
|
49
|
+
}
|
|
50
|
+
catch ( /* fallthrough */_a) { /* fallthrough */ }
|
|
51
|
+
throw new Error("Invalid Ed25519 signature encoding (expected 64 bytes as base64/hex/base58)");
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Builds a single Ed25519SigVerify instruction carrying `entries` self-contained signatures
|
|
55
|
+
* (each entry's pubkey, signature and message live in this instruction's own data). This is the
|
|
56
|
+
* compact layout the program scans in `verify_treasury_threshold`; one instruction for the whole
|
|
57
|
+
* batch keeps the transaction far smaller than one instruction per signature.
|
|
58
|
+
*
|
|
59
|
+
* Identical messages are stored ONCE and shared by every signature over them, since the offsets
|
|
60
|
+
* table lets multiple entries point at the same message region. This matters: the N signers who
|
|
61
|
+
* approve one withdrawal all sign the same ~194-byte payload, so without sharing, a 2-of-N
|
|
62
|
+
* approval would spend an extra ~194 bytes and overflow Solana's 1232-byte transaction limit.
|
|
63
|
+
*/
|
|
64
|
+
function buildTreasuryEd25519Instruction(entries) {
|
|
65
|
+
const N = entries.length;
|
|
66
|
+
const OFFSETS_SIZE = 14;
|
|
67
|
+
const ENTRY_SIZE = 32 + 64; // pubkey + signature
|
|
68
|
+
const header = 2 + N * OFFSETS_SIZE;
|
|
69
|
+
const msgStart = header + N * ENTRY_SIZE;
|
|
70
|
+
// Deduplicate message blobs by content; remember where each unique one lands.
|
|
71
|
+
const uniqueMessages = [];
|
|
72
|
+
const messageOffsets = [];
|
|
73
|
+
const seen = new Map();
|
|
74
|
+
let cursor = msgStart;
|
|
75
|
+
for (const entry of entries) {
|
|
76
|
+
const key = Buffer.from(entry.message).toString("base64");
|
|
77
|
+
let offset = seen.get(key);
|
|
78
|
+
if (offset === undefined) {
|
|
79
|
+
offset = cursor;
|
|
80
|
+
seen.set(key, offset);
|
|
81
|
+
uniqueMessages.push(entry.message);
|
|
82
|
+
cursor += entry.message.length;
|
|
83
|
+
}
|
|
84
|
+
messageOffsets.push(offset);
|
|
85
|
+
}
|
|
86
|
+
const data = Buffer.alloc(cursor);
|
|
87
|
+
data[0] = N; // number of signatures
|
|
88
|
+
data[1] = 0; // padding
|
|
89
|
+
for (let i = 0; i < N; i++) {
|
|
90
|
+
const base = 2 + i * OFFSETS_SIZE;
|
|
91
|
+
const pkOffset = header + i * ENTRY_SIZE;
|
|
92
|
+
const sigOffset = pkOffset + 32;
|
|
93
|
+
data.writeUInt16LE(sigOffset, base + 0); // signature_offset
|
|
94
|
+
data.writeUInt16LE(0xffff, base + 2); // signature_instruction_index (self)
|
|
95
|
+
data.writeUInt16LE(pkOffset, base + 4); // public_key_offset
|
|
96
|
+
data.writeUInt16LE(0xffff, base + 6); // public_key_instruction_index (self)
|
|
97
|
+
data.writeUInt16LE(messageOffsets[i], base + 8); // message_data_offset (may be shared)
|
|
98
|
+
data.writeUInt16LE(entries[i].message.length, base + 10); // message_data_size
|
|
99
|
+
data.writeUInt16LE(0xffff, base + 12); // message_instruction_index (self)
|
|
100
|
+
data.set(entries[i].publicKey, pkOffset);
|
|
101
|
+
data.set(entries[i].signature, sigOffset);
|
|
102
|
+
}
|
|
103
|
+
// Write each unique message once, at the offset its first referrer recorded.
|
|
104
|
+
for (let i = 0, offset = msgStart; i < uniqueMessages.length; i++) {
|
|
105
|
+
data.set(uniqueMessages[i], offset);
|
|
106
|
+
offset += uniqueMessages[i].length;
|
|
107
|
+
}
|
|
108
|
+
return new web3_js_1.TransactionInstruction({ keys: [], programId: web3_js_1.Ed25519Program.programId, data });
|
|
109
|
+
}
|