@magicblock-console/core 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/dist/client.d.ts +98 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +96 -0
- package/dist/client.js.map +1 -0
- package/dist/config.d.ts +41 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +94 -0
- package/dist/config.js.map +1 -0
- package/dist/connection.d.ts +42 -0
- package/dist/connection.d.ts.map +1 -0
- package/dist/connection.js +82 -0
- package/dist/connection.js.map +1 -0
- package/dist/cranks.d.ts +14 -0
- package/dist/cranks.d.ts.map +1 -0
- package/dist/cranks.js +128 -0
- package/dist/cranks.js.map +1 -0
- package/dist/er.d.ts +17 -0
- package/dist/er.d.ts.map +1 -0
- package/dist/er.js +314 -0
- package/dist/er.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/monitor.d.ts +21 -0
- package/dist/monitor.d.ts.map +1 -0
- package/dist/monitor.js +170 -0
- package/dist/monitor.js.map +1 -0
- package/dist/oracle.d.ts +13 -0
- package/dist/oracle.d.ts.map +1 -0
- package/dist/oracle.js +215 -0
- package/dist/oracle.js.map +1 -0
- package/dist/privacy.d.ts +14 -0
- package/dist/privacy.d.ts.map +1 -0
- package/dist/privacy.js +177 -0
- package/dist/privacy.js.map +1 -0
- package/dist/projects.d.ts +9 -0
- package/dist/projects.d.ts.map +1 -0
- package/dist/projects.js +94 -0
- package/dist/projects.js.map +1 -0
- package/dist/storage.d.ts +37 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +150 -0
- package/dist/storage.js.map +1 -0
- package/dist/types.d.ts +180 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +18 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +43 -0
- package/dist/utils.js.map +1 -0
- package/dist/vrf.d.ts +42 -0
- package/dist/vrf.d.ts.map +1 -0
- package/dist/vrf.js +117 -0
- package/dist/vrf.js.map +1 -0
- package/package.json +30 -0
package/dist/storage.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Storage Interface
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
// MemoryStorage — volatile, suitable for MCP and testing
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
export class MemoryStorage {
|
|
8
|
+
data = new Map();
|
|
9
|
+
async get(key) {
|
|
10
|
+
return this.data.get(key) ?? null;
|
|
11
|
+
}
|
|
12
|
+
async set(key, value) {
|
|
13
|
+
this.data.set(key, value);
|
|
14
|
+
}
|
|
15
|
+
async delete(key) {
|
|
16
|
+
this.data.delete(key);
|
|
17
|
+
}
|
|
18
|
+
async list(prefix) {
|
|
19
|
+
return Array.from(this.data.keys()).filter((k) => k.startsWith(prefix));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
// FileStorage — persists to ~/.mb-console/ on disk
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
export class FileStorage {
|
|
26
|
+
baseDir;
|
|
27
|
+
constructor(baseDir) {
|
|
28
|
+
if (baseDir) {
|
|
29
|
+
this.baseDir = baseDir;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
const home = typeof process !== 'undefined'
|
|
33
|
+
? process.env['HOME'] || process.env['USERPROFILE'] || '.'
|
|
34
|
+
: '.';
|
|
35
|
+
this.baseDir = `${home}/.mb-console`;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async fs() {
|
|
39
|
+
return await import('node:fs/promises');
|
|
40
|
+
}
|
|
41
|
+
async path() {
|
|
42
|
+
return await import('node:path');
|
|
43
|
+
}
|
|
44
|
+
/** Encode a key to a safe filename. */
|
|
45
|
+
encodeKey(key) {
|
|
46
|
+
return encodeURIComponent(key);
|
|
47
|
+
}
|
|
48
|
+
decodeKey(filename) {
|
|
49
|
+
return decodeURIComponent(filename);
|
|
50
|
+
}
|
|
51
|
+
async filePath(key) {
|
|
52
|
+
const p = await this.path();
|
|
53
|
+
const resolved = p.resolve(this.baseDir, this.encodeKey(key));
|
|
54
|
+
const resolvedBase = p.resolve(this.baseDir);
|
|
55
|
+
if (!resolved.startsWith(resolvedBase + p.sep) && resolved !== resolvedBase) {
|
|
56
|
+
throw new Error('Path traversal detected: key escapes base directory');
|
|
57
|
+
}
|
|
58
|
+
return resolved;
|
|
59
|
+
}
|
|
60
|
+
async ensureDir() {
|
|
61
|
+
const fsp = await this.fs();
|
|
62
|
+
await fsp.mkdir(this.baseDir, { recursive: true, mode: 0o700 });
|
|
63
|
+
}
|
|
64
|
+
async get(key) {
|
|
65
|
+
const fsp = await this.fs();
|
|
66
|
+
try {
|
|
67
|
+
const fp = await this.filePath(key);
|
|
68
|
+
return await fsp.readFile(fp, 'utf-8');
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
if (isNodeError(err) && err.code === 'ENOENT')
|
|
72
|
+
return null;
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async set(key, value) {
|
|
77
|
+
await this.ensureDir();
|
|
78
|
+
const fsp = await this.fs();
|
|
79
|
+
const fp = await this.filePath(key);
|
|
80
|
+
await fsp.writeFile(fp, value, { encoding: 'utf-8', mode: 0o600 });
|
|
81
|
+
}
|
|
82
|
+
async delete(key) {
|
|
83
|
+
const fsp = await this.fs();
|
|
84
|
+
try {
|
|
85
|
+
const fp = await this.filePath(key);
|
|
86
|
+
await fsp.unlink(fp);
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
if (isNodeError(err) && err.code === 'ENOENT')
|
|
90
|
+
return;
|
|
91
|
+
throw err;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async list(prefix) {
|
|
95
|
+
const fsp = await this.fs();
|
|
96
|
+
try {
|
|
97
|
+
const entries = await fsp.readdir(this.baseDir);
|
|
98
|
+
const encodedPrefix = this.encodeKey(prefix);
|
|
99
|
+
return entries
|
|
100
|
+
.filter((e) => e.startsWith(encodedPrefix))
|
|
101
|
+
.map((e) => this.decodeKey(e));
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
if (isNodeError(err) && err.code === 'ENOENT')
|
|
105
|
+
return [];
|
|
106
|
+
throw err;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// ---------------------------------------------------------------------------
|
|
111
|
+
// BrowserStorage — wraps localStorage with a key prefix
|
|
112
|
+
// ---------------------------------------------------------------------------
|
|
113
|
+
const BROWSER_PREFIX = 'mb-console:';
|
|
114
|
+
export class BrowserStorage {
|
|
115
|
+
getLocalStorage() {
|
|
116
|
+
if (typeof localStorage === 'undefined') {
|
|
117
|
+
throw new Error('BrowserStorage requires a browser environment with localStorage');
|
|
118
|
+
}
|
|
119
|
+
return localStorage;
|
|
120
|
+
}
|
|
121
|
+
async get(key) {
|
|
122
|
+
const store = this.getLocalStorage();
|
|
123
|
+
return store.getItem(BROWSER_PREFIX + key);
|
|
124
|
+
}
|
|
125
|
+
async set(key, value) {
|
|
126
|
+
const store = this.getLocalStorage();
|
|
127
|
+
store.setItem(BROWSER_PREFIX + key, value);
|
|
128
|
+
}
|
|
129
|
+
async delete(key) {
|
|
130
|
+
const store = this.getLocalStorage();
|
|
131
|
+
store.removeItem(BROWSER_PREFIX + key);
|
|
132
|
+
}
|
|
133
|
+
async list(prefix) {
|
|
134
|
+
const store = this.getLocalStorage();
|
|
135
|
+
const fullPrefix = BROWSER_PREFIX + prefix;
|
|
136
|
+
const keys = [];
|
|
137
|
+
for (let i = 0; i < store.length; i++) {
|
|
138
|
+
const raw = store.key(i);
|
|
139
|
+
if (raw && raw.startsWith(fullPrefix)) {
|
|
140
|
+
// Strip the BROWSER_PREFIX, return the logical key
|
|
141
|
+
keys.push(raw.slice(BROWSER_PREFIX.length));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return keys;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function isNodeError(err) {
|
|
148
|
+
return typeof err === 'object' && err !== null && 'code' in err;
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,oBAAoB;AACpB,8EAA8E;AAU9E,8EAA8E;AAC9E,yDAAyD;AACzD,8EAA8E;AAE9E,MAAM,OAAO,aAAa;IACP,IAAI,GAAG,IAAI,GAAG,EAAkB,CAAC;IAElD,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,KAAa;QAClC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAW;QACtB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAAc;QACvB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1E,CAAC;CACF;AAED,8EAA8E;AAC9E,mDAAmD;AACnD,8EAA8E;AAE9E,MAAM,OAAO,WAAW;IACL,OAAO,CAAS;IAEjC,YA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| 'eu' | 'asia';
|
|
2
|
+
export type Network = 'devnet' | 'mainnet';
|
|
3
|
+
export interface FeatureFlags {
|
|
4
|
+
gasless: boolean;
|
|
5
|
+
privacy: boolean;
|
|
6
|
+
vrf: boolean;
|
|
7
|
+
cranks: boolean;
|
|
8
|
+
oracle: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface Project {
|
|
11
|
+
name: string;
|
|
12
|
+
region: Region;
|
|
13
|
+
features: FeatureFlags;
|
|
14
|
+
createdAt: Date;
|
|
15
|
+
}
|
|
16
|
+
export interface DelegationResult {
|
|
17
|
+
signature: string;
|
|
18
|
+
validator: string;
|
|
19
|
+
delegatedAt: Date;
|
|
20
|
+
slot?: number;
|
|
21
|
+
/** True when the result was simulated (no real blockchain transaction). */
|
|
22
|
+
simulated: boolean;
|
|
23
|
+
}
|
|
24
|
+
export interface DelegationStatus {
|
|
25
|
+
isDelegated: boolean;
|
|
26
|
+
validator?: string;
|
|
27
|
+
validatorPubkey?: string;
|
|
28
|
+
delegatedAt?: Date;
|
|
29
|
+
}
|
|
30
|
+
export interface CommitResult {
|
|
31
|
+
signature: string;
|
|
32
|
+
slot: number;
|
|
33
|
+
/** True when the result was simulated (no real blockchain transaction). */
|
|
34
|
+
simulated: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface DelegatedAccount {
|
|
37
|
+
address: string;
|
|
38
|
+
validator: string;
|
|
39
|
+
delegatedAt: Date;
|
|
40
|
+
}
|
|
41
|
+
export interface StateDiff {
|
|
42
|
+
account: string;
|
|
43
|
+
baseLayerData: string;
|
|
44
|
+
erData: string;
|
|
45
|
+
isDifferent: boolean;
|
|
46
|
+
baseLayerLamports?: number;
|
|
47
|
+
erLamports?: number;
|
|
48
|
+
owner?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface VrfResult {
|
|
51
|
+
requestId: string;
|
|
52
|
+
randomness: Uint8Array;
|
|
53
|
+
proof: string;
|
|
54
|
+
latencyMs: number;
|
|
55
|
+
/** True when the result was simulated (no real on-chain VRF). */
|
|
56
|
+
simulated: boolean;
|
|
57
|
+
}
|
|
58
|
+
export interface Crank {
|
|
59
|
+
id: string;
|
|
60
|
+
intervalMs: number;
|
|
61
|
+
iterations: number;
|
|
62
|
+
executed: number;
|
|
63
|
+
status: 'running' | 'completed' | 'stopped';
|
|
64
|
+
/** Account being committed (when using real blockchain). */
|
|
65
|
+
account?: string;
|
|
66
|
+
/** Initial commit transaction signature (when using real blockchain). */
|
|
67
|
+
commitSignature?: string;
|
|
68
|
+
/** True when the result was simulated (no real blockchain transaction). */
|
|
69
|
+
simulated: boolean;
|
|
70
|
+
}
|
|
71
|
+
export interface PriceFeed {
|
|
72
|
+
feed: string;
|
|
73
|
+
price: number;
|
|
74
|
+
confidence: number;
|
|
75
|
+
timestamp: Date;
|
|
76
|
+
slot: number;
|
|
77
|
+
/** True when the price was simulated (no real on-chain read). */
|
|
78
|
+
simulated: boolean;
|
|
79
|
+
}
|
|
80
|
+
export interface PrivacyResult {
|
|
81
|
+
signature: string;
|
|
82
|
+
/** True when the result was simulated (no real blockchain transaction). */
|
|
83
|
+
simulated: boolean;
|
|
84
|
+
}
|
|
85
|
+
export interface ProjectStatus {
|
|
86
|
+
project: string;
|
|
87
|
+
region: string;
|
|
88
|
+
features: FeatureFlags;
|
|
89
|
+
accounts: DelegatedAccount[];
|
|
90
|
+
uptime: number;
|
|
91
|
+
transactionCount: number;
|
|
92
|
+
}
|
|
93
|
+
export interface CostBreakdown {
|
|
94
|
+
transactions: {
|
|
95
|
+
count: number;
|
|
96
|
+
cost: number;
|
|
97
|
+
};
|
|
98
|
+
commits: {
|
|
99
|
+
count: number;
|
|
100
|
+
cost: number;
|
|
101
|
+
};
|
|
102
|
+
sessions: {
|
|
103
|
+
count: number;
|
|
104
|
+
cost: number;
|
|
105
|
+
};
|
|
106
|
+
total: number;
|
|
107
|
+
period: string;
|
|
108
|
+
}
|
|
109
|
+
export interface LogEntry {
|
|
110
|
+
timestamp: Date;
|
|
111
|
+
type: string;
|
|
112
|
+
message: string;
|
|
113
|
+
data?: Record<string, unknown>;
|
|
114
|
+
}
|
|
115
|
+
export interface ClientOptions {
|
|
116
|
+
network?: Network;
|
|
117
|
+
storage?: import('./storage.js').Storage;
|
|
118
|
+
}
|
|
119
|
+
export interface CreateProjectOptions {
|
|
120
|
+
name: string;
|
|
121
|
+
region?: Region;
|
|
122
|
+
features?: Partial<FeatureFlags>;
|
|
123
|
+
}
|
|
124
|
+
export interface ConfigureProjectOptions {
|
|
125
|
+
features?: Partial<FeatureFlags>;
|
|
126
|
+
region?: Region;
|
|
127
|
+
}
|
|
128
|
+
export interface DelegateOptions {
|
|
129
|
+
account: string;
|
|
130
|
+
project: string;
|
|
131
|
+
/** Owner program of the delegated account (required for real blockchain ops). */
|
|
132
|
+
ownerProgram?: string;
|
|
133
|
+
}
|
|
134
|
+
export interface CommitOptions {
|
|
135
|
+
account: string;
|
|
136
|
+
project: string;
|
|
137
|
+
}
|
|
138
|
+
export interface UndelegateOptions {
|
|
139
|
+
account: string;
|
|
140
|
+
project: string;
|
|
141
|
+
/** Owner program of the delegated account (required for real blockchain ops). */
|
|
142
|
+
ownerProgram?: string;
|
|
143
|
+
}
|
|
144
|
+
export interface PrivacyDepositOptions {
|
|
145
|
+
project: string;
|
|
146
|
+
token: string;
|
|
147
|
+
amount: number;
|
|
148
|
+
/** SPL mint address (optional, for real blockchain operations). */
|
|
149
|
+
mint?: string;
|
|
150
|
+
}
|
|
151
|
+
export interface PrivacyTransferOptions {
|
|
152
|
+
project: string;
|
|
153
|
+
token: string;
|
|
154
|
+
amount: number;
|
|
155
|
+
to: string;
|
|
156
|
+
/** SPL mint address (optional, for real blockchain operations). */
|
|
157
|
+
mint?: string;
|
|
158
|
+
}
|
|
159
|
+
export interface PrivacyWithdrawOptions {
|
|
160
|
+
project: string;
|
|
161
|
+
token: string;
|
|
162
|
+
amount: number;
|
|
163
|
+
/** SPL mint address (optional, for real blockchain operations). */
|
|
164
|
+
mint?: string;
|
|
165
|
+
}
|
|
166
|
+
export interface CrankCreateOptions {
|
|
167
|
+
project: string;
|
|
168
|
+
intervalMs: number;
|
|
169
|
+
iterations?: number;
|
|
170
|
+
/** Account to commit (required for real blockchain operations). */
|
|
171
|
+
account?: string;
|
|
172
|
+
}
|
|
173
|
+
export interface PriceFeedOptions {
|
|
174
|
+
project: string;
|
|
175
|
+
feed: string;
|
|
176
|
+
}
|
|
177
|
+
export interface VrfRequestOptions {
|
|
178
|
+
project: string;
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,MAAM,GAAG,IAAI,GAAG,IAAI,GAAG,MAAM,CAAC;AAC1C,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC;AAM3C,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,OAAO,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;CACjB;AAMD,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,YAAY,CAAC;IACvB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,IAAI,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2EAA2E;IAC3E,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IAC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AAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;CACjB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate a random base58 string of the given length.
|
|
3
|
+
* Uses crypto.getRandomValues() for secure randomness.
|
|
4
|
+
*/
|
|
5
|
+
export declare function generateBase58(length: number): string;
|
|
6
|
+
/** Generate a realistic-looking base58 transaction signature (88 chars). */
|
|
7
|
+
export declare function generateSignature(): string;
|
|
8
|
+
/**
|
|
9
|
+
* Validate that a string looks like a Solana public key (base58, 32-44 chars).
|
|
10
|
+
* Does NOT verify that the key is on-curve — only checks format.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isValidPubkey(value: string): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Assert that a value is a valid-looking Solana public key.
|
|
15
|
+
* Throws a descriptive error if invalid.
|
|
16
|
+
*/
|
|
17
|
+
export declare function assertPubkey(value: string, label?: string): void;
|
|
18
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAQrD;AAED,4EAA4E;AAC5E,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAQD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,SAAY,GAAG,IAAI,CAOnE"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Shared utilities
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
const BASE58_CHARS = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
5
|
+
/**
|
|
6
|
+
* Generate a random base58 string of the given length.
|
|
7
|
+
* Uses crypto.getRandomValues() for secure randomness.
|
|
8
|
+
*/
|
|
9
|
+
export function generateBase58(length) {
|
|
10
|
+
const bytes = new Uint8Array(length);
|
|
11
|
+
crypto.getRandomValues(bytes);
|
|
12
|
+
let result = '';
|
|
13
|
+
for (let i = 0; i < length; i++) {
|
|
14
|
+
result += BASE58_CHARS[bytes[i] % BASE58_CHARS.length];
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
/** Generate a realistic-looking base58 transaction signature (88 chars). */
|
|
19
|
+
export function generateSignature() {
|
|
20
|
+
return generateBase58(88);
|
|
21
|
+
}
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
// Validation
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
const BASE58_REGEX = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
|
|
26
|
+
/**
|
|
27
|
+
* Validate that a string looks like a Solana public key (base58, 32-44 chars).
|
|
28
|
+
* Does NOT verify that the key is on-curve — only checks format.
|
|
29
|
+
*/
|
|
30
|
+
export function isValidPubkey(value) {
|
|
31
|
+
return BASE58_REGEX.test(value);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Assert that a value is a valid-looking Solana public key.
|
|
35
|
+
* Throws a descriptive error if invalid.
|
|
36
|
+
*/
|
|
37
|
+
export function assertPubkey(value, label = 'address') {
|
|
38
|
+
if (!isValidPubkey(value)) {
|
|
39
|
+
throw new Error(`Invalid Solana ${label}: "${value}". ` +
|
|
40
|
+
'Expected a base58-encoded public key (32-44 characters).');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E,MAAM,YAAY,GAAG,4DAA4D,CAAC;AAElF;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IACrC,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IAC9B,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,MAAM,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC,CAAE,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IAC1D,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,iBAAiB;IAC/B,OAAO,cAAc,CAAC,EAAE,CAAC,CAAC;AAC5B,CAAC;AAED,8EAA8E;AAC9E,aAAa;AACb,8EAA8E;AAE9E,MAAM,YAAY,GAAG,+BAA+B,CAAC;AAErD;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAClC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa,EAAE,KAAK,GAAG,SAAS;IAC3D,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CACb,kBAAkB,KAAK,MAAM,KAAK,KAAK;YACvC,0DAA0D,CAC3D,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/dist/vrf.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Storage } from './storage.js';
|
|
2
|
+
import type { Network } from './types.js';
|
|
3
|
+
import type { VrfNamespace } from './client.js';
|
|
4
|
+
/**
|
|
5
|
+
* Create a fully-functional `VrfNamespace` backed by the given Storage.
|
|
6
|
+
*
|
|
7
|
+
* The `request()` method validates the project, generates 32 bytes of
|
|
8
|
+
* cryptographic randomness, and returns a simulated VRF result with
|
|
9
|
+
* proof and latency metrics.
|
|
10
|
+
*
|
|
11
|
+
* NOTE: Randomness generation uses `crypto.getRandomValues` which is
|
|
12
|
+
* cryptographically secure, but the proof is simulated for hackathon demo.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createVrfNamespace(storage: Storage, _network: Network): VrfNamespace;
|
|
15
|
+
/**
|
|
16
|
+
* Utility functions for working with VRF randomness output.
|
|
17
|
+
*
|
|
18
|
+
* These helpers make it easy to derive usable random values from the
|
|
19
|
+
* raw 32-byte randomness returned by `client.vrf.request()`.
|
|
20
|
+
*/
|
|
21
|
+
export declare const vrf: {
|
|
22
|
+
/**
|
|
23
|
+
* Derive a random integer in the range [min, max] (inclusive) from
|
|
24
|
+
* the first 4 bytes of the randomness output.
|
|
25
|
+
*/
|
|
26
|
+
randomInRange(randomBytes: Uint8Array, min: number, max: number): number;
|
|
27
|
+
/**
|
|
28
|
+
* Pick a random element from an array using the VRF randomness.
|
|
29
|
+
*/
|
|
30
|
+
randomPick<T>(randomBytes: Uint8Array, items: T[]): T;
|
|
31
|
+
/**
|
|
32
|
+
* Split 32 bytes of randomness into `count` equal-sized chunks.
|
|
33
|
+
*
|
|
34
|
+
* Each chunk can be used as independent randomness for different
|
|
35
|
+
* purposes (e.g., multiple dice rolls from a single VRF request).
|
|
36
|
+
*
|
|
37
|
+
* If 32 is not evenly divisible by `count`, the last chunk may
|
|
38
|
+
* include fewer bytes. Minimum chunk size is 1 byte.
|
|
39
|
+
*/
|
|
40
|
+
split(randomBytes: Uint8Array, count: number): Uint8Array[];
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=vrf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vrf.d.ts","sourceRoot":"","sources":["../src/vrf.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAyC,MAAM,YAAY,CAAC;AACjF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AA6BhD;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,OAAO,GAChB,YAAY,CA6Bd;AAMD;;;;;GAKG;AACH,eAAO,MAAM,GAAG;IACd;;;OAGG;+BACwB,UAAU,OAAO,MAAM,OAAO,MAAM,GAAG,MAAM;IAUxE;;OAEG;eACQ,CAAC,eAAe,UAAU,SAAS,CAAC,EAAE,GAAG,CAAC;IAQrD;;;;;;;;OAQG;uBACgB,UAAU,SAAS,MAAM,GAAG,UAAU,EAAE;CAmB5D,CAAC"}
|
package/dist/vrf.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { generateBase58 } from './utils.js';
|
|
2
|
+
// ---------------------------------------------------------------------------
|
|
3
|
+
// Helpers
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
/**
|
|
6
|
+
* Load a project from storage and validate that the VRF feature is enabled.
|
|
7
|
+
*/
|
|
8
|
+
async function requireVrfEnabled(storage, project) {
|
|
9
|
+
const data = await storage.get(`project:${project}`);
|
|
10
|
+
if (!data) {
|
|
11
|
+
throw new Error(`Project "${project}" not found`);
|
|
12
|
+
}
|
|
13
|
+
const parsed = JSON.parse(data);
|
|
14
|
+
if (!parsed.features.vrf) {
|
|
15
|
+
throw new Error(`Feature "vrf" is not enabled for project "${project}". ` +
|
|
16
|
+
`Enable it with: client.projects.configure("${project}", { features: { vrf: true } })`);
|
|
17
|
+
}
|
|
18
|
+
return parsed;
|
|
19
|
+
}
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// Factory
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
/**
|
|
24
|
+
* Create a fully-functional `VrfNamespace` backed by the given Storage.
|
|
25
|
+
*
|
|
26
|
+
* The `request()` method validates the project, generates 32 bytes of
|
|
27
|
+
* cryptographic randomness, and returns a simulated VRF result with
|
|
28
|
+
* proof and latency metrics.
|
|
29
|
+
*
|
|
30
|
+
* NOTE: Randomness generation uses `crypto.getRandomValues` which is
|
|
31
|
+
* cryptographically secure, but the proof is simulated for hackathon demo.
|
|
32
|
+
*/
|
|
33
|
+
export function createVrfNamespace(storage, _network) {
|
|
34
|
+
return {
|
|
35
|
+
async request(options) {
|
|
36
|
+
await requireVrfEnabled(storage, options.project);
|
|
37
|
+
const start = performance.now();
|
|
38
|
+
// Generate 32 bytes of cryptographic randomness
|
|
39
|
+
const randomness = new Uint8Array(32);
|
|
40
|
+
crypto.getRandomValues(randomness);
|
|
41
|
+
// Simulate realistic VRF latency (80-120ms)
|
|
42
|
+
const targetLatency = 80 + Math.random() * 40;
|
|
43
|
+
const elapsed = performance.now() - start;
|
|
44
|
+
if (elapsed < targetLatency) {
|
|
45
|
+
await new Promise((resolve) => setTimeout(resolve, targetLatency - elapsed));
|
|
46
|
+
}
|
|
47
|
+
const latencyMs = Math.round(performance.now() - start);
|
|
48
|
+
return {
|
|
49
|
+
requestId: `vrf_${Date.now().toString(36)}_${generateBase58(8)}`,
|
|
50
|
+
randomness,
|
|
51
|
+
proof: generateBase58(128),
|
|
52
|
+
latencyMs,
|
|
53
|
+
simulated: true,
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
// VRF Utility Functions
|
|
60
|
+
// ---------------------------------------------------------------------------
|
|
61
|
+
/**
|
|
62
|
+
* Utility functions for working with VRF randomness output.
|
|
63
|
+
*
|
|
64
|
+
* These helpers make it easy to derive usable random values from the
|
|
65
|
+
* raw 32-byte randomness returned by `client.vrf.request()`.
|
|
66
|
+
*/
|
|
67
|
+
export const vrf = {
|
|
68
|
+
/**
|
|
69
|
+
* Derive a random integer in the range [min, max] (inclusive) from
|
|
70
|
+
* the first 4 bytes of the randomness output.
|
|
71
|
+
*/
|
|
72
|
+
randomInRange(randomBytes, min, max) {
|
|
73
|
+
if (min > max) {
|
|
74
|
+
throw new Error(`min (${min}) must be <= max (${max})`);
|
|
75
|
+
}
|
|
76
|
+
// Read first 4 bytes as a big-endian uint32
|
|
77
|
+
const view = new DataView(randomBytes.buffer, randomBytes.byteOffset, randomBytes.byteLength);
|
|
78
|
+
const value = view.getUint32(0);
|
|
79
|
+
return min + (value % (max - min + 1));
|
|
80
|
+
},
|
|
81
|
+
/**
|
|
82
|
+
* Pick a random element from an array using the VRF randomness.
|
|
83
|
+
*/
|
|
84
|
+
randomPick(randomBytes, items) {
|
|
85
|
+
if (items.length === 0) {
|
|
86
|
+
throw new Error('Cannot pick from an empty array');
|
|
87
|
+
}
|
|
88
|
+
const index = vrf.randomInRange(randomBytes, 0, items.length - 1);
|
|
89
|
+
return items[index];
|
|
90
|
+
},
|
|
91
|
+
/**
|
|
92
|
+
* Split 32 bytes of randomness into `count` equal-sized chunks.
|
|
93
|
+
*
|
|
94
|
+
* Each chunk can be used as independent randomness for different
|
|
95
|
+
* purposes (e.g., multiple dice rolls from a single VRF request).
|
|
96
|
+
*
|
|
97
|
+
* If 32 is not evenly divisible by `count`, the last chunk may
|
|
98
|
+
* include fewer bytes. Minimum chunk size is 1 byte.
|
|
99
|
+
*/
|
|
100
|
+
split(randomBytes, count) {
|
|
101
|
+
if (count <= 0) {
|
|
102
|
+
throw new Error('count must be greater than 0');
|
|
103
|
+
}
|
|
104
|
+
if (count > randomBytes.length) {
|
|
105
|
+
throw new Error(`Cannot split ${randomBytes.length} bytes into ${count} chunks`);
|
|
106
|
+
}
|
|
107
|
+
const chunkSize = Math.floor(randomBytes.length / count);
|
|
108
|
+
const chunks = [];
|
|
109
|
+
for (let i = 0; i < count; i++) {
|
|
110
|
+
const start = i * chunkSize;
|
|
111
|
+
const end = i === count - 1 ? randomBytes.length : start + chunkSize;
|
|
112
|
+
chunks.push(randomBytes.slice(start, end));
|
|
113
|
+
}
|
|
114
|
+
return chunks;
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
//# sourceMappingURL=vrf.js.map
|
package/dist/vrf.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vrf.js","sourceRoot":"","sources":["../src/vrf.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E;;GAEG;AACH,KAAK,UAAU,iBAAiB,CAAC,OAAgB,EAAE,OAAe;IAChE,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,WAAW,OAAO,EAAE,CAAC,CAAC;IACrD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CAAC,YAAY,OAAO,aAAa,CAAC,CAAC;IACpD,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAY,CAAC;IAC3C,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,6CAA6C,OAAO,KAAK;YACvD,8CAA8C,OAAO,iCAAiC,CACzF,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAAgB,EAChB,QAAiB;IAEjB,OAA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AAM,KAAK,GAAG,CAAC,GAAG,SAAS,CAAC;YAC5B,MAAM,GAAG,GAAG,CAAC,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,SAAS,CAAC;YACrE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;QAC7C,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@magicblock-console/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Core SDK for MagicBlock Ephemeral Rollups — shared logic for CLI, MCP, and Web",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": ["dist"],
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc",
|
|
18
|
+
"dev": "tsc --watch",
|
|
19
|
+
"lint": "tsc --noEmit"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@solana/spl-token": "^0.4.9",
|
|
23
|
+
"@solana/web3.js": "^1.98.0",
|
|
24
|
+
"@magicblock-labs/ephemeral-rollups-sdk": "^0.8.5",
|
|
25
|
+
"bs58": "^6.0.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"typescript": "^5.7.0"
|
|
29
|
+
}
|
|
30
|
+
}
|