sigil-protocol-sdk 1.0.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/README.md +90 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +18 -0
- package/dist/sdk/src/index.d.ts +2 -0
- package/dist/sdk/src/index.js +18 -0
- package/dist/sdk/src/sigil-client.d.ts +34 -0
- package/dist/sdk/src/sigil-client.js +159 -0
- package/dist/sdk/src/sigil-registry.d.ts +63 -0
- package/dist/sdk/src/sigil-registry.js +191 -0
- package/dist/sdk/src/types.d.ts +833 -0
- package/dist/sdk/src/types.js +2 -0
- package/dist/sigil-client.d.ts +34 -0
- package/dist/sigil-client.js +159 -0
- package/dist/sigil-registry.d.ts +63 -0
- package/dist/sigil-registry.js +191 -0
- package/dist/types.d.ts +833 -0
- package/dist/types.js +2 -0
- package/package.json +18 -0
- package/src/index.ts +2 -0
- package/src/sigil-client.ts +193 -0
- package/src/sigil-registry.d.ts +21 -0
- package/src/sigil-registry.js +142 -0
- package/src/sigil-registry.ts +267 -0
- package/src/types.d.ts +262 -0
- package/src/types.js +2 -0
- package/src/types.ts +833 -0
- package/tsconfig.json +15 -0
package/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# sigil-protocol-sdk
|
|
2
|
+
|
|
3
|
+
Official TypeScript SDK for interacting with the Sigil Protocol on Solana. Designed for autonomous agents to discover, verify, and execute skills.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install sigil-protocol-sdk @solana/web3.js @coral-xyz/anchor
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### 1. Initialize Client
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { Connection, Keypair } from '@solana/web3.js';
|
|
17
|
+
import { Wallet } from '@coral-xyz/anchor';
|
|
18
|
+
import { SigilClient } from 'sigil-protocol-sdk';
|
|
19
|
+
|
|
20
|
+
const connection = new Connection("https://api.devnet.solana.com");
|
|
21
|
+
const wallet = new Wallet(Keypair.fromSecretKey(...));
|
|
22
|
+
const client = new SigilClient(connection, wallet);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### 2. Register a Skill (Mint)
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
const tx = await client.registerSkill({
|
|
29
|
+
name: "Arbitrage Scout",
|
|
30
|
+
description: "Finds atomic arb routes on Jupiter",
|
|
31
|
+
priceUsdc: 0.1, // 0.10 USDC
|
|
32
|
+
externalUrl: "https://github.com/agent/skills/arb.md",
|
|
33
|
+
logicContent: "console.log('logic code here')..." // Optional: for hash generation
|
|
34
|
+
});
|
|
35
|
+
console.log("Skill Minted:", tx);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### 3. Execute a Skill (Atomic Payment)
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
const skillPda = new PublicKey("..."); // Get from marketplace
|
|
42
|
+
const tx = await client.executeSkill(
|
|
43
|
+
skillPda,
|
|
44
|
+
true, // Success status
|
|
45
|
+
150 // Latency in ms
|
|
46
|
+
);
|
|
47
|
+
console.log("Execution logged & paid:", tx);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 4. Verify Integrity
|
|
51
|
+
|
|
52
|
+
Before executing code downloaded from an external URL, verify it matches the on-chain hash.
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
const isValid = await client.verifyIntegrity(skillPda, downloadedCode);
|
|
56
|
+
if (!isValid) throw new Error("Security Alert: Code has been tampered with!");
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 5. Auditor Management
|
|
60
|
+
|
|
61
|
+
Join the decentralized network of auditors to verify skills and earn rewards.
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
// Register as an Auditor
|
|
65
|
+
const tx = await client.initializeAuditor();
|
|
66
|
+
console.log("Auditor Registered:", tx);
|
|
67
|
+
|
|
68
|
+
// Stake USDC for skin-in-the-game
|
|
69
|
+
const stakeTx = await client.stakeUsdc(
|
|
70
|
+
auditorPda,
|
|
71
|
+
auditorTokenAccount,
|
|
72
|
+
vaultTokenAccount,
|
|
73
|
+
vaultAuthorityPda,
|
|
74
|
+
usdcMint,
|
|
75
|
+
new BN(1000_000000) // 1000 USDC
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
// Sign a Skill (Approve)
|
|
79
|
+
const signTx = await client.addAuditorSignature(
|
|
80
|
+
skillPda,
|
|
81
|
+
auditorPda,
|
|
82
|
+
signatureBytes,
|
|
83
|
+
auditReportHash
|
|
84
|
+
);
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Compatibility
|
|
88
|
+
- Node.js 18+
|
|
89
|
+
- Solana Web3.js 1.95+
|
|
90
|
+
- Anchor 0.30+
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./sigil-registry"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./sigil-registry"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Program, AnchorProvider } from '@coral-xyz/anchor';
|
|
2
|
+
import { Connection, PublicKey } from '@solana/web3.js';
|
|
3
|
+
import { SigilRegistry } from './types';
|
|
4
|
+
export declare class SigilClient {
|
|
5
|
+
program: Program<SigilRegistry>;
|
|
6
|
+
provider: AnchorProvider;
|
|
7
|
+
connection: Connection;
|
|
8
|
+
constructor(connection: Connection, wallet: any);
|
|
9
|
+
/**
|
|
10
|
+
* High-level method to execute a skill and handle payments atomically.
|
|
11
|
+
*/
|
|
12
|
+
executeSkill(skillPda: PublicKey, success: boolean, latencyMs: number): Promise<string>;
|
|
13
|
+
/**
|
|
14
|
+
* Registers a new skill with metadata compression and integrity hashing.
|
|
15
|
+
*/
|
|
16
|
+
registerSkill(params: {
|
|
17
|
+
name: string;
|
|
18
|
+
description: string;
|
|
19
|
+
priceUsdc: number;
|
|
20
|
+
externalUrl?: string;
|
|
21
|
+
logicContent?: string;
|
|
22
|
+
}): Promise<string>;
|
|
23
|
+
/**
|
|
24
|
+
* Verifies if the local logic matches the on-chain recorded integrity hash.
|
|
25
|
+
*/
|
|
26
|
+
verifyIntegrity(skillPda: PublicKey, localLogicContent: string): Promise<boolean>;
|
|
27
|
+
/**
|
|
28
|
+
* Auditor Staking Management
|
|
29
|
+
*/
|
|
30
|
+
stake(amountUsdc: number): Promise<string>;
|
|
31
|
+
deriveAuditorPda(authority: PublicKey): PublicKey;
|
|
32
|
+
deriveVaultPda(mint: PublicKey, auditor: PublicKey): PublicKey;
|
|
33
|
+
deriveVaultAuthorityPda(): PublicKey;
|
|
34
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
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.SigilClient = void 0;
|
|
7
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
8
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
9
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
10
|
+
const sigil_registry_json_1 = __importDefault(require("../../target/idl/sigil_registry.json"));
|
|
11
|
+
class SigilClient {
|
|
12
|
+
constructor(connection, wallet) {
|
|
13
|
+
this.connection = connection;
|
|
14
|
+
this.provider = new anchor_1.AnchorProvider(connection, wallet, {
|
|
15
|
+
commitment: 'confirmed',
|
|
16
|
+
});
|
|
17
|
+
this.program = new anchor_1.Program(sigil_registry_json_1.default, this.provider);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* High-level method to execute a skill and handle payments atomically.
|
|
21
|
+
*/
|
|
22
|
+
async executeSkill(skillPda, success, latencyMs) {
|
|
23
|
+
const skillData = await this.program.account.skill.fetch(skillPda);
|
|
24
|
+
const creator = skillData.creator;
|
|
25
|
+
const protocolTreasury = new web3_js_1.PublicKey('3adsGFsaGUDePR61ZtvkwkkpCeLne6immQbp2gR5jbfo');
|
|
26
|
+
const usdcMint = new web3_js_1.PublicKey('4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU');
|
|
27
|
+
const executorUsdc = await (0, spl_token_1.getAssociatedTokenAddress)(usdcMint, this.provider.wallet.publicKey);
|
|
28
|
+
const creatorUsdc = await (0, spl_token_1.getAssociatedTokenAddress)(usdcMint, creator);
|
|
29
|
+
const protocolUsdc = await (0, spl_token_1.getAssociatedTokenAddress)(usdcMint, protocolTreasury);
|
|
30
|
+
const executionLog = web3_js_1.Keypair.generate();
|
|
31
|
+
return await this.program.methods
|
|
32
|
+
.logExecution(success, latencyMs)
|
|
33
|
+
.accounts({
|
|
34
|
+
skill: skillPda,
|
|
35
|
+
executionLog: executionLog.publicKey,
|
|
36
|
+
executor: this.provider.wallet.publicKey,
|
|
37
|
+
executorUsdc,
|
|
38
|
+
creatorUsdc,
|
|
39
|
+
protocolUsdc,
|
|
40
|
+
})
|
|
41
|
+
.signers([executionLog])
|
|
42
|
+
.rpc();
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Registers a new skill with metadata compression and integrity hashing.
|
|
46
|
+
*/
|
|
47
|
+
async registerSkill(params) {
|
|
48
|
+
const skillId = Array.from(crypto.getRandomValues(new Uint8Array(32)));
|
|
49
|
+
const priceBN = new anchor_1.BN(params.priceUsdc * 1000000);
|
|
50
|
+
// 1. Calculate Integrity Hash
|
|
51
|
+
let integrityHash = "";
|
|
52
|
+
if (params.logicContent) {
|
|
53
|
+
const msgBuffer = new TextEncoder().encode(params.logicContent);
|
|
54
|
+
const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer);
|
|
55
|
+
integrityHash = Array.from(new Uint8Array(hashBuffer))
|
|
56
|
+
.map(b => b.toString(16).padStart(2, '0'))
|
|
57
|
+
.join('');
|
|
58
|
+
}
|
|
59
|
+
// 2. Prepare Metadata
|
|
60
|
+
const metadataObj = {
|
|
61
|
+
n: params.name,
|
|
62
|
+
d: params.description,
|
|
63
|
+
u: params.externalUrl,
|
|
64
|
+
h: integrityHash
|
|
65
|
+
};
|
|
66
|
+
// 3. Compress using Gzip
|
|
67
|
+
const metadataStr = JSON.stringify(metadataObj);
|
|
68
|
+
const blob = new Blob([metadataStr]);
|
|
69
|
+
const compressedStream = blob.stream().pipeThrough(new window.DecompressionStream('gzip'));
|
|
70
|
+
const compressedBuffer = await new Response(compressedStream).arrayBuffer();
|
|
71
|
+
const finalMetadata = `gz:${Buffer.from(compressedBuffer).toString('base64')}`;
|
|
72
|
+
// 4. Generate Signature
|
|
73
|
+
let signature = Array(64).fill(0);
|
|
74
|
+
if (this.provider.wallet.signMessage) {
|
|
75
|
+
const message = new TextEncoder().encode(`Minting Sigil Skill: ${params.name}`);
|
|
76
|
+
const sig = await this.provider.wallet.signMessage(message);
|
|
77
|
+
signature = Array.from(sig);
|
|
78
|
+
}
|
|
79
|
+
const [skillPda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('skill'), new Uint8Array(skillId)], this.program.programId);
|
|
80
|
+
const [registryPda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('registry_v1')], this.program.programId);
|
|
81
|
+
return await this.program.methods
|
|
82
|
+
.mintSkill(skillId, priceBN, finalMetadata, signature)
|
|
83
|
+
.accounts({
|
|
84
|
+
skill: skillPda,
|
|
85
|
+
creator: this.provider.wallet.publicKey,
|
|
86
|
+
registry: registryPda,
|
|
87
|
+
})
|
|
88
|
+
.rpc();
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Verifies if the local logic matches the on-chain recorded integrity hash.
|
|
92
|
+
*/
|
|
93
|
+
async verifyIntegrity(skillPda, localLogicContent) {
|
|
94
|
+
const skillData = await this.program.account.skill.fetch(skillPda);
|
|
95
|
+
const ipfsHash = skillData.ipfsHash;
|
|
96
|
+
if (!ipfsHash.startsWith('gz:'))
|
|
97
|
+
return false;
|
|
98
|
+
// Decompress
|
|
99
|
+
const base64Data = ipfsHash.slice(3);
|
|
100
|
+
const binaryString = window.atob(base64Data);
|
|
101
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
102
|
+
for (let i = 0; i < binaryString.length; i++)
|
|
103
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
104
|
+
const decompressedStream = new Blob([bytes]).stream().pipeThrough(new window.DecompressionStream('gzip'));
|
|
105
|
+
const metadata = JSON.parse(await new Response(decompressedStream).text());
|
|
106
|
+
if (!metadata.h)
|
|
107
|
+
return true; // No hash to verify
|
|
108
|
+
// Calculate local hash
|
|
109
|
+
const msgBuffer = new TextEncoder().encode(localLogicContent);
|
|
110
|
+
const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer);
|
|
111
|
+
const localHash = Array.from(new Uint8Array(hashBuffer))
|
|
112
|
+
.map(b => b.toString(16).padStart(2, '0'))
|
|
113
|
+
.join('');
|
|
114
|
+
return localHash === metadata.h;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Auditor Staking Management
|
|
118
|
+
*/
|
|
119
|
+
async stake(amountUsdc) {
|
|
120
|
+
const amount = new anchor_1.BN(amountUsdc * 1000000);
|
|
121
|
+
const auditorPda = this.deriveAuditorPda(this.provider.wallet.publicKey);
|
|
122
|
+
// Check if initialized
|
|
123
|
+
try {
|
|
124
|
+
await this.program.account.auditor.fetch(auditorPda);
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
await this.program.methods.initializeAuditor().accounts({
|
|
128
|
+
auditor: auditorPda,
|
|
129
|
+
authority: this.provider.wallet.publicKey,
|
|
130
|
+
}).rpc();
|
|
131
|
+
}
|
|
132
|
+
const usdcMint = new web3_js_1.PublicKey('4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU');
|
|
133
|
+
const auditorTokenAccount = await (0, spl_token_1.getAssociatedTokenAddress)(usdcMint, this.provider.wallet.publicKey);
|
|
134
|
+
const vaultTokenAccount = this.deriveVaultPda(usdcMint, auditorPda);
|
|
135
|
+
const vaultAuthority = this.deriveVaultAuthorityPda();
|
|
136
|
+
return await this.program.methods
|
|
137
|
+
.stakeUsdc(amount)
|
|
138
|
+
.accounts({
|
|
139
|
+
auditor: auditorPda,
|
|
140
|
+
auditorTokenAccount,
|
|
141
|
+
vaultTokenAccount,
|
|
142
|
+
vaultAuthority,
|
|
143
|
+
usdcMint,
|
|
144
|
+
authority: this.provider.wallet.publicKey,
|
|
145
|
+
})
|
|
146
|
+
.rpc();
|
|
147
|
+
}
|
|
148
|
+
// PDA Derivation Helpers
|
|
149
|
+
deriveAuditorPda(authority) {
|
|
150
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('auditor'), authority.toBuffer()], this.program.programId)[0];
|
|
151
|
+
}
|
|
152
|
+
deriveVaultPda(mint, auditor) {
|
|
153
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('vault'), mint.toBuffer(), auditor.toBuffer()], this.program.programId)[0];
|
|
154
|
+
}
|
|
155
|
+
deriveVaultAuthorityPda() {
|
|
156
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('vault_authority')], this.program.programId)[0];
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.SigilClient = SigilClient;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Program, AnchorProvider, BN } from '@coral-xyz/anchor';
|
|
2
|
+
import { Connection, PublicKey } from '@solana/web3.js';
|
|
3
|
+
import { SigilRegistry } from './types';
|
|
4
|
+
export declare class SigilRegistryClient {
|
|
5
|
+
program: Program<SigilRegistry>;
|
|
6
|
+
provider: AnchorProvider;
|
|
7
|
+
constructor(connection: Connection, wallet: any);
|
|
8
|
+
initializeRegistry(): Promise<string>;
|
|
9
|
+
initializeAuditor(): Promise<string>;
|
|
10
|
+
mintSkill(skillId: number[], priceUsdc: BN, ipfsHash: string, creatorSignature: number[]): Promise<string>;
|
|
11
|
+
addAuditorSignature(skillPda: PublicKey, auditorPda: PublicKey, signature: number[], auditReportHash: string): Promise<string>;
|
|
12
|
+
logExecution(skillPda: PublicKey, executionLogPda: PublicKey, executorUsdc: PublicKey, creatorUsdc: PublicKey, protocolUsdc: PublicKey, success: boolean, latencyMs: number): Promise<string>;
|
|
13
|
+
getSkill(skillPda: PublicKey): Promise<{
|
|
14
|
+
skillId: number[];
|
|
15
|
+
creator: PublicKey;
|
|
16
|
+
creatorSignature: number[];
|
|
17
|
+
priceUsdc: BN;
|
|
18
|
+
ipfsHash: string;
|
|
19
|
+
auditReportHash: string;
|
|
20
|
+
auditorCount: number;
|
|
21
|
+
auditors: any[];
|
|
22
|
+
consensusStatus: any;
|
|
23
|
+
consensusRecord: PublicKey | null;
|
|
24
|
+
trustScore: number;
|
|
25
|
+
executionCount: BN;
|
|
26
|
+
successCount: BN;
|
|
27
|
+
totalEarned: BN;
|
|
28
|
+
lastUsed: BN;
|
|
29
|
+
createdAt: BN;
|
|
30
|
+
bump: number;
|
|
31
|
+
}>;
|
|
32
|
+
getAllSkills(): Promise<import("@coral-xyz/anchor").ProgramAccount<{
|
|
33
|
+
skillId: number[];
|
|
34
|
+
creator: PublicKey;
|
|
35
|
+
creatorSignature: number[];
|
|
36
|
+
priceUsdc: BN;
|
|
37
|
+
ipfsHash: string;
|
|
38
|
+
auditReportHash: string;
|
|
39
|
+
auditorCount: number;
|
|
40
|
+
auditors: any[];
|
|
41
|
+
consensusStatus: any;
|
|
42
|
+
consensusRecord: PublicKey | null;
|
|
43
|
+
trustScore: number;
|
|
44
|
+
executionCount: BN;
|
|
45
|
+
successCount: BN;
|
|
46
|
+
totalEarned: BN;
|
|
47
|
+
lastUsed: BN;
|
|
48
|
+
createdAt: BN;
|
|
49
|
+
bump: number;
|
|
50
|
+
}>[]>;
|
|
51
|
+
getAllLogs(): Promise<any>;
|
|
52
|
+
getAuditor(auditorPda: PublicKey): Promise<any>;
|
|
53
|
+
getAllAuditors(): Promise<any>;
|
|
54
|
+
getRegistry(): Promise<any>;
|
|
55
|
+
stakeUsdc(auditorPda: PublicKey, auditorTokenAccount: PublicKey, vaultTokenAccount: PublicKey, vaultAuthorityPda: PublicKey, usdcMint: PublicKey, amount: BN): Promise<string>;
|
|
56
|
+
requestUnstake(auditorPda: PublicKey): Promise<string>;
|
|
57
|
+
withdrawStake(auditorPda: PublicKey, auditorTokenAccount: PublicKey, vaultTokenAccount: PublicKey, vaultAuthorityPda: PublicKey, usdcMint: PublicKey): Promise<string>;
|
|
58
|
+
deriveSkillPda(skillId: number[] | Uint8Array): PublicKey;
|
|
59
|
+
deriveAuditorPda(auditorPubkey: PublicKey): PublicKey;
|
|
60
|
+
deriveVaultPda(usdcMint: PublicKey, auditorPda: PublicKey): PublicKey;
|
|
61
|
+
deriveVaultAuthorityPda(): PublicKey;
|
|
62
|
+
deriveExecutionLogPda(skillPda: PublicKey, executor: PublicKey, timestamp: BN): PublicKey;
|
|
63
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
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.SigilRegistryClient = void 0;
|
|
7
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
8
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
9
|
+
const sigil_registry_json_1 = __importDefault(require("../../target/idl/sigil_registry.json"));
|
|
10
|
+
class SigilRegistryClient {
|
|
11
|
+
constructor(connection, wallet) {
|
|
12
|
+
this.provider = new anchor_1.AnchorProvider(connection, wallet, {
|
|
13
|
+
commitment: 'confirmed',
|
|
14
|
+
});
|
|
15
|
+
this.program = new anchor_1.Program(sigil_registry_json_1.default, this.provider);
|
|
16
|
+
}
|
|
17
|
+
async initializeRegistry() {
|
|
18
|
+
const [registryPda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('registry_v1')], this.program.programId);
|
|
19
|
+
return await this.program.methods
|
|
20
|
+
.initializeRegistry()
|
|
21
|
+
.accounts({
|
|
22
|
+
registry: registryPda,
|
|
23
|
+
authority: this.provider.wallet.publicKey,
|
|
24
|
+
})
|
|
25
|
+
.rpc();
|
|
26
|
+
}
|
|
27
|
+
async initializeAuditor() {
|
|
28
|
+
const [auditorPda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('auditor'), this.provider.wallet.publicKey.toBuffer()], this.program.programId);
|
|
29
|
+
return await this.program.methods
|
|
30
|
+
.initializeAuditor()
|
|
31
|
+
.accounts({
|
|
32
|
+
auditor: auditorPda,
|
|
33
|
+
authority: this.provider.wallet.publicKey,
|
|
34
|
+
})
|
|
35
|
+
.rpc();
|
|
36
|
+
}
|
|
37
|
+
async mintSkill(skillId, priceUsdc, ipfsHash, creatorSignature) {
|
|
38
|
+
const [skillPda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('skill'), Buffer.from(skillId)], this.program.programId);
|
|
39
|
+
const [registryPda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('registry_v1')], this.program.programId);
|
|
40
|
+
return await this.program.methods
|
|
41
|
+
.mintSkill(skillId, priceUsdc, ipfsHash, creatorSignature)
|
|
42
|
+
.accounts({
|
|
43
|
+
skill: skillPda,
|
|
44
|
+
creator: this.provider.wallet.publicKey,
|
|
45
|
+
registry: registryPda,
|
|
46
|
+
})
|
|
47
|
+
.rpc();
|
|
48
|
+
}
|
|
49
|
+
async addAuditorSignature(skillPda, auditorPda, signature, auditReportHash) {
|
|
50
|
+
return await this.program.methods
|
|
51
|
+
.addAuditorSignature(signature, auditReportHash)
|
|
52
|
+
.accounts({
|
|
53
|
+
skill: skillPda,
|
|
54
|
+
auditor: auditorPda,
|
|
55
|
+
auditorSigner: this.provider.wallet.publicKey,
|
|
56
|
+
})
|
|
57
|
+
.rpc();
|
|
58
|
+
}
|
|
59
|
+
async logExecution(skillPda, executionLogPda, executorUsdc, creatorUsdc, protocolUsdc, success, latencyMs) {
|
|
60
|
+
return await this.program.methods
|
|
61
|
+
.logExecution(success, latencyMs)
|
|
62
|
+
.accounts({
|
|
63
|
+
skill: skillPda,
|
|
64
|
+
executionLog: executionLogPda,
|
|
65
|
+
executor: this.provider.wallet.publicKey,
|
|
66
|
+
executorUsdc,
|
|
67
|
+
creatorUsdc,
|
|
68
|
+
protocolUsdc,
|
|
69
|
+
})
|
|
70
|
+
.rpc();
|
|
71
|
+
}
|
|
72
|
+
async getSkill(skillPda) {
|
|
73
|
+
return await this.program.account.skill.fetch(skillPda);
|
|
74
|
+
}
|
|
75
|
+
async getAllSkills() {
|
|
76
|
+
return await this.program.account.skill.all();
|
|
77
|
+
}
|
|
78
|
+
async getAllLogs() {
|
|
79
|
+
// ExecutionLog account may not be defined in current IDL
|
|
80
|
+
// Return empty array for MVP - logs are tracked via transaction history
|
|
81
|
+
try {
|
|
82
|
+
// Try to fetch if account exists
|
|
83
|
+
const accounts = await this.program.account.executionLog?.all();
|
|
84
|
+
return accounts || [];
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
console.warn('ExecutionLog account not available in current program version');
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async getAuditor(auditorPda) {
|
|
92
|
+
// Auditor account may not be defined in current IDL
|
|
93
|
+
try {
|
|
94
|
+
return await this.program.account.auditor?.fetch(auditorPda);
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
console.warn('Auditor account not available in current program version');
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async getAllAuditors() {
|
|
102
|
+
// Auditor account may not be defined in current IDL
|
|
103
|
+
try {
|
|
104
|
+
const accounts = await this.program.account.auditor?.all();
|
|
105
|
+
return accounts || [];
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
console.warn('Auditor account not available in current program version');
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async getRegistry() {
|
|
113
|
+
const [registryPda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('registry_v1')], this.program.programId);
|
|
114
|
+
try {
|
|
115
|
+
// Account names in Anchor are camelCase versions of the struct name
|
|
116
|
+
return await this.program.account.skillRegistry.fetch(registryPda);
|
|
117
|
+
}
|
|
118
|
+
catch (e) {
|
|
119
|
+
// Try PascalCase as fallback
|
|
120
|
+
try {
|
|
121
|
+
return await this.program.account.SkillRegistry.fetch(registryPda);
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
console.warn('Registry not initialized');
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
async stakeUsdc(auditorPda, auditorTokenAccount, vaultTokenAccount, vaultAuthorityPda, usdcMint, amount) {
|
|
130
|
+
return await this.program.methods
|
|
131
|
+
.stakeUsdc(amount)
|
|
132
|
+
.accounts({
|
|
133
|
+
auditor: auditorPda,
|
|
134
|
+
auditorTokenAccount,
|
|
135
|
+
vaultTokenAccount,
|
|
136
|
+
vaultAuthority: vaultAuthorityPda,
|
|
137
|
+
usdcMint,
|
|
138
|
+
authority: this.provider.wallet.publicKey,
|
|
139
|
+
})
|
|
140
|
+
.rpc();
|
|
141
|
+
}
|
|
142
|
+
async requestUnstake(auditorPda) {
|
|
143
|
+
return await this.program.methods
|
|
144
|
+
.requestUnstake()
|
|
145
|
+
.accounts({
|
|
146
|
+
auditor: auditorPda,
|
|
147
|
+
authority: this.provider.wallet.publicKey,
|
|
148
|
+
})
|
|
149
|
+
.rpc();
|
|
150
|
+
}
|
|
151
|
+
async withdrawStake(auditorPda, auditorTokenAccount, vaultTokenAccount, vaultAuthorityPda, usdcMint) {
|
|
152
|
+
return await this.program.methods
|
|
153
|
+
.withdrawStake()
|
|
154
|
+
.accounts({
|
|
155
|
+
auditor: auditorPda,
|
|
156
|
+
auditorTokenAccount,
|
|
157
|
+
vaultTokenAccount,
|
|
158
|
+
vaultAuthority: vaultAuthorityPda,
|
|
159
|
+
usdcMint,
|
|
160
|
+
authority: this.provider.wallet.publicKey,
|
|
161
|
+
})
|
|
162
|
+
.rpc();
|
|
163
|
+
}
|
|
164
|
+
// Helper to derive PDAs
|
|
165
|
+
deriveSkillPda(skillId) {
|
|
166
|
+
const [pda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('skill'), Buffer.from(skillId)], this.program.programId);
|
|
167
|
+
return pda;
|
|
168
|
+
}
|
|
169
|
+
deriveAuditorPda(auditorPubkey) {
|
|
170
|
+
const [pda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('auditor'), auditorPubkey.toBuffer()], this.program.programId);
|
|
171
|
+
return pda;
|
|
172
|
+
}
|
|
173
|
+
deriveVaultPda(usdcMint, auditorPda) {
|
|
174
|
+
const [pda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('vault'), usdcMint.toBuffer(), auditorPda.toBuffer()], this.program.programId);
|
|
175
|
+
return pda;
|
|
176
|
+
}
|
|
177
|
+
deriveVaultAuthorityPda() {
|
|
178
|
+
const [pda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('vault_authority')], this.program.programId);
|
|
179
|
+
return pda;
|
|
180
|
+
}
|
|
181
|
+
deriveExecutionLogPda(skillPda, executor, timestamp) {
|
|
182
|
+
const [pda] = web3_js_1.PublicKey.findProgramAddressSync([
|
|
183
|
+
Buffer.from('execution'),
|
|
184
|
+
skillPda.toBuffer(),
|
|
185
|
+
executor.toBuffer(),
|
|
186
|
+
timestamp.toArrayLike(Buffer, 'le', 8)
|
|
187
|
+
], this.program.programId);
|
|
188
|
+
return pda;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
exports.SigilRegistryClient = SigilRegistryClient;
|