@dimcool/sdk 0.1.2 → 0.1.7
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 +19 -0
- package/dist/index.cjs +1820 -1696
- package/dist/index.d.cts +85 -2
- package/dist/index.d.ts +85 -2
- package/dist/index.js +1820 -1696
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11854,655 +11854,6 @@ var NodeStorage = class {
|
|
|
11854
11854
|
// src/version.ts
|
|
11855
11855
|
var SDK_VERSION = "1.0.0";
|
|
11856
11856
|
|
|
11857
|
-
// src/http-client.ts
|
|
11858
|
-
var HttpClient = class {
|
|
11859
|
-
constructor(baseUrl, storage, logger2, appId) {
|
|
11860
|
-
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
11861
|
-
this.storage = storage;
|
|
11862
|
-
this.logger = logger2 || logger;
|
|
11863
|
-
this.appId = appId;
|
|
11864
|
-
}
|
|
11865
|
-
async request(endpoint, options = {}) {
|
|
11866
|
-
const url2 = `${this.baseUrl}${endpoint}`;
|
|
11867
|
-
const token = this.storage.get(TOKEN_KEY);
|
|
11868
|
-
this.logger.debug("HTTP request", {
|
|
11869
|
-
method: options.method || "GET",
|
|
11870
|
-
endpoint,
|
|
11871
|
-
url: url2,
|
|
11872
|
-
hasToken: !!token
|
|
11873
|
-
});
|
|
11874
|
-
const headers = {
|
|
11875
|
-
"Content-Type": "application/json",
|
|
11876
|
-
"X-SDK-Version": SDK_VERSION,
|
|
11877
|
-
...options.headers
|
|
11878
|
-
};
|
|
11879
|
-
if (this.appId) {
|
|
11880
|
-
headers["X-App-Id"] = this.appId;
|
|
11881
|
-
}
|
|
11882
|
-
if (token) {
|
|
11883
|
-
headers["Authorization"] = `Bearer ${token}`;
|
|
11884
|
-
}
|
|
11885
|
-
const response = await fetch(url2, {
|
|
11886
|
-
...options,
|
|
11887
|
-
headers
|
|
11888
|
-
});
|
|
11889
|
-
this.logger.debug("HTTP response", {
|
|
11890
|
-
method: options.method || "GET",
|
|
11891
|
-
endpoint,
|
|
11892
|
-
status: response.status,
|
|
11893
|
-
ok: response.ok
|
|
11894
|
-
});
|
|
11895
|
-
if (!response.ok) {
|
|
11896
|
-
if (response.status === 426) {
|
|
11897
|
-
let upgradeMessage = "SDK version outdated. Run: npm install @dimcool/sdk@latest";
|
|
11898
|
-
try {
|
|
11899
|
-
const errorData = await response.json();
|
|
11900
|
-
if (typeof errorData.message === "string") {
|
|
11901
|
-
upgradeMessage = errorData.message;
|
|
11902
|
-
}
|
|
11903
|
-
} catch {
|
|
11904
|
-
}
|
|
11905
|
-
this.logger.error("SDK upgrade required", {
|
|
11906
|
-
endpoint,
|
|
11907
|
-
sdkVersion: SDK_VERSION,
|
|
11908
|
-
message: upgradeMessage
|
|
11909
|
-
});
|
|
11910
|
-
const error2 = new Error(upgradeMessage);
|
|
11911
|
-
error2.code = "SDK_UPGRADE_REQUIRED";
|
|
11912
|
-
error2.statusCode = 426;
|
|
11913
|
-
throw error2;
|
|
11914
|
-
}
|
|
11915
|
-
if (response.status === 401) {
|
|
11916
|
-
this.logger.warn("Unauthorized response, clearing token", { endpoint });
|
|
11917
|
-
this.storage.delete(TOKEN_KEY);
|
|
11918
|
-
throw new Error("Unauthorized - please login again");
|
|
11919
|
-
}
|
|
11920
|
-
let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
|
|
11921
|
-
let errorCode;
|
|
11922
|
-
try {
|
|
11923
|
-
const errorData = await response.json();
|
|
11924
|
-
errorCode = errorData.code;
|
|
11925
|
-
if (typeof errorData.message === "string" && errorData.message.trim()) {
|
|
11926
|
-
errorMessage = errorData.message;
|
|
11927
|
-
} else if (Array.isArray(errorData.message) && errorData.message.length) {
|
|
11928
|
-
errorMessage = errorData.message.join(", ");
|
|
11929
|
-
} else if (typeof errorData.error === "string" && errorData.error.trim()) {
|
|
11930
|
-
errorMessage = errorData.error;
|
|
11931
|
-
}
|
|
11932
|
-
} catch {
|
|
11933
|
-
}
|
|
11934
|
-
this.logger.error("HTTP request failed", {
|
|
11935
|
-
endpoint,
|
|
11936
|
-
status: response.status,
|
|
11937
|
-
error: errorMessage,
|
|
11938
|
-
code: errorCode
|
|
11939
|
-
});
|
|
11940
|
-
const error = new Error(errorMessage);
|
|
11941
|
-
error.code = errorCode;
|
|
11942
|
-
error.statusCode = response.status;
|
|
11943
|
-
throw error;
|
|
11944
|
-
}
|
|
11945
|
-
const contentType = response.headers.get("content-type");
|
|
11946
|
-
if (contentType && contentType.includes("application/json")) {
|
|
11947
|
-
const data = await response.json();
|
|
11948
|
-
this.logger.debug("HTTP response parsed", { endpoint, hasData: !!data });
|
|
11949
|
-
return data;
|
|
11950
|
-
}
|
|
11951
|
-
this.logger.debug("HTTP response empty", { endpoint });
|
|
11952
|
-
return {};
|
|
11953
|
-
}
|
|
11954
|
-
get(endpoint, options) {
|
|
11955
|
-
return this.request(endpoint, { ...options, method: "GET" });
|
|
11956
|
-
}
|
|
11957
|
-
post(endpoint, data, options) {
|
|
11958
|
-
return this.request(endpoint, {
|
|
11959
|
-
...options,
|
|
11960
|
-
method: "POST",
|
|
11961
|
-
body: data ? JSON.stringify(data) : void 0
|
|
11962
|
-
});
|
|
11963
|
-
}
|
|
11964
|
-
patch(endpoint, data, options) {
|
|
11965
|
-
return this.request(endpoint, {
|
|
11966
|
-
...options,
|
|
11967
|
-
method: "PATCH",
|
|
11968
|
-
body: data ? JSON.stringify(data) : void 0
|
|
11969
|
-
});
|
|
11970
|
-
}
|
|
11971
|
-
delete(endpoint, options) {
|
|
11972
|
-
return this.request(endpoint, { ...options, method: "DELETE" });
|
|
11973
|
-
}
|
|
11974
|
-
async upload(endpoint, formData) {
|
|
11975
|
-
const url2 = `${this.baseUrl}${endpoint}`;
|
|
11976
|
-
const token = this.storage.get(TOKEN_KEY);
|
|
11977
|
-
this.logger.debug("HTTP upload request", {
|
|
11978
|
-
method: "POST",
|
|
11979
|
-
endpoint,
|
|
11980
|
-
url: url2,
|
|
11981
|
-
hasToken: !!token
|
|
11982
|
-
});
|
|
11983
|
-
const headers = {
|
|
11984
|
-
"X-SDK-Version": SDK_VERSION
|
|
11985
|
-
};
|
|
11986
|
-
if (this.appId) {
|
|
11987
|
-
headers["X-App-Id"] = this.appId;
|
|
11988
|
-
}
|
|
11989
|
-
if (token) {
|
|
11990
|
-
headers["Authorization"] = `Bearer ${token}`;
|
|
11991
|
-
}
|
|
11992
|
-
const response = await fetch(url2, {
|
|
11993
|
-
method: "POST",
|
|
11994
|
-
headers,
|
|
11995
|
-
body: formData
|
|
11996
|
-
});
|
|
11997
|
-
this.logger.debug("HTTP upload response", {
|
|
11998
|
-
method: "POST",
|
|
11999
|
-
endpoint,
|
|
12000
|
-
status: response.status,
|
|
12001
|
-
ok: response.ok
|
|
12002
|
-
});
|
|
12003
|
-
if (!response.ok) {
|
|
12004
|
-
if (response.status === 426) {
|
|
12005
|
-
let upgradeMessage = "SDK version outdated. Run: npm install @dimcool/sdk@latest";
|
|
12006
|
-
try {
|
|
12007
|
-
const errorData = await response.json();
|
|
12008
|
-
if (typeof errorData.message === "string") {
|
|
12009
|
-
upgradeMessage = errorData.message;
|
|
12010
|
-
}
|
|
12011
|
-
} catch {
|
|
12012
|
-
}
|
|
12013
|
-
this.logger.error("SDK upgrade required", {
|
|
12014
|
-
endpoint,
|
|
12015
|
-
sdkVersion: SDK_VERSION,
|
|
12016
|
-
message: upgradeMessage
|
|
12017
|
-
});
|
|
12018
|
-
const error = new Error(upgradeMessage);
|
|
12019
|
-
error.code = "SDK_UPGRADE_REQUIRED";
|
|
12020
|
-
error.statusCode = 426;
|
|
12021
|
-
throw error;
|
|
12022
|
-
}
|
|
12023
|
-
if (response.status === 401) {
|
|
12024
|
-
this.logger.warn("Unauthorized response, clearing token", { endpoint });
|
|
12025
|
-
this.storage.delete(TOKEN_KEY);
|
|
12026
|
-
throw new Error("Unauthorized - please login again");
|
|
12027
|
-
}
|
|
12028
|
-
let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
|
|
12029
|
-
try {
|
|
12030
|
-
const errorData = await response.json();
|
|
12031
|
-
errorMessage = errorData.error || errorMessage;
|
|
12032
|
-
} catch {
|
|
12033
|
-
}
|
|
12034
|
-
this.logger.error("HTTP upload failed", {
|
|
12035
|
-
endpoint,
|
|
12036
|
-
status: response.status,
|
|
12037
|
-
error: errorMessage
|
|
12038
|
-
});
|
|
12039
|
-
throw new Error(errorMessage);
|
|
12040
|
-
}
|
|
12041
|
-
const contentType = response.headers.get("content-type");
|
|
12042
|
-
if (contentType && contentType.includes("application/json")) {
|
|
12043
|
-
const data = await response.json();
|
|
12044
|
-
this.logger.debug("HTTP upload response parsed", {
|
|
12045
|
-
endpoint,
|
|
12046
|
-
hasData: !!data
|
|
12047
|
-
});
|
|
12048
|
-
return data;
|
|
12049
|
-
}
|
|
12050
|
-
this.logger.debug("HTTP upload response empty", { endpoint });
|
|
12051
|
-
return {};
|
|
12052
|
-
}
|
|
12053
|
-
};
|
|
12054
|
-
|
|
12055
|
-
// src/auth.ts
|
|
12056
|
-
function toBase64(bytes) {
|
|
12057
|
-
if (typeof Buffer !== "undefined") {
|
|
12058
|
-
return Buffer.from(bytes).toString("base64");
|
|
12059
|
-
}
|
|
12060
|
-
let binary = "";
|
|
12061
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
12062
|
-
binary += String.fromCharCode(bytes[i]);
|
|
12063
|
-
}
|
|
12064
|
-
if (typeof btoa === "undefined") {
|
|
12065
|
-
throw new Error("Base64 encoding is not available in this environment");
|
|
12066
|
-
}
|
|
12067
|
-
return btoa(binary);
|
|
12068
|
-
}
|
|
12069
|
-
var Auth = class {
|
|
12070
|
-
constructor(http2, storage, wallet, logger2) {
|
|
12071
|
-
this.http = http2;
|
|
12072
|
-
this.storage = storage;
|
|
12073
|
-
this.wallet = wallet;
|
|
12074
|
-
this.logger = logger2 || logger;
|
|
12075
|
-
}
|
|
12076
|
-
async login(email, password) {
|
|
12077
|
-
this.logger.debug("Auth.login called", { email });
|
|
12078
|
-
const response = await this.http.post("/auth/login", {
|
|
12079
|
-
email,
|
|
12080
|
-
password
|
|
12081
|
-
});
|
|
12082
|
-
this.logger.debug("Login response received", {
|
|
12083
|
-
userId: response.user.id,
|
|
12084
|
-
hasToken: !!response.access_token,
|
|
12085
|
-
tokenLength: response.access_token?.length
|
|
12086
|
-
});
|
|
12087
|
-
if (!response.access_token) {
|
|
12088
|
-
throw new Error("Login response missing access_token");
|
|
12089
|
-
}
|
|
12090
|
-
this.storage.set(TOKEN_KEY, response.access_token);
|
|
12091
|
-
const storedToken = this.storage.get(TOKEN_KEY);
|
|
12092
|
-
if (!storedToken || storedToken !== response.access_token) {
|
|
12093
|
-
throw new Error(
|
|
12094
|
-
`Token storage failed! Expected: ${response.access_token.substring(0, 20)}..., Got: ${storedToken?.substring(0, 20)}...`
|
|
12095
|
-
);
|
|
12096
|
-
}
|
|
12097
|
-
this.logger.debug("Token stored in storage", {
|
|
12098
|
-
tokenKey: TOKEN_KEY,
|
|
12099
|
-
stored: !!storedToken,
|
|
12100
|
-
storedTokenLength: storedToken?.length,
|
|
12101
|
-
storageType: this.storage.constructor.name
|
|
12102
|
-
});
|
|
12103
|
-
return response;
|
|
12104
|
-
}
|
|
12105
|
-
async generateHandshake(walletAddress) {
|
|
12106
|
-
this.logger.debug("Auth.generateHandshake called", { walletAddress });
|
|
12107
|
-
const response = await this.http.post(
|
|
12108
|
-
"/auth/handshake",
|
|
12109
|
-
{
|
|
12110
|
-
walletAddress
|
|
12111
|
-
}
|
|
12112
|
-
);
|
|
12113
|
-
this.logger.debug("Handshake generated", {
|
|
12114
|
-
hasMessage: !!response.message,
|
|
12115
|
-
hasNonce: !!response.nonce
|
|
12116
|
-
});
|
|
12117
|
-
return response;
|
|
12118
|
-
}
|
|
12119
|
-
async loginWithWallet(options) {
|
|
12120
|
-
const address = this.wallet.getSignerAddress();
|
|
12121
|
-
if (!address) {
|
|
12122
|
-
throw new Error(
|
|
12123
|
-
"Wallet signer address is required for wallet login. Set sdk.wallet.setSigner({ address, signMessage, signTransaction })."
|
|
12124
|
-
);
|
|
12125
|
-
}
|
|
12126
|
-
if (!this.wallet.hasSigner()) {
|
|
12127
|
-
throw new Error(
|
|
12128
|
-
"No signer configured. Call sdk.wallet.setSigner(...) before wallet login."
|
|
12129
|
-
);
|
|
12130
|
-
}
|
|
12131
|
-
const { message } = await this.generateHandshake(address);
|
|
12132
|
-
const signatureResult = await this.wallet.signMessage(message);
|
|
12133
|
-
const signedMessage = typeof signatureResult === "string" ? signatureResult : toBase64(signatureResult);
|
|
12134
|
-
this.logger.debug("Auth.loginWithWallet called", {
|
|
12135
|
-
address,
|
|
12136
|
-
walletMeta: options?.walletMeta
|
|
12137
|
-
});
|
|
12138
|
-
const response = await this.http.post("/auth/login-wallet", {
|
|
12139
|
-
signedMessage,
|
|
12140
|
-
address,
|
|
12141
|
-
referralCode: options?.referralCode,
|
|
12142
|
-
walletMeta: options?.walletMeta
|
|
12143
|
-
});
|
|
12144
|
-
this.logger.debug("Wallet login response received", {
|
|
12145
|
-
userId: response.user.id,
|
|
12146
|
-
hasToken: !!response.access_token
|
|
12147
|
-
});
|
|
12148
|
-
this.storage.set(TOKEN_KEY, response.access_token);
|
|
12149
|
-
this.logger.debug("Token stored in storage", { tokenKey: TOKEN_KEY });
|
|
12150
|
-
return response;
|
|
12151
|
-
}
|
|
12152
|
-
logout() {
|
|
12153
|
-
this.logger.debug("Auth.logout called");
|
|
12154
|
-
const hadToken = this.storage.get(TOKEN_KEY) !== null;
|
|
12155
|
-
this.storage.delete(TOKEN_KEY);
|
|
12156
|
-
this.logger.debug("Token removed from storage", { hadToken });
|
|
12157
|
-
}
|
|
12158
|
-
isAuthenticated() {
|
|
12159
|
-
const isAuth = this.storage.get(TOKEN_KEY) !== null;
|
|
12160
|
-
this.logger.debug("Auth.isAuthenticated called", {
|
|
12161
|
-
isAuthenticated: isAuth
|
|
12162
|
-
});
|
|
12163
|
-
return isAuth;
|
|
12164
|
-
}
|
|
12165
|
-
async getLatestSessions(limit) {
|
|
12166
|
-
this.logger.debug("Auth.getLatestSessions called", { limit });
|
|
12167
|
-
const params = new URLSearchParams();
|
|
12168
|
-
if (limit !== void 0) {
|
|
12169
|
-
params.append("limit", limit.toString());
|
|
12170
|
-
}
|
|
12171
|
-
const queryString = params.toString();
|
|
12172
|
-
const endpoint = queryString ? `/auth/sessions?${queryString}` : "/auth/sessions";
|
|
12173
|
-
const response = await this.http.get(endpoint);
|
|
12174
|
-
this.logger.debug("Latest sessions retrieved", { total: response.total });
|
|
12175
|
-
return response;
|
|
12176
|
-
}
|
|
12177
|
-
};
|
|
12178
|
-
|
|
12179
|
-
// src/admin.ts
|
|
12180
|
-
var Admin = class {
|
|
12181
|
-
constructor(http2, logger2) {
|
|
12182
|
-
this.http = http2;
|
|
12183
|
-
this.logger = logger2;
|
|
12184
|
-
}
|
|
12185
|
-
async getUserById(id) {
|
|
12186
|
-
return this.http.get(`/admin/users/${id}`);
|
|
12187
|
-
}
|
|
12188
|
-
async getStats() {
|
|
12189
|
-
return this.http.get("/admin/stats");
|
|
12190
|
-
}
|
|
12191
|
-
// Backward-compatible alias used in some consumers.
|
|
12192
|
-
async getAdminStats() {
|
|
12193
|
-
return this.getStats();
|
|
12194
|
-
}
|
|
12195
|
-
async getDailyStats(days) {
|
|
12196
|
-
const params = new URLSearchParams();
|
|
12197
|
-
if (days != null) params.append("days", String(days));
|
|
12198
|
-
const queryString = params.toString();
|
|
12199
|
-
const endpoint = queryString ? `/admin/stats/daily?${queryString}` : "/admin/stats/daily";
|
|
12200
|
-
return this.http.get(endpoint);
|
|
12201
|
-
}
|
|
12202
|
-
// Backward-compatible alias used in some consumers.
|
|
12203
|
-
async getAdminDailyStats(days) {
|
|
12204
|
-
return this.getDailyStats(days);
|
|
12205
|
-
}
|
|
12206
|
-
async getEscrowSweepPreview() {
|
|
12207
|
-
return this.http.post("/admin/escrow/sweep-preview");
|
|
12208
|
-
}
|
|
12209
|
-
async getEscrowSweeps(limit = 20) {
|
|
12210
|
-
return this.http.get(
|
|
12211
|
-
`/admin/escrow/sweeps?limit=${limit}`
|
|
12212
|
-
);
|
|
12213
|
-
}
|
|
12214
|
-
async executeEscrowSweep(amountUsdcMinor, idempotencyKey) {
|
|
12215
|
-
return this.http.post("/admin/escrow/sweep", {
|
|
12216
|
-
amountUsdcMinor,
|
|
12217
|
-
idempotencyKey
|
|
12218
|
-
});
|
|
12219
|
-
}
|
|
12220
|
-
async banUser(userId, reason) {
|
|
12221
|
-
return this.http.post(`/admin/users/${userId}/ban`, { reason });
|
|
12222
|
-
}
|
|
12223
|
-
async unbanUser(userId) {
|
|
12224
|
-
return this.http.post(`/admin/users/${userId}/unban`, {});
|
|
12225
|
-
}
|
|
12226
|
-
async getCriticalIncidentSummary(hours = 24) {
|
|
12227
|
-
return this.http.get(
|
|
12228
|
-
`/admin/critical-incidents/summary?hours=${hours}`
|
|
12229
|
-
);
|
|
12230
|
-
}
|
|
12231
|
-
async getCriticalIncidents(input) {
|
|
12232
|
-
const params = new URLSearchParams();
|
|
12233
|
-
if (input.page != null) params.append("page", String(input.page));
|
|
12234
|
-
if (input.limit != null) params.append("limit", String(input.limit));
|
|
12235
|
-
if (input.status) params.append("status", input.status);
|
|
12236
|
-
if (input.severity) params.append("severity", input.severity);
|
|
12237
|
-
if (input.category) params.append("category", input.category);
|
|
12238
|
-
const query = params.toString();
|
|
12239
|
-
return this.http.get(
|
|
12240
|
-
`/admin/critical-incidents${query ? `?${query}` : ""}`
|
|
12241
|
-
);
|
|
12242
|
-
}
|
|
12243
|
-
async resolveCriticalIncident(id, resolutionNote) {
|
|
12244
|
-
return this.http.patch(
|
|
12245
|
-
`/admin/critical-incidents/${id}/resolve`,
|
|
12246
|
-
{ resolutionNote }
|
|
12247
|
-
);
|
|
12248
|
-
}
|
|
12249
|
-
};
|
|
12250
|
-
|
|
12251
|
-
// src/users.ts
|
|
12252
|
-
var Users = class {
|
|
12253
|
-
constructor(http2, logger2) {
|
|
12254
|
-
this.http = http2;
|
|
12255
|
-
this.logger = logger2;
|
|
12256
|
-
}
|
|
12257
|
-
async getUsers(page, limit, username, address) {
|
|
12258
|
-
const params = new URLSearchParams();
|
|
12259
|
-
if (page !== void 0) params.append("page", page.toString());
|
|
12260
|
-
if (limit !== void 0) params.append("limit", limit.toString());
|
|
12261
|
-
if (username !== void 0) params.append("username", username);
|
|
12262
|
-
if (address !== void 0) params.append("address", address);
|
|
12263
|
-
const queryString = params.toString();
|
|
12264
|
-
const endpoint = queryString ? `/users?${queryString}` : "/users";
|
|
12265
|
-
return this.http.get(endpoint);
|
|
12266
|
-
}
|
|
12267
|
-
async getUserById(id) {
|
|
12268
|
-
return this.http.get(`/users/${id}`);
|
|
12269
|
-
}
|
|
12270
|
-
async isUsernameAvailable(username) {
|
|
12271
|
-
const params = new URLSearchParams();
|
|
12272
|
-
params.append("username", username);
|
|
12273
|
-
return this.http.get(
|
|
12274
|
-
`/users/username/availability?${params.toString()}`
|
|
12275
|
-
);
|
|
12276
|
-
}
|
|
12277
|
-
async updateUsername(username) {
|
|
12278
|
-
return this.http.patch("/users/me/username", { username });
|
|
12279
|
-
}
|
|
12280
|
-
async getPublicUserByUsername(username) {
|
|
12281
|
-
return this.http.get(`/users/username/${username}`);
|
|
12282
|
-
}
|
|
12283
|
-
/**
|
|
12284
|
-
* Get a public user profile by ID.
|
|
12285
|
-
* Returns PublicUser with optional spectatorCount.
|
|
12286
|
-
*/
|
|
12287
|
-
async getPublicUserById(userId) {
|
|
12288
|
-
return this.http.get(`/users/${userId}`);
|
|
12289
|
-
}
|
|
12290
|
-
async searchUsers(username, page, limit) {
|
|
12291
|
-
const params = new URLSearchParams();
|
|
12292
|
-
params.append("username", username);
|
|
12293
|
-
if (page !== void 0) params.append("page", page.toString());
|
|
12294
|
-
if (limit !== void 0) params.append("limit", limit.toString());
|
|
12295
|
-
return this.http.get(
|
|
12296
|
-
`/users/search?${params.toString()}`
|
|
12297
|
-
);
|
|
12298
|
-
}
|
|
12299
|
-
async getFriends(userId, page, limit, search) {
|
|
12300
|
-
const params = new URLSearchParams();
|
|
12301
|
-
if (page !== void 0) params.append("page", page.toString());
|
|
12302
|
-
if (limit !== void 0) params.append("limit", limit.toString());
|
|
12303
|
-
if (search !== void 0) params.append("search", search);
|
|
12304
|
-
const queryString = params.toString();
|
|
12305
|
-
const endpoint = queryString ? `/friends/${userId}?${queryString}` : `/friends/${userId}`;
|
|
12306
|
-
return this.http.get(endpoint);
|
|
12307
|
-
}
|
|
12308
|
-
async addFriend(userId) {
|
|
12309
|
-
return this.http.post(`/friends/${userId}`, {});
|
|
12310
|
-
}
|
|
12311
|
-
async removeFriend(userId) {
|
|
12312
|
-
return this.http.delete(`/friends/${userId}`);
|
|
12313
|
-
}
|
|
12314
|
-
async getIncomingFriendRequests() {
|
|
12315
|
-
return this.http.get("/friends/requests/incoming");
|
|
12316
|
-
}
|
|
12317
|
-
async getOutgoingFriendRequests() {
|
|
12318
|
-
return this.http.get("/friends/requests/outgoing");
|
|
12319
|
-
}
|
|
12320
|
-
async acceptFriendRequest(userId) {
|
|
12321
|
-
return this.http.post(
|
|
12322
|
-
`/friends/requests/${userId}/accept`,
|
|
12323
|
-
{}
|
|
12324
|
-
);
|
|
12325
|
-
}
|
|
12326
|
-
async declineFriendRequest(userId) {
|
|
12327
|
-
return this.http.post(
|
|
12328
|
-
`/friends/requests/${userId}/decline`,
|
|
12329
|
-
{}
|
|
12330
|
-
);
|
|
12331
|
-
}
|
|
12332
|
-
async cancelFriendRequest(userId) {
|
|
12333
|
-
return this.http.delete(`/friends/requests/${userId}`);
|
|
12334
|
-
}
|
|
12335
|
-
async updateProfile(data) {
|
|
12336
|
-
return this.http.patch("/users/me/profile", data);
|
|
12337
|
-
}
|
|
12338
|
-
async uploadAvatar(file) {
|
|
12339
|
-
const formData = new FormData();
|
|
12340
|
-
formData.append("file", file);
|
|
12341
|
-
return this.http.upload("/users/me/profile/avatar", formData);
|
|
12342
|
-
}
|
|
12343
|
-
async uploadCoverImage(file) {
|
|
12344
|
-
const formData = new FormData();
|
|
12345
|
-
formData.append("file", file);
|
|
12346
|
-
return this.http.upload("/users/me/profile/cover", formData);
|
|
12347
|
-
}
|
|
12348
|
-
async removeAvatar() {
|
|
12349
|
-
return this.http.delete("/users/me/profile/avatar");
|
|
12350
|
-
}
|
|
12351
|
-
async removeCoverImage() {
|
|
12352
|
-
return this.http.delete("/users/me/profile/cover");
|
|
12353
|
-
}
|
|
12354
|
-
// Admin file management methods
|
|
12355
|
-
async getAllFiles() {
|
|
12356
|
-
return this.http.get("/files");
|
|
12357
|
-
}
|
|
12358
|
-
async deleteFile(fileId) {
|
|
12359
|
-
return this.http.delete(`/files/${fileId}`);
|
|
12360
|
-
}
|
|
12361
|
-
async getGameHistory(userId) {
|
|
12362
|
-
return this.http.get(`/users/${userId}/game-history`);
|
|
12363
|
-
}
|
|
12364
|
-
/**
|
|
12365
|
-
* Get user activity for spectate flow. Returns in_game (with gameId, gameType), in_lobby (with lobbyId, lobbyStatus), or idle.
|
|
12366
|
-
*/
|
|
12367
|
-
async getUserActivity(userId) {
|
|
12368
|
-
return this.http.get(`/users/${userId}/activity`, {
|
|
12369
|
-
cache: "no-store"
|
|
12370
|
-
});
|
|
12371
|
-
}
|
|
12372
|
-
/**
|
|
12373
|
-
* Get the current active game for a user (if they are a player in one).
|
|
12374
|
-
* Returns null if the user is not in an active game.
|
|
12375
|
-
*/
|
|
12376
|
-
async getCurrentGame(userId) {
|
|
12377
|
-
return this.http.get(`/users/${userId}/current-game`, {
|
|
12378
|
-
cache: "no-store"
|
|
12379
|
-
});
|
|
12380
|
-
}
|
|
12381
|
-
async getUserStats(userId) {
|
|
12382
|
-
return this.http.get(`/users/${userId}/stats`);
|
|
12383
|
-
}
|
|
12384
|
-
};
|
|
12385
|
-
|
|
12386
|
-
// src/feature-flags.ts
|
|
12387
|
-
var FeatureFlags = class {
|
|
12388
|
-
constructor(http2, logger2) {
|
|
12389
|
-
this.http = http2;
|
|
12390
|
-
this.logger = logger2;
|
|
12391
|
-
this.flags = [];
|
|
12392
|
-
this.loaded = false;
|
|
12393
|
-
}
|
|
12394
|
-
async getFeatureFlags() {
|
|
12395
|
-
this.flags = await this.http.get("/feature-flags");
|
|
12396
|
-
this.loaded = true;
|
|
12397
|
-
return this.flags;
|
|
12398
|
-
}
|
|
12399
|
-
isEnabledFlag(name) {
|
|
12400
|
-
const flag = this.flags.find((f) => f.name === name);
|
|
12401
|
-
return flag?.enabled ?? false;
|
|
12402
|
-
}
|
|
12403
|
-
isLoaded() {
|
|
12404
|
-
return this.loaded;
|
|
12405
|
-
}
|
|
12406
|
-
async updateFeatureFlag(name, enabled) {
|
|
12407
|
-
const flag = await this.http.patch(`/feature-flags/${name}`, {
|
|
12408
|
-
enabled
|
|
12409
|
-
});
|
|
12410
|
-
const index = this.flags.findIndex((f) => f.name === name);
|
|
12411
|
-
if (index >= 0) {
|
|
12412
|
-
this.flags[index] = flag;
|
|
12413
|
-
} else {
|
|
12414
|
-
this.flags.push(flag);
|
|
12415
|
-
}
|
|
12416
|
-
return flag;
|
|
12417
|
-
}
|
|
12418
|
-
async createFeatureFlag(name, enabled) {
|
|
12419
|
-
const flag = await this.http.post("/feature-flags", {
|
|
12420
|
-
name,
|
|
12421
|
-
enabled
|
|
12422
|
-
});
|
|
12423
|
-
this.flags.push(flag);
|
|
12424
|
-
return flag;
|
|
12425
|
-
}
|
|
12426
|
-
};
|
|
12427
|
-
|
|
12428
|
-
// src/lobbies.ts
|
|
12429
|
-
var Lobbies = class {
|
|
12430
|
-
constructor(http2, logger2) {
|
|
12431
|
-
this.http = http2;
|
|
12432
|
-
this.logger = logger2;
|
|
12433
|
-
}
|
|
12434
|
-
async createLobby(gameType, betAmount) {
|
|
12435
|
-
return this.http.post("/lobbies", { gameType, betAmount });
|
|
12436
|
-
}
|
|
12437
|
-
async getLobby(lobbyId) {
|
|
12438
|
-
return this.http.get(`/lobbies/${lobbyId}`);
|
|
12439
|
-
}
|
|
12440
|
-
async inviteFriend(lobbyId, friendId) {
|
|
12441
|
-
return this.http.post(`/lobbies/${lobbyId}/invite`, {
|
|
12442
|
-
friendId
|
|
12443
|
-
});
|
|
12444
|
-
}
|
|
12445
|
-
async acceptInvite(lobbyId) {
|
|
12446
|
-
return this.http.post(`/lobbies/${lobbyId}/accept-invite`, {});
|
|
12447
|
-
}
|
|
12448
|
-
async joinLobby(lobbyId) {
|
|
12449
|
-
return this.http.post(`/lobbies/${lobbyId}/join`, {});
|
|
12450
|
-
}
|
|
12451
|
-
async removePlayer(lobbyId, userId) {
|
|
12452
|
-
return this.http.delete(
|
|
12453
|
-
`/lobbies/${lobbyId}/players/${userId}`
|
|
12454
|
-
);
|
|
12455
|
-
}
|
|
12456
|
-
async kickPlayer(lobbyId, userId) {
|
|
12457
|
-
return this.removePlayer(lobbyId, userId);
|
|
12458
|
-
}
|
|
12459
|
-
async leaveLobby(lobbyId) {
|
|
12460
|
-
return this.http.delete(`/lobbies/${lobbyId}`);
|
|
12461
|
-
}
|
|
12462
|
-
async joinQueue(lobbyId) {
|
|
12463
|
-
return this.http.post(`/lobbies/${lobbyId}/join-queue`, {});
|
|
12464
|
-
}
|
|
12465
|
-
async cancelQueue(lobbyId) {
|
|
12466
|
-
return this.http.delete(`/lobbies/${lobbyId}/queue`);
|
|
12467
|
-
}
|
|
12468
|
-
async updateBetAmount(lobbyId, betAmount) {
|
|
12469
|
-
return this.http.patch(`/lobbies/${lobbyId}/bet-amount`, {
|
|
12470
|
-
betAmount
|
|
12471
|
-
});
|
|
12472
|
-
}
|
|
12473
|
-
async playSound(lobbyId, sound) {
|
|
12474
|
-
return this.http.post(`/lobbies/${lobbyId}/sound`, {
|
|
12475
|
-
sound
|
|
12476
|
-
});
|
|
12477
|
-
}
|
|
12478
|
-
// Admin methods
|
|
12479
|
-
async getActiveLobbies() {
|
|
12480
|
-
return this.http.get("/lobbies/admin/active");
|
|
12481
|
-
}
|
|
12482
|
-
async getQueueStats() {
|
|
12483
|
-
return this.http.get("/lobbies/admin/queues");
|
|
12484
|
-
}
|
|
12485
|
-
async deleteLobby(lobbyId) {
|
|
12486
|
-
return this.http.delete(`/lobbies/admin/${lobbyId}`);
|
|
12487
|
-
}
|
|
12488
|
-
/**
|
|
12489
|
-
* Play again: Create a new lobby, start deposits, and prepare deposit transaction
|
|
12490
|
-
* Returns the lobby and unsigned transaction that needs to be signed
|
|
12491
|
-
* @param gameType - The game type to play again
|
|
12492
|
-
* @param betAmount - The bet amount (same as previous game)
|
|
12493
|
-
* @param escrow - The escrow service instance (from sdk.escrow)
|
|
12494
|
-
*/
|
|
12495
|
-
async playAgain(gameType, betAmount, escrow) {
|
|
12496
|
-
const lobby = await this.createLobby(gameType, betAmount);
|
|
12497
|
-
await escrow.startDeposits(lobby.id);
|
|
12498
|
-
const prepareResponse = await escrow.prepareDepositTransaction(lobby.id);
|
|
12499
|
-
return {
|
|
12500
|
-
lobby,
|
|
12501
|
-
unsignedTransaction: prepareResponse.transaction
|
|
12502
|
-
};
|
|
12503
|
-
}
|
|
12504
|
-
};
|
|
12505
|
-
|
|
12506
11857
|
// ../../node_modules/@solana/web3.js/lib/index.esm.js
|
|
12507
11858
|
import { Buffer as Buffer2 } from "buffer";
|
|
12508
11859
|
|
|
@@ -21072,626 +20423,1086 @@ var LogsNotificationResult = type({
|
|
|
21072
20423
|
result: notificationResultAndContext(LogsResult),
|
|
21073
20424
|
subscription: number()
|
|
21074
20425
|
});
|
|
21075
|
-
var Keypair = class _Keypair {
|
|
20426
|
+
var Keypair = class _Keypair {
|
|
20427
|
+
/**
|
|
20428
|
+
* Create a new keypair instance.
|
|
20429
|
+
* Generate random keypair if no {@link Ed25519Keypair} is provided.
|
|
20430
|
+
*
|
|
20431
|
+
* @param {Ed25519Keypair} keypair ed25519 keypair
|
|
20432
|
+
*/
|
|
20433
|
+
constructor(keypair) {
|
|
20434
|
+
this._keypair = void 0;
|
|
20435
|
+
this._keypair = keypair ?? generateKeypair();
|
|
20436
|
+
}
|
|
20437
|
+
/**
|
|
20438
|
+
* Generate a new random keypair
|
|
20439
|
+
*
|
|
20440
|
+
* @returns {Keypair} Keypair
|
|
20441
|
+
*/
|
|
20442
|
+
static generate() {
|
|
20443
|
+
return new _Keypair(generateKeypair());
|
|
20444
|
+
}
|
|
20445
|
+
/**
|
|
20446
|
+
* Create a keypair from a raw secret key byte array.
|
|
20447
|
+
*
|
|
20448
|
+
* This method should only be used to recreate a keypair from a previously
|
|
20449
|
+
* generated secret key. Generating keypairs from a random seed should be done
|
|
20450
|
+
* with the {@link Keypair.fromSeed} method.
|
|
20451
|
+
*
|
|
20452
|
+
* @throws error if the provided secret key is invalid and validation is not skipped.
|
|
20453
|
+
*
|
|
20454
|
+
* @param secretKey secret key byte array
|
|
20455
|
+
* @param options skip secret key validation
|
|
20456
|
+
*
|
|
20457
|
+
* @returns {Keypair} Keypair
|
|
20458
|
+
*/
|
|
20459
|
+
static fromSecretKey(secretKey, options) {
|
|
20460
|
+
if (secretKey.byteLength !== 64) {
|
|
20461
|
+
throw new Error("bad secret key size");
|
|
20462
|
+
}
|
|
20463
|
+
const publicKey2 = secretKey.slice(32, 64);
|
|
20464
|
+
if (!options || !options.skipValidation) {
|
|
20465
|
+
const privateScalar = secretKey.slice(0, 32);
|
|
20466
|
+
const computedPublicKey = getPublicKey(privateScalar);
|
|
20467
|
+
for (let ii = 0; ii < 32; ii++) {
|
|
20468
|
+
if (publicKey2[ii] !== computedPublicKey[ii]) {
|
|
20469
|
+
throw new Error("provided secretKey is invalid");
|
|
20470
|
+
}
|
|
20471
|
+
}
|
|
20472
|
+
}
|
|
20473
|
+
return new _Keypair({
|
|
20474
|
+
publicKey: publicKey2,
|
|
20475
|
+
secretKey
|
|
20476
|
+
});
|
|
20477
|
+
}
|
|
20478
|
+
/**
|
|
20479
|
+
* Generate a keypair from a 32 byte seed.
|
|
20480
|
+
*
|
|
20481
|
+
* @param seed seed byte array
|
|
20482
|
+
*
|
|
20483
|
+
* @returns {Keypair} Keypair
|
|
20484
|
+
*/
|
|
20485
|
+
static fromSeed(seed) {
|
|
20486
|
+
const publicKey2 = getPublicKey(seed);
|
|
20487
|
+
const secretKey = new Uint8Array(64);
|
|
20488
|
+
secretKey.set(seed);
|
|
20489
|
+
secretKey.set(publicKey2, 32);
|
|
20490
|
+
return new _Keypair({
|
|
20491
|
+
publicKey: publicKey2,
|
|
20492
|
+
secretKey
|
|
20493
|
+
});
|
|
20494
|
+
}
|
|
20495
|
+
/**
|
|
20496
|
+
* The public key for this keypair
|
|
20497
|
+
*
|
|
20498
|
+
* @returns {PublicKey} PublicKey
|
|
20499
|
+
*/
|
|
20500
|
+
get publicKey() {
|
|
20501
|
+
return new PublicKey(this._keypair.publicKey);
|
|
20502
|
+
}
|
|
20503
|
+
/**
|
|
20504
|
+
* The raw secret key for this keypair
|
|
20505
|
+
* @returns {Uint8Array} Secret key in an array of Uint8 bytes
|
|
20506
|
+
*/
|
|
20507
|
+
get secretKey() {
|
|
20508
|
+
return new Uint8Array(this._keypair.secretKey);
|
|
20509
|
+
}
|
|
20510
|
+
};
|
|
20511
|
+
var LOOKUP_TABLE_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
20512
|
+
CreateLookupTable: {
|
|
20513
|
+
index: 0,
|
|
20514
|
+
layout: BufferLayout.struct([BufferLayout.u32("instruction"), u64("recentSlot"), BufferLayout.u8("bumpSeed")])
|
|
20515
|
+
},
|
|
20516
|
+
FreezeLookupTable: {
|
|
20517
|
+
index: 1,
|
|
20518
|
+
layout: BufferLayout.struct([BufferLayout.u32("instruction")])
|
|
20519
|
+
},
|
|
20520
|
+
ExtendLookupTable: {
|
|
20521
|
+
index: 2,
|
|
20522
|
+
layout: BufferLayout.struct([BufferLayout.u32("instruction"), u64(), BufferLayout.seq(publicKey(), BufferLayout.offset(BufferLayout.u32(), -8), "addresses")])
|
|
20523
|
+
},
|
|
20524
|
+
DeactivateLookupTable: {
|
|
20525
|
+
index: 3,
|
|
20526
|
+
layout: BufferLayout.struct([BufferLayout.u32("instruction")])
|
|
20527
|
+
},
|
|
20528
|
+
CloseLookupTable: {
|
|
20529
|
+
index: 4,
|
|
20530
|
+
layout: BufferLayout.struct([BufferLayout.u32("instruction")])
|
|
20531
|
+
}
|
|
20532
|
+
});
|
|
20533
|
+
var AddressLookupTableProgram = class {
|
|
20534
|
+
/**
|
|
20535
|
+
* @internal
|
|
20536
|
+
*/
|
|
20537
|
+
constructor() {
|
|
20538
|
+
}
|
|
20539
|
+
static createLookupTable(params) {
|
|
20540
|
+
const [lookupTableAddress, bumpSeed] = PublicKey.findProgramAddressSync([params.authority.toBuffer(), getU64Encoder().encode(params.recentSlot)], this.programId);
|
|
20541
|
+
const type2 = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CreateLookupTable;
|
|
20542
|
+
const data = encodeData(type2, {
|
|
20543
|
+
recentSlot: BigInt(params.recentSlot),
|
|
20544
|
+
bumpSeed
|
|
20545
|
+
});
|
|
20546
|
+
const keys = [{
|
|
20547
|
+
pubkey: lookupTableAddress,
|
|
20548
|
+
isSigner: false,
|
|
20549
|
+
isWritable: true
|
|
20550
|
+
}, {
|
|
20551
|
+
pubkey: params.authority,
|
|
20552
|
+
isSigner: true,
|
|
20553
|
+
isWritable: false
|
|
20554
|
+
}, {
|
|
20555
|
+
pubkey: params.payer,
|
|
20556
|
+
isSigner: true,
|
|
20557
|
+
isWritable: true
|
|
20558
|
+
}, {
|
|
20559
|
+
pubkey: SystemProgram.programId,
|
|
20560
|
+
isSigner: false,
|
|
20561
|
+
isWritable: false
|
|
20562
|
+
}];
|
|
20563
|
+
return [new TransactionInstruction({
|
|
20564
|
+
programId: this.programId,
|
|
20565
|
+
keys,
|
|
20566
|
+
data
|
|
20567
|
+
}), lookupTableAddress];
|
|
20568
|
+
}
|
|
20569
|
+
static freezeLookupTable(params) {
|
|
20570
|
+
const type2 = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.FreezeLookupTable;
|
|
20571
|
+
const data = encodeData(type2);
|
|
20572
|
+
const keys = [{
|
|
20573
|
+
pubkey: params.lookupTable,
|
|
20574
|
+
isSigner: false,
|
|
20575
|
+
isWritable: true
|
|
20576
|
+
}, {
|
|
20577
|
+
pubkey: params.authority,
|
|
20578
|
+
isSigner: true,
|
|
20579
|
+
isWritable: false
|
|
20580
|
+
}];
|
|
20581
|
+
return new TransactionInstruction({
|
|
20582
|
+
programId: this.programId,
|
|
20583
|
+
keys,
|
|
20584
|
+
data
|
|
20585
|
+
});
|
|
20586
|
+
}
|
|
20587
|
+
static extendLookupTable(params) {
|
|
20588
|
+
const type2 = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.ExtendLookupTable;
|
|
20589
|
+
const data = encodeData(type2, {
|
|
20590
|
+
addresses: params.addresses.map((addr) => addr.toBytes())
|
|
20591
|
+
});
|
|
20592
|
+
const keys = [{
|
|
20593
|
+
pubkey: params.lookupTable,
|
|
20594
|
+
isSigner: false,
|
|
20595
|
+
isWritable: true
|
|
20596
|
+
}, {
|
|
20597
|
+
pubkey: params.authority,
|
|
20598
|
+
isSigner: true,
|
|
20599
|
+
isWritable: false
|
|
20600
|
+
}];
|
|
20601
|
+
if (params.payer) {
|
|
20602
|
+
keys.push({
|
|
20603
|
+
pubkey: params.payer,
|
|
20604
|
+
isSigner: true,
|
|
20605
|
+
isWritable: true
|
|
20606
|
+
}, {
|
|
20607
|
+
pubkey: SystemProgram.programId,
|
|
20608
|
+
isSigner: false,
|
|
20609
|
+
isWritable: false
|
|
20610
|
+
});
|
|
20611
|
+
}
|
|
20612
|
+
return new TransactionInstruction({
|
|
20613
|
+
programId: this.programId,
|
|
20614
|
+
keys,
|
|
20615
|
+
data
|
|
20616
|
+
});
|
|
20617
|
+
}
|
|
20618
|
+
static deactivateLookupTable(params) {
|
|
20619
|
+
const type2 = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.DeactivateLookupTable;
|
|
20620
|
+
const data = encodeData(type2);
|
|
20621
|
+
const keys = [{
|
|
20622
|
+
pubkey: params.lookupTable,
|
|
20623
|
+
isSigner: false,
|
|
20624
|
+
isWritable: true
|
|
20625
|
+
}, {
|
|
20626
|
+
pubkey: params.authority,
|
|
20627
|
+
isSigner: true,
|
|
20628
|
+
isWritable: false
|
|
20629
|
+
}];
|
|
20630
|
+
return new TransactionInstruction({
|
|
20631
|
+
programId: this.programId,
|
|
20632
|
+
keys,
|
|
20633
|
+
data
|
|
20634
|
+
});
|
|
20635
|
+
}
|
|
20636
|
+
static closeLookupTable(params) {
|
|
20637
|
+
const type2 = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CloseLookupTable;
|
|
20638
|
+
const data = encodeData(type2);
|
|
20639
|
+
const keys = [{
|
|
20640
|
+
pubkey: params.lookupTable,
|
|
20641
|
+
isSigner: false,
|
|
20642
|
+
isWritable: true
|
|
20643
|
+
}, {
|
|
20644
|
+
pubkey: params.authority,
|
|
20645
|
+
isSigner: true,
|
|
20646
|
+
isWritable: false
|
|
20647
|
+
}, {
|
|
20648
|
+
pubkey: params.recipient,
|
|
20649
|
+
isSigner: false,
|
|
20650
|
+
isWritable: true
|
|
20651
|
+
}];
|
|
20652
|
+
return new TransactionInstruction({
|
|
20653
|
+
programId: this.programId,
|
|
20654
|
+
keys,
|
|
20655
|
+
data
|
|
20656
|
+
});
|
|
20657
|
+
}
|
|
20658
|
+
};
|
|
20659
|
+
AddressLookupTableProgram.programId = new PublicKey("AddressLookupTab1e1111111111111111111111111");
|
|
20660
|
+
var COMPUTE_BUDGET_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
20661
|
+
RequestUnits: {
|
|
20662
|
+
index: 0,
|
|
20663
|
+
layout: BufferLayout.struct([BufferLayout.u8("instruction"), BufferLayout.u32("units"), BufferLayout.u32("additionalFee")])
|
|
20664
|
+
},
|
|
20665
|
+
RequestHeapFrame: {
|
|
20666
|
+
index: 1,
|
|
20667
|
+
layout: BufferLayout.struct([BufferLayout.u8("instruction"), BufferLayout.u32("bytes")])
|
|
20668
|
+
},
|
|
20669
|
+
SetComputeUnitLimit: {
|
|
20670
|
+
index: 2,
|
|
20671
|
+
layout: BufferLayout.struct([BufferLayout.u8("instruction"), BufferLayout.u32("units")])
|
|
20672
|
+
},
|
|
20673
|
+
SetComputeUnitPrice: {
|
|
20674
|
+
index: 3,
|
|
20675
|
+
layout: BufferLayout.struct([BufferLayout.u8("instruction"), u64("microLamports")])
|
|
20676
|
+
}
|
|
20677
|
+
});
|
|
20678
|
+
var ComputeBudgetProgram = class {
|
|
21076
20679
|
/**
|
|
21077
|
-
*
|
|
21078
|
-
* Generate random keypair if no {@link Ed25519Keypair} is provided.
|
|
21079
|
-
*
|
|
21080
|
-
* @param {Ed25519Keypair} keypair ed25519 keypair
|
|
20680
|
+
* @internal
|
|
21081
20681
|
*/
|
|
21082
|
-
constructor(
|
|
21083
|
-
this._keypair = void 0;
|
|
21084
|
-
this._keypair = keypair ?? generateKeypair();
|
|
20682
|
+
constructor() {
|
|
21085
20683
|
}
|
|
21086
20684
|
/**
|
|
21087
|
-
*
|
|
21088
|
-
*
|
|
21089
|
-
* @returns {Keypair} Keypair
|
|
20685
|
+
* Public key that identifies the Compute Budget program
|
|
21090
20686
|
*/
|
|
21091
|
-
|
|
21092
|
-
|
|
20687
|
+
/**
|
|
20688
|
+
* @deprecated Instead, call {@link setComputeUnitLimit} and/or {@link setComputeUnitPrice}
|
|
20689
|
+
*/
|
|
20690
|
+
static requestUnits(params) {
|
|
20691
|
+
const type2 = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.RequestUnits;
|
|
20692
|
+
const data = encodeData(type2, params);
|
|
20693
|
+
return new TransactionInstruction({
|
|
20694
|
+
keys: [],
|
|
20695
|
+
programId: this.programId,
|
|
20696
|
+
data
|
|
20697
|
+
});
|
|
20698
|
+
}
|
|
20699
|
+
static requestHeapFrame(params) {
|
|
20700
|
+
const type2 = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.RequestHeapFrame;
|
|
20701
|
+
const data = encodeData(type2, params);
|
|
20702
|
+
return new TransactionInstruction({
|
|
20703
|
+
keys: [],
|
|
20704
|
+
programId: this.programId,
|
|
20705
|
+
data
|
|
20706
|
+
});
|
|
20707
|
+
}
|
|
20708
|
+
static setComputeUnitLimit(params) {
|
|
20709
|
+
const type2 = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitLimit;
|
|
20710
|
+
const data = encodeData(type2, params);
|
|
20711
|
+
return new TransactionInstruction({
|
|
20712
|
+
keys: [],
|
|
20713
|
+
programId: this.programId,
|
|
20714
|
+
data
|
|
20715
|
+
});
|
|
20716
|
+
}
|
|
20717
|
+
static setComputeUnitPrice(params) {
|
|
20718
|
+
const type2 = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitPrice;
|
|
20719
|
+
const data = encodeData(type2, {
|
|
20720
|
+
microLamports: BigInt(params.microLamports)
|
|
20721
|
+
});
|
|
20722
|
+
return new TransactionInstruction({
|
|
20723
|
+
keys: [],
|
|
20724
|
+
programId: this.programId,
|
|
20725
|
+
data
|
|
20726
|
+
});
|
|
21093
20727
|
}
|
|
20728
|
+
};
|
|
20729
|
+
ComputeBudgetProgram.programId = new PublicKey("ComputeBudget111111111111111111111111111111");
|
|
20730
|
+
var PRIVATE_KEY_BYTES$1 = 64;
|
|
20731
|
+
var PUBLIC_KEY_BYTES$1 = 32;
|
|
20732
|
+
var SIGNATURE_BYTES = 64;
|
|
20733
|
+
var ED25519_INSTRUCTION_LAYOUT = BufferLayout.struct([BufferLayout.u8("numSignatures"), BufferLayout.u8("padding"), BufferLayout.u16("signatureOffset"), BufferLayout.u16("signatureInstructionIndex"), BufferLayout.u16("publicKeyOffset"), BufferLayout.u16("publicKeyInstructionIndex"), BufferLayout.u16("messageDataOffset"), BufferLayout.u16("messageDataSize"), BufferLayout.u16("messageInstructionIndex")]);
|
|
20734
|
+
var Ed25519Program = class _Ed25519Program {
|
|
21094
20735
|
/**
|
|
21095
|
-
*
|
|
21096
|
-
*
|
|
21097
|
-
* This method should only be used to recreate a keypair from a previously
|
|
21098
|
-
* generated secret key. Generating keypairs from a random seed should be done
|
|
21099
|
-
* with the {@link Keypair.fromSeed} method.
|
|
21100
|
-
*
|
|
21101
|
-
* @throws error if the provided secret key is invalid and validation is not skipped.
|
|
21102
|
-
*
|
|
21103
|
-
* @param secretKey secret key byte array
|
|
21104
|
-
* @param options skip secret key validation
|
|
21105
|
-
*
|
|
21106
|
-
* @returns {Keypair} Keypair
|
|
20736
|
+
* @internal
|
|
21107
20737
|
*/
|
|
21108
|
-
|
|
21109
|
-
|
|
21110
|
-
|
|
20738
|
+
constructor() {
|
|
20739
|
+
}
|
|
20740
|
+
/**
|
|
20741
|
+
* Public key that identifies the ed25519 program
|
|
20742
|
+
*/
|
|
20743
|
+
/**
|
|
20744
|
+
* Create an ed25519 instruction with a public key and signature. The
|
|
20745
|
+
* public key must be a buffer that is 32 bytes long, and the signature
|
|
20746
|
+
* must be a buffer of 64 bytes.
|
|
20747
|
+
*/
|
|
20748
|
+
static createInstructionWithPublicKey(params) {
|
|
20749
|
+
const {
|
|
20750
|
+
publicKey: publicKey2,
|
|
20751
|
+
message,
|
|
20752
|
+
signature,
|
|
20753
|
+
instructionIndex
|
|
20754
|
+
} = params;
|
|
20755
|
+
assert2(publicKey2.length === PUBLIC_KEY_BYTES$1, `Public Key must be ${PUBLIC_KEY_BYTES$1} bytes but received ${publicKey2.length} bytes`);
|
|
20756
|
+
assert2(signature.length === SIGNATURE_BYTES, `Signature must be ${SIGNATURE_BYTES} bytes but received ${signature.length} bytes`);
|
|
20757
|
+
const publicKeyOffset = ED25519_INSTRUCTION_LAYOUT.span;
|
|
20758
|
+
const signatureOffset = publicKeyOffset + publicKey2.length;
|
|
20759
|
+
const messageDataOffset = signatureOffset + signature.length;
|
|
20760
|
+
const numSignatures = 1;
|
|
20761
|
+
const instructionData = Buffer2.alloc(messageDataOffset + message.length);
|
|
20762
|
+
const index = instructionIndex == null ? 65535 : instructionIndex;
|
|
20763
|
+
ED25519_INSTRUCTION_LAYOUT.encode({
|
|
20764
|
+
numSignatures,
|
|
20765
|
+
padding: 0,
|
|
20766
|
+
signatureOffset,
|
|
20767
|
+
signatureInstructionIndex: index,
|
|
20768
|
+
publicKeyOffset,
|
|
20769
|
+
publicKeyInstructionIndex: index,
|
|
20770
|
+
messageDataOffset,
|
|
20771
|
+
messageDataSize: message.length,
|
|
20772
|
+
messageInstructionIndex: index
|
|
20773
|
+
}, instructionData);
|
|
20774
|
+
instructionData.fill(publicKey2, publicKeyOffset);
|
|
20775
|
+
instructionData.fill(signature, signatureOffset);
|
|
20776
|
+
instructionData.fill(message, messageDataOffset);
|
|
20777
|
+
return new TransactionInstruction({
|
|
20778
|
+
keys: [],
|
|
20779
|
+
programId: _Ed25519Program.programId,
|
|
20780
|
+
data: instructionData
|
|
20781
|
+
});
|
|
20782
|
+
}
|
|
20783
|
+
/**
|
|
20784
|
+
* Create an ed25519 instruction with a private key. The private key
|
|
20785
|
+
* must be a buffer that is 64 bytes long.
|
|
20786
|
+
*/
|
|
20787
|
+
static createInstructionWithPrivateKey(params) {
|
|
20788
|
+
const {
|
|
20789
|
+
privateKey,
|
|
20790
|
+
message,
|
|
20791
|
+
instructionIndex
|
|
20792
|
+
} = params;
|
|
20793
|
+
assert2(privateKey.length === PRIVATE_KEY_BYTES$1, `Private key must be ${PRIVATE_KEY_BYTES$1} bytes but received ${privateKey.length} bytes`);
|
|
20794
|
+
try {
|
|
20795
|
+
const keypair = Keypair.fromSecretKey(privateKey);
|
|
20796
|
+
const publicKey2 = keypair.publicKey.toBytes();
|
|
20797
|
+
const signature = sign(message, keypair.secretKey);
|
|
20798
|
+
return this.createInstructionWithPublicKey({
|
|
20799
|
+
publicKey: publicKey2,
|
|
20800
|
+
message,
|
|
20801
|
+
signature,
|
|
20802
|
+
instructionIndex
|
|
20803
|
+
});
|
|
20804
|
+
} catch (error) {
|
|
20805
|
+
throw new Error(`Error creating instruction; ${error}`);
|
|
21111
20806
|
}
|
|
21112
|
-
|
|
21113
|
-
|
|
21114
|
-
|
|
21115
|
-
|
|
21116
|
-
|
|
21117
|
-
|
|
21118
|
-
|
|
21119
|
-
|
|
21120
|
-
|
|
20807
|
+
}
|
|
20808
|
+
};
|
|
20809
|
+
Ed25519Program.programId = new PublicKey("Ed25519SigVerify111111111111111111111111111");
|
|
20810
|
+
var ecdsaSign = (msgHash, privKey) => {
|
|
20811
|
+
const signature = secp256k1.sign(msgHash, privKey);
|
|
20812
|
+
return [signature.toCompactRawBytes(), signature.recovery];
|
|
20813
|
+
};
|
|
20814
|
+
secp256k1.utils.isValidPrivateKey;
|
|
20815
|
+
var publicKeyCreate = secp256k1.getPublicKey;
|
|
20816
|
+
var PRIVATE_KEY_BYTES = 32;
|
|
20817
|
+
var ETHEREUM_ADDRESS_BYTES = 20;
|
|
20818
|
+
var PUBLIC_KEY_BYTES = 64;
|
|
20819
|
+
var SIGNATURE_OFFSETS_SERIALIZED_SIZE = 11;
|
|
20820
|
+
var SECP256K1_INSTRUCTION_LAYOUT = BufferLayout.struct([BufferLayout.u8("numSignatures"), BufferLayout.u16("signatureOffset"), BufferLayout.u8("signatureInstructionIndex"), BufferLayout.u16("ethAddressOffset"), BufferLayout.u8("ethAddressInstructionIndex"), BufferLayout.u16("messageDataOffset"), BufferLayout.u16("messageDataSize"), BufferLayout.u8("messageInstructionIndex"), BufferLayout.blob(20, "ethAddress"), BufferLayout.blob(64, "signature"), BufferLayout.u8("recoveryId")]);
|
|
20821
|
+
var Secp256k1Program = class _Secp256k1Program {
|
|
20822
|
+
/**
|
|
20823
|
+
* @internal
|
|
20824
|
+
*/
|
|
20825
|
+
constructor() {
|
|
20826
|
+
}
|
|
20827
|
+
/**
|
|
20828
|
+
* Public key that identifies the secp256k1 program
|
|
20829
|
+
*/
|
|
20830
|
+
/**
|
|
20831
|
+
* Construct an Ethereum address from a secp256k1 public key buffer.
|
|
20832
|
+
* @param {Buffer} publicKey a 64 byte secp256k1 public key buffer
|
|
20833
|
+
*/
|
|
20834
|
+
static publicKeyToEthAddress(publicKey2) {
|
|
20835
|
+
assert2(publicKey2.length === PUBLIC_KEY_BYTES, `Public key must be ${PUBLIC_KEY_BYTES} bytes but received ${publicKey2.length} bytes`);
|
|
20836
|
+
try {
|
|
20837
|
+
return Buffer2.from(keccak_256(toBuffer(publicKey2))).slice(-ETHEREUM_ADDRESS_BYTES);
|
|
20838
|
+
} catch (error) {
|
|
20839
|
+
throw new Error(`Error constructing Ethereum address: ${error}`);
|
|
21121
20840
|
}
|
|
21122
|
-
|
|
20841
|
+
}
|
|
20842
|
+
/**
|
|
20843
|
+
* Create an secp256k1 instruction with a public key. The public key
|
|
20844
|
+
* must be a buffer that is 64 bytes long.
|
|
20845
|
+
*/
|
|
20846
|
+
static createInstructionWithPublicKey(params) {
|
|
20847
|
+
const {
|
|
21123
20848
|
publicKey: publicKey2,
|
|
21124
|
-
|
|
20849
|
+
message,
|
|
20850
|
+
signature,
|
|
20851
|
+
recoveryId,
|
|
20852
|
+
instructionIndex
|
|
20853
|
+
} = params;
|
|
20854
|
+
return _Secp256k1Program.createInstructionWithEthAddress({
|
|
20855
|
+
ethAddress: _Secp256k1Program.publicKeyToEthAddress(publicKey2),
|
|
20856
|
+
message,
|
|
20857
|
+
signature,
|
|
20858
|
+
recoveryId,
|
|
20859
|
+
instructionIndex
|
|
20860
|
+
});
|
|
20861
|
+
}
|
|
20862
|
+
/**
|
|
20863
|
+
* Create an secp256k1 instruction with an Ethereum address. The address
|
|
20864
|
+
* must be a hex string or a buffer that is 20 bytes long.
|
|
20865
|
+
*/
|
|
20866
|
+
static createInstructionWithEthAddress(params) {
|
|
20867
|
+
const {
|
|
20868
|
+
ethAddress: rawAddress,
|
|
20869
|
+
message,
|
|
20870
|
+
signature,
|
|
20871
|
+
recoveryId,
|
|
20872
|
+
instructionIndex = 0
|
|
20873
|
+
} = params;
|
|
20874
|
+
let ethAddress;
|
|
20875
|
+
if (typeof rawAddress === "string") {
|
|
20876
|
+
if (rawAddress.startsWith("0x")) {
|
|
20877
|
+
ethAddress = Buffer2.from(rawAddress.substr(2), "hex");
|
|
20878
|
+
} else {
|
|
20879
|
+
ethAddress = Buffer2.from(rawAddress, "hex");
|
|
20880
|
+
}
|
|
20881
|
+
} else {
|
|
20882
|
+
ethAddress = rawAddress;
|
|
20883
|
+
}
|
|
20884
|
+
assert2(ethAddress.length === ETHEREUM_ADDRESS_BYTES, `Address must be ${ETHEREUM_ADDRESS_BYTES} bytes but received ${ethAddress.length} bytes`);
|
|
20885
|
+
const dataStart = 1 + SIGNATURE_OFFSETS_SERIALIZED_SIZE;
|
|
20886
|
+
const ethAddressOffset = dataStart;
|
|
20887
|
+
const signatureOffset = dataStart + ethAddress.length;
|
|
20888
|
+
const messageDataOffset = signatureOffset + signature.length + 1;
|
|
20889
|
+
const numSignatures = 1;
|
|
20890
|
+
const instructionData = Buffer2.alloc(SECP256K1_INSTRUCTION_LAYOUT.span + message.length);
|
|
20891
|
+
SECP256K1_INSTRUCTION_LAYOUT.encode({
|
|
20892
|
+
numSignatures,
|
|
20893
|
+
signatureOffset,
|
|
20894
|
+
signatureInstructionIndex: instructionIndex,
|
|
20895
|
+
ethAddressOffset,
|
|
20896
|
+
ethAddressInstructionIndex: instructionIndex,
|
|
20897
|
+
messageDataOffset,
|
|
20898
|
+
messageDataSize: message.length,
|
|
20899
|
+
messageInstructionIndex: instructionIndex,
|
|
20900
|
+
signature: toBuffer(signature),
|
|
20901
|
+
ethAddress: toBuffer(ethAddress),
|
|
20902
|
+
recoveryId
|
|
20903
|
+
}, instructionData);
|
|
20904
|
+
instructionData.fill(toBuffer(message), SECP256K1_INSTRUCTION_LAYOUT.span);
|
|
20905
|
+
return new TransactionInstruction({
|
|
20906
|
+
keys: [],
|
|
20907
|
+
programId: _Secp256k1Program.programId,
|
|
20908
|
+
data: instructionData
|
|
21125
20909
|
});
|
|
21126
20910
|
}
|
|
21127
20911
|
/**
|
|
21128
|
-
*
|
|
21129
|
-
*
|
|
21130
|
-
* @param seed seed byte array
|
|
21131
|
-
*
|
|
21132
|
-
* @returns {Keypair} Keypair
|
|
20912
|
+
* Create an secp256k1 instruction with a private key. The private key
|
|
20913
|
+
* must be a buffer that is 32 bytes long.
|
|
21133
20914
|
*/
|
|
21134
|
-
static
|
|
21135
|
-
const
|
|
21136
|
-
|
|
21137
|
-
|
|
21138
|
-
|
|
21139
|
-
|
|
21140
|
-
|
|
21141
|
-
|
|
21142
|
-
|
|
20915
|
+
static createInstructionWithPrivateKey(params) {
|
|
20916
|
+
const {
|
|
20917
|
+
privateKey: pkey,
|
|
20918
|
+
message,
|
|
20919
|
+
instructionIndex
|
|
20920
|
+
} = params;
|
|
20921
|
+
assert2(pkey.length === PRIVATE_KEY_BYTES, `Private key must be ${PRIVATE_KEY_BYTES} bytes but received ${pkey.length} bytes`);
|
|
20922
|
+
try {
|
|
20923
|
+
const privateKey = toBuffer(pkey);
|
|
20924
|
+
const publicKey2 = publicKeyCreate(
|
|
20925
|
+
privateKey,
|
|
20926
|
+
false
|
|
20927
|
+
/* isCompressed */
|
|
20928
|
+
).slice(1);
|
|
20929
|
+
const messageHash = Buffer2.from(keccak_256(toBuffer(message)));
|
|
20930
|
+
const [signature, recoveryId] = ecdsaSign(messageHash, privateKey);
|
|
20931
|
+
return this.createInstructionWithPublicKey({
|
|
20932
|
+
publicKey: publicKey2,
|
|
20933
|
+
message,
|
|
20934
|
+
signature,
|
|
20935
|
+
recoveryId,
|
|
20936
|
+
instructionIndex
|
|
20937
|
+
});
|
|
20938
|
+
} catch (error) {
|
|
20939
|
+
throw new Error(`Error creating instruction; ${error}`);
|
|
20940
|
+
}
|
|
21143
20941
|
}
|
|
20942
|
+
};
|
|
20943
|
+
Secp256k1Program.programId = new PublicKey("KeccakSecp256k11111111111111111111111111111");
|
|
20944
|
+
var _Lockup;
|
|
20945
|
+
var STAKE_CONFIG_ID = new PublicKey("StakeConfig11111111111111111111111111111111");
|
|
20946
|
+
var Lockup = class {
|
|
21144
20947
|
/**
|
|
21145
|
-
*
|
|
21146
|
-
*
|
|
21147
|
-
* @returns {PublicKey} PublicKey
|
|
20948
|
+
* Create a new Lockup object
|
|
21148
20949
|
*/
|
|
21149
|
-
|
|
21150
|
-
|
|
20950
|
+
constructor(unixTimestamp, epoch, custodian) {
|
|
20951
|
+
this.unixTimestamp = void 0;
|
|
20952
|
+
this.epoch = void 0;
|
|
20953
|
+
this.custodian = void 0;
|
|
20954
|
+
this.unixTimestamp = unixTimestamp;
|
|
20955
|
+
this.epoch = epoch;
|
|
20956
|
+
this.custodian = custodian;
|
|
21151
20957
|
}
|
|
21152
20958
|
/**
|
|
21153
|
-
*
|
|
21154
|
-
* @returns {Uint8Array} Secret key in an array of Uint8 bytes
|
|
20959
|
+
* Default, inactive Lockup value
|
|
21155
20960
|
*/
|
|
21156
|
-
get secretKey() {
|
|
21157
|
-
return new Uint8Array(this._keypair.secretKey);
|
|
21158
|
-
}
|
|
21159
20961
|
};
|
|
21160
|
-
|
|
21161
|
-
|
|
20962
|
+
_Lockup = Lockup;
|
|
20963
|
+
Lockup.default = new _Lockup(0, 0, PublicKey.default);
|
|
20964
|
+
var STAKE_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
20965
|
+
Initialize: {
|
|
21162
20966
|
index: 0,
|
|
21163
|
-
layout: BufferLayout.struct([BufferLayout.u32("instruction"),
|
|
20967
|
+
layout: BufferLayout.struct([BufferLayout.u32("instruction"), authorized(), lockup()])
|
|
21164
20968
|
},
|
|
21165
|
-
|
|
20969
|
+
Authorize: {
|
|
21166
20970
|
index: 1,
|
|
21167
|
-
layout: BufferLayout.struct([BufferLayout.u32("instruction")])
|
|
20971
|
+
layout: BufferLayout.struct([BufferLayout.u32("instruction"), publicKey("newAuthorized"), BufferLayout.u32("stakeAuthorizationType")])
|
|
21168
20972
|
},
|
|
21169
|
-
|
|
20973
|
+
Delegate: {
|
|
21170
20974
|
index: 2,
|
|
21171
|
-
layout: BufferLayout.struct([BufferLayout.u32("instruction")
|
|
20975
|
+
layout: BufferLayout.struct([BufferLayout.u32("instruction")])
|
|
21172
20976
|
},
|
|
21173
|
-
|
|
20977
|
+
Split: {
|
|
21174
20978
|
index: 3,
|
|
21175
|
-
layout: BufferLayout.struct([BufferLayout.u32("instruction")])
|
|
20979
|
+
layout: BufferLayout.struct([BufferLayout.u32("instruction"), BufferLayout.ns64("lamports")])
|
|
21176
20980
|
},
|
|
21177
|
-
|
|
20981
|
+
Withdraw: {
|
|
21178
20982
|
index: 4,
|
|
21179
|
-
layout: BufferLayout.struct([BufferLayout.u32("instruction")])
|
|
21180
|
-
}
|
|
21181
|
-
});
|
|
21182
|
-
var AddressLookupTableProgram = class {
|
|
21183
|
-
/**
|
|
21184
|
-
* @internal
|
|
21185
|
-
*/
|
|
21186
|
-
constructor() {
|
|
21187
|
-
}
|
|
21188
|
-
static createLookupTable(params) {
|
|
21189
|
-
const [lookupTableAddress, bumpSeed] = PublicKey.findProgramAddressSync([params.authority.toBuffer(), getU64Encoder().encode(params.recentSlot)], this.programId);
|
|
21190
|
-
const type2 = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CreateLookupTable;
|
|
21191
|
-
const data = encodeData(type2, {
|
|
21192
|
-
recentSlot: BigInt(params.recentSlot),
|
|
21193
|
-
bumpSeed
|
|
21194
|
-
});
|
|
21195
|
-
const keys = [{
|
|
21196
|
-
pubkey: lookupTableAddress,
|
|
21197
|
-
isSigner: false,
|
|
21198
|
-
isWritable: true
|
|
21199
|
-
}, {
|
|
21200
|
-
pubkey: params.authority,
|
|
21201
|
-
isSigner: true,
|
|
21202
|
-
isWritable: false
|
|
21203
|
-
}, {
|
|
21204
|
-
pubkey: params.payer,
|
|
21205
|
-
isSigner: true,
|
|
21206
|
-
isWritable: true
|
|
21207
|
-
}, {
|
|
21208
|
-
pubkey: SystemProgram.programId,
|
|
21209
|
-
isSigner: false,
|
|
21210
|
-
isWritable: false
|
|
21211
|
-
}];
|
|
21212
|
-
return [new TransactionInstruction({
|
|
21213
|
-
programId: this.programId,
|
|
21214
|
-
keys,
|
|
21215
|
-
data
|
|
21216
|
-
}), lookupTableAddress];
|
|
21217
|
-
}
|
|
21218
|
-
static freezeLookupTable(params) {
|
|
21219
|
-
const type2 = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.FreezeLookupTable;
|
|
21220
|
-
const data = encodeData(type2);
|
|
21221
|
-
const keys = [{
|
|
21222
|
-
pubkey: params.lookupTable,
|
|
21223
|
-
isSigner: false,
|
|
21224
|
-
isWritable: true
|
|
21225
|
-
}, {
|
|
21226
|
-
pubkey: params.authority,
|
|
21227
|
-
isSigner: true,
|
|
21228
|
-
isWritable: false
|
|
21229
|
-
}];
|
|
21230
|
-
return new TransactionInstruction({
|
|
21231
|
-
programId: this.programId,
|
|
21232
|
-
keys,
|
|
21233
|
-
data
|
|
21234
|
-
});
|
|
21235
|
-
}
|
|
21236
|
-
static extendLookupTable(params) {
|
|
21237
|
-
const type2 = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.ExtendLookupTable;
|
|
21238
|
-
const data = encodeData(type2, {
|
|
21239
|
-
addresses: params.addresses.map((addr) => addr.toBytes())
|
|
21240
|
-
});
|
|
21241
|
-
const keys = [{
|
|
21242
|
-
pubkey: params.lookupTable,
|
|
21243
|
-
isSigner: false,
|
|
21244
|
-
isWritable: true
|
|
21245
|
-
}, {
|
|
21246
|
-
pubkey: params.authority,
|
|
21247
|
-
isSigner: true,
|
|
21248
|
-
isWritable: false
|
|
21249
|
-
}];
|
|
21250
|
-
if (params.payer) {
|
|
21251
|
-
keys.push({
|
|
21252
|
-
pubkey: params.payer,
|
|
21253
|
-
isSigner: true,
|
|
21254
|
-
isWritable: true
|
|
21255
|
-
}, {
|
|
21256
|
-
pubkey: SystemProgram.programId,
|
|
21257
|
-
isSigner: false,
|
|
21258
|
-
isWritable: false
|
|
21259
|
-
});
|
|
21260
|
-
}
|
|
21261
|
-
return new TransactionInstruction({
|
|
21262
|
-
programId: this.programId,
|
|
21263
|
-
keys,
|
|
21264
|
-
data
|
|
21265
|
-
});
|
|
21266
|
-
}
|
|
21267
|
-
static deactivateLookupTable(params) {
|
|
21268
|
-
const type2 = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.DeactivateLookupTable;
|
|
21269
|
-
const data = encodeData(type2);
|
|
21270
|
-
const keys = [{
|
|
21271
|
-
pubkey: params.lookupTable,
|
|
21272
|
-
isSigner: false,
|
|
21273
|
-
isWritable: true
|
|
21274
|
-
}, {
|
|
21275
|
-
pubkey: params.authority,
|
|
21276
|
-
isSigner: true,
|
|
21277
|
-
isWritable: false
|
|
21278
|
-
}];
|
|
21279
|
-
return new TransactionInstruction({
|
|
21280
|
-
programId: this.programId,
|
|
21281
|
-
keys,
|
|
21282
|
-
data
|
|
21283
|
-
});
|
|
21284
|
-
}
|
|
21285
|
-
static closeLookupTable(params) {
|
|
21286
|
-
const type2 = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CloseLookupTable;
|
|
21287
|
-
const data = encodeData(type2);
|
|
21288
|
-
const keys = [{
|
|
21289
|
-
pubkey: params.lookupTable,
|
|
21290
|
-
isSigner: false,
|
|
21291
|
-
isWritable: true
|
|
21292
|
-
}, {
|
|
21293
|
-
pubkey: params.authority,
|
|
21294
|
-
isSigner: true,
|
|
21295
|
-
isWritable: false
|
|
21296
|
-
}, {
|
|
21297
|
-
pubkey: params.recipient,
|
|
21298
|
-
isSigner: false,
|
|
21299
|
-
isWritable: true
|
|
21300
|
-
}];
|
|
21301
|
-
return new TransactionInstruction({
|
|
21302
|
-
programId: this.programId,
|
|
21303
|
-
keys,
|
|
21304
|
-
data
|
|
21305
|
-
});
|
|
21306
|
-
}
|
|
21307
|
-
};
|
|
21308
|
-
AddressLookupTableProgram.programId = new PublicKey("AddressLookupTab1e1111111111111111111111111");
|
|
21309
|
-
var COMPUTE_BUDGET_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
21310
|
-
RequestUnits: {
|
|
21311
|
-
index: 0,
|
|
21312
|
-
layout: BufferLayout.struct([BufferLayout.u8("instruction"), BufferLayout.u32("units"), BufferLayout.u32("additionalFee")])
|
|
20983
|
+
layout: BufferLayout.struct([BufferLayout.u32("instruction"), BufferLayout.ns64("lamports")])
|
|
21313
20984
|
},
|
|
21314
|
-
|
|
21315
|
-
index:
|
|
21316
|
-
layout: BufferLayout.struct([BufferLayout.
|
|
20985
|
+
Deactivate: {
|
|
20986
|
+
index: 5,
|
|
20987
|
+
layout: BufferLayout.struct([BufferLayout.u32("instruction")])
|
|
21317
20988
|
},
|
|
21318
|
-
|
|
21319
|
-
index:
|
|
21320
|
-
layout: BufferLayout.struct([BufferLayout.
|
|
20989
|
+
Merge: {
|
|
20990
|
+
index: 7,
|
|
20991
|
+
layout: BufferLayout.struct([BufferLayout.u32("instruction")])
|
|
21321
20992
|
},
|
|
21322
|
-
|
|
21323
|
-
index:
|
|
21324
|
-
layout: BufferLayout.struct([BufferLayout.
|
|
20993
|
+
AuthorizeWithSeed: {
|
|
20994
|
+
index: 8,
|
|
20995
|
+
layout: BufferLayout.struct([BufferLayout.u32("instruction"), publicKey("newAuthorized"), BufferLayout.u32("stakeAuthorizationType"), rustString("authoritySeed"), publicKey("authorityOwner")])
|
|
21325
20996
|
}
|
|
21326
20997
|
});
|
|
21327
|
-
var
|
|
20998
|
+
var StakeAuthorizationLayout = Object.freeze({
|
|
20999
|
+
Staker: {
|
|
21000
|
+
index: 0
|
|
21001
|
+
},
|
|
21002
|
+
Withdrawer: {
|
|
21003
|
+
index: 1
|
|
21004
|
+
}
|
|
21005
|
+
});
|
|
21006
|
+
var StakeProgram = class {
|
|
21328
21007
|
/**
|
|
21329
21008
|
* @internal
|
|
21330
21009
|
*/
|
|
21331
21010
|
constructor() {
|
|
21332
21011
|
}
|
|
21333
21012
|
/**
|
|
21334
|
-
* Public key that identifies the
|
|
21013
|
+
* Public key that identifies the Stake program
|
|
21335
21014
|
*/
|
|
21336
21015
|
/**
|
|
21337
|
-
*
|
|
21016
|
+
* Generate an Initialize instruction to add to a Stake Create transaction
|
|
21338
21017
|
*/
|
|
21339
|
-
static
|
|
21340
|
-
const
|
|
21341
|
-
|
|
21342
|
-
|
|
21343
|
-
|
|
21344
|
-
|
|
21345
|
-
|
|
21346
|
-
|
|
21347
|
-
}
|
|
21348
|
-
static requestHeapFrame(params) {
|
|
21349
|
-
const type2 = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.RequestHeapFrame;
|
|
21350
|
-
const data = encodeData(type2, params);
|
|
21351
|
-
return new TransactionInstruction({
|
|
21352
|
-
keys: [],
|
|
21353
|
-
programId: this.programId,
|
|
21354
|
-
data
|
|
21355
|
-
});
|
|
21356
|
-
}
|
|
21357
|
-
static setComputeUnitLimit(params) {
|
|
21358
|
-
const type2 = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitLimit;
|
|
21359
|
-
const data = encodeData(type2, params);
|
|
21360
|
-
return new TransactionInstruction({
|
|
21361
|
-
keys: [],
|
|
21362
|
-
programId: this.programId,
|
|
21363
|
-
data
|
|
21364
|
-
});
|
|
21365
|
-
}
|
|
21366
|
-
static setComputeUnitPrice(params) {
|
|
21367
|
-
const type2 = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitPrice;
|
|
21018
|
+
static initialize(params) {
|
|
21019
|
+
const {
|
|
21020
|
+
stakePubkey,
|
|
21021
|
+
authorized: authorized2,
|
|
21022
|
+
lockup: maybeLockup
|
|
21023
|
+
} = params;
|
|
21024
|
+
const lockup2 = maybeLockup || Lockup.default;
|
|
21025
|
+
const type2 = STAKE_INSTRUCTION_LAYOUTS.Initialize;
|
|
21368
21026
|
const data = encodeData(type2, {
|
|
21369
|
-
|
|
21027
|
+
authorized: {
|
|
21028
|
+
staker: toBuffer(authorized2.staker.toBuffer()),
|
|
21029
|
+
withdrawer: toBuffer(authorized2.withdrawer.toBuffer())
|
|
21030
|
+
},
|
|
21031
|
+
lockup: {
|
|
21032
|
+
unixTimestamp: lockup2.unixTimestamp,
|
|
21033
|
+
epoch: lockup2.epoch,
|
|
21034
|
+
custodian: toBuffer(lockup2.custodian.toBuffer())
|
|
21035
|
+
}
|
|
21370
21036
|
});
|
|
21371
|
-
|
|
21372
|
-
keys: [
|
|
21037
|
+
const instructionData = {
|
|
21038
|
+
keys: [{
|
|
21039
|
+
pubkey: stakePubkey,
|
|
21040
|
+
isSigner: false,
|
|
21041
|
+
isWritable: true
|
|
21042
|
+
}, {
|
|
21043
|
+
pubkey: SYSVAR_RENT_PUBKEY,
|
|
21044
|
+
isSigner: false,
|
|
21045
|
+
isWritable: false
|
|
21046
|
+
}],
|
|
21373
21047
|
programId: this.programId,
|
|
21374
21048
|
data
|
|
21375
|
-
}
|
|
21049
|
+
};
|
|
21050
|
+
return new TransactionInstruction(instructionData);
|
|
21376
21051
|
}
|
|
21377
|
-
};
|
|
21378
|
-
ComputeBudgetProgram.programId = new PublicKey("ComputeBudget111111111111111111111111111111");
|
|
21379
|
-
var PRIVATE_KEY_BYTES$1 = 64;
|
|
21380
|
-
var PUBLIC_KEY_BYTES$1 = 32;
|
|
21381
|
-
var SIGNATURE_BYTES = 64;
|
|
21382
|
-
var ED25519_INSTRUCTION_LAYOUT = BufferLayout.struct([BufferLayout.u8("numSignatures"), BufferLayout.u8("padding"), BufferLayout.u16("signatureOffset"), BufferLayout.u16("signatureInstructionIndex"), BufferLayout.u16("publicKeyOffset"), BufferLayout.u16("publicKeyInstructionIndex"), BufferLayout.u16("messageDataOffset"), BufferLayout.u16("messageDataSize"), BufferLayout.u16("messageInstructionIndex")]);
|
|
21383
|
-
var Ed25519Program = class _Ed25519Program {
|
|
21384
21052
|
/**
|
|
21385
|
-
*
|
|
21053
|
+
* Generate a Transaction that creates a new Stake account at
|
|
21054
|
+
* an address generated with `from`, a seed, and the Stake programId
|
|
21386
21055
|
*/
|
|
21387
|
-
|
|
21056
|
+
static createAccountWithSeed(params) {
|
|
21057
|
+
const transaction = new Transaction();
|
|
21058
|
+
transaction.add(SystemProgram.createAccountWithSeed({
|
|
21059
|
+
fromPubkey: params.fromPubkey,
|
|
21060
|
+
newAccountPubkey: params.stakePubkey,
|
|
21061
|
+
basePubkey: params.basePubkey,
|
|
21062
|
+
seed: params.seed,
|
|
21063
|
+
lamports: params.lamports,
|
|
21064
|
+
space: this.space,
|
|
21065
|
+
programId: this.programId
|
|
21066
|
+
}));
|
|
21067
|
+
const {
|
|
21068
|
+
stakePubkey,
|
|
21069
|
+
authorized: authorized2,
|
|
21070
|
+
lockup: lockup2
|
|
21071
|
+
} = params;
|
|
21072
|
+
return transaction.add(this.initialize({
|
|
21073
|
+
stakePubkey,
|
|
21074
|
+
authorized: authorized2,
|
|
21075
|
+
lockup: lockup2
|
|
21076
|
+
}));
|
|
21388
21077
|
}
|
|
21389
21078
|
/**
|
|
21390
|
-
*
|
|
21079
|
+
* Generate a Transaction that creates a new Stake account
|
|
21080
|
+
*/
|
|
21081
|
+
static createAccount(params) {
|
|
21082
|
+
const transaction = new Transaction();
|
|
21083
|
+
transaction.add(SystemProgram.createAccount({
|
|
21084
|
+
fromPubkey: params.fromPubkey,
|
|
21085
|
+
newAccountPubkey: params.stakePubkey,
|
|
21086
|
+
lamports: params.lamports,
|
|
21087
|
+
space: this.space,
|
|
21088
|
+
programId: this.programId
|
|
21089
|
+
}));
|
|
21090
|
+
const {
|
|
21091
|
+
stakePubkey,
|
|
21092
|
+
authorized: authorized2,
|
|
21093
|
+
lockup: lockup2
|
|
21094
|
+
} = params;
|
|
21095
|
+
return transaction.add(this.initialize({
|
|
21096
|
+
stakePubkey,
|
|
21097
|
+
authorized: authorized2,
|
|
21098
|
+
lockup: lockup2
|
|
21099
|
+
}));
|
|
21100
|
+
}
|
|
21101
|
+
/**
|
|
21102
|
+
* Generate a Transaction that delegates Stake tokens to a validator
|
|
21103
|
+
* Vote PublicKey. This transaction can also be used to redelegate Stake
|
|
21104
|
+
* to a new validator Vote PublicKey.
|
|
21391
21105
|
*/
|
|
21106
|
+
static delegate(params) {
|
|
21107
|
+
const {
|
|
21108
|
+
stakePubkey,
|
|
21109
|
+
authorizedPubkey,
|
|
21110
|
+
votePubkey
|
|
21111
|
+
} = params;
|
|
21112
|
+
const type2 = STAKE_INSTRUCTION_LAYOUTS.Delegate;
|
|
21113
|
+
const data = encodeData(type2);
|
|
21114
|
+
return new Transaction().add({
|
|
21115
|
+
keys: [{
|
|
21116
|
+
pubkey: stakePubkey,
|
|
21117
|
+
isSigner: false,
|
|
21118
|
+
isWritable: true
|
|
21119
|
+
}, {
|
|
21120
|
+
pubkey: votePubkey,
|
|
21121
|
+
isSigner: false,
|
|
21122
|
+
isWritable: false
|
|
21123
|
+
}, {
|
|
21124
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
21125
|
+
isSigner: false,
|
|
21126
|
+
isWritable: false
|
|
21127
|
+
}, {
|
|
21128
|
+
pubkey: SYSVAR_STAKE_HISTORY_PUBKEY,
|
|
21129
|
+
isSigner: false,
|
|
21130
|
+
isWritable: false
|
|
21131
|
+
}, {
|
|
21132
|
+
pubkey: STAKE_CONFIG_ID,
|
|
21133
|
+
isSigner: false,
|
|
21134
|
+
isWritable: false
|
|
21135
|
+
}, {
|
|
21136
|
+
pubkey: authorizedPubkey,
|
|
21137
|
+
isSigner: true,
|
|
21138
|
+
isWritable: false
|
|
21139
|
+
}],
|
|
21140
|
+
programId: this.programId,
|
|
21141
|
+
data
|
|
21142
|
+
});
|
|
21143
|
+
}
|
|
21392
21144
|
/**
|
|
21393
|
-
*
|
|
21394
|
-
*
|
|
21395
|
-
* must be a buffer of 64 bytes.
|
|
21145
|
+
* Generate a Transaction that authorizes a new PublicKey as Staker
|
|
21146
|
+
* or Withdrawer on the Stake account.
|
|
21396
21147
|
*/
|
|
21397
|
-
static
|
|
21148
|
+
static authorize(params) {
|
|
21398
21149
|
const {
|
|
21399
|
-
|
|
21400
|
-
|
|
21401
|
-
|
|
21402
|
-
|
|
21150
|
+
stakePubkey,
|
|
21151
|
+
authorizedPubkey,
|
|
21152
|
+
newAuthorizedPubkey,
|
|
21153
|
+
stakeAuthorizationType,
|
|
21154
|
+
custodianPubkey
|
|
21403
21155
|
} = params;
|
|
21404
|
-
|
|
21405
|
-
|
|
21406
|
-
|
|
21407
|
-
|
|
21408
|
-
|
|
21409
|
-
const
|
|
21410
|
-
|
|
21411
|
-
|
|
21412
|
-
|
|
21413
|
-
|
|
21414
|
-
|
|
21415
|
-
|
|
21416
|
-
|
|
21417
|
-
|
|
21418
|
-
|
|
21419
|
-
|
|
21420
|
-
|
|
21421
|
-
|
|
21422
|
-
|
|
21423
|
-
|
|
21424
|
-
|
|
21425
|
-
|
|
21426
|
-
|
|
21427
|
-
|
|
21428
|
-
|
|
21429
|
-
|
|
21156
|
+
const type2 = STAKE_INSTRUCTION_LAYOUTS.Authorize;
|
|
21157
|
+
const data = encodeData(type2, {
|
|
21158
|
+
newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
|
|
21159
|
+
stakeAuthorizationType: stakeAuthorizationType.index
|
|
21160
|
+
});
|
|
21161
|
+
const keys = [{
|
|
21162
|
+
pubkey: stakePubkey,
|
|
21163
|
+
isSigner: false,
|
|
21164
|
+
isWritable: true
|
|
21165
|
+
}, {
|
|
21166
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
21167
|
+
isSigner: false,
|
|
21168
|
+
isWritable: true
|
|
21169
|
+
}, {
|
|
21170
|
+
pubkey: authorizedPubkey,
|
|
21171
|
+
isSigner: true,
|
|
21172
|
+
isWritable: false
|
|
21173
|
+
}];
|
|
21174
|
+
if (custodianPubkey) {
|
|
21175
|
+
keys.push({
|
|
21176
|
+
pubkey: custodianPubkey,
|
|
21177
|
+
isSigner: true,
|
|
21178
|
+
isWritable: false
|
|
21179
|
+
});
|
|
21180
|
+
}
|
|
21181
|
+
return new Transaction().add({
|
|
21182
|
+
keys,
|
|
21183
|
+
programId: this.programId,
|
|
21184
|
+
data
|
|
21430
21185
|
});
|
|
21431
21186
|
}
|
|
21432
21187
|
/**
|
|
21433
|
-
*
|
|
21434
|
-
*
|
|
21188
|
+
* Generate a Transaction that authorizes a new PublicKey as Staker
|
|
21189
|
+
* or Withdrawer on the Stake account.
|
|
21435
21190
|
*/
|
|
21436
|
-
static
|
|
21191
|
+
static authorizeWithSeed(params) {
|
|
21437
21192
|
const {
|
|
21438
|
-
|
|
21439
|
-
|
|
21440
|
-
|
|
21193
|
+
stakePubkey,
|
|
21194
|
+
authorityBase,
|
|
21195
|
+
authoritySeed,
|
|
21196
|
+
authorityOwner,
|
|
21197
|
+
newAuthorizedPubkey,
|
|
21198
|
+
stakeAuthorizationType,
|
|
21199
|
+
custodianPubkey
|
|
21441
21200
|
} = params;
|
|
21442
|
-
|
|
21443
|
-
|
|
21444
|
-
|
|
21445
|
-
|
|
21446
|
-
|
|
21447
|
-
|
|
21448
|
-
|
|
21449
|
-
|
|
21450
|
-
|
|
21451
|
-
|
|
21201
|
+
const type2 = STAKE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed;
|
|
21202
|
+
const data = encodeData(type2, {
|
|
21203
|
+
newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
|
|
21204
|
+
stakeAuthorizationType: stakeAuthorizationType.index,
|
|
21205
|
+
authoritySeed,
|
|
21206
|
+
authorityOwner: toBuffer(authorityOwner.toBuffer())
|
|
21207
|
+
});
|
|
21208
|
+
const keys = [{
|
|
21209
|
+
pubkey: stakePubkey,
|
|
21210
|
+
isSigner: false,
|
|
21211
|
+
isWritable: true
|
|
21212
|
+
}, {
|
|
21213
|
+
pubkey: authorityBase,
|
|
21214
|
+
isSigner: true,
|
|
21215
|
+
isWritable: false
|
|
21216
|
+
}, {
|
|
21217
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
21218
|
+
isSigner: false,
|
|
21219
|
+
isWritable: false
|
|
21220
|
+
}];
|
|
21221
|
+
if (custodianPubkey) {
|
|
21222
|
+
keys.push({
|
|
21223
|
+
pubkey: custodianPubkey,
|
|
21224
|
+
isSigner: true,
|
|
21225
|
+
isWritable: false
|
|
21452
21226
|
});
|
|
21453
|
-
} catch (error) {
|
|
21454
|
-
throw new Error(`Error creating instruction; ${error}`);
|
|
21455
21227
|
}
|
|
21228
|
+
return new Transaction().add({
|
|
21229
|
+
keys,
|
|
21230
|
+
programId: this.programId,
|
|
21231
|
+
data
|
|
21232
|
+
});
|
|
21456
21233
|
}
|
|
21457
|
-
};
|
|
21458
|
-
Ed25519Program.programId = new PublicKey("Ed25519SigVerify111111111111111111111111111");
|
|
21459
|
-
var ecdsaSign = (msgHash, privKey) => {
|
|
21460
|
-
const signature = secp256k1.sign(msgHash, privKey);
|
|
21461
|
-
return [signature.toCompactRawBytes(), signature.recovery];
|
|
21462
|
-
};
|
|
21463
|
-
secp256k1.utils.isValidPrivateKey;
|
|
21464
|
-
var publicKeyCreate = secp256k1.getPublicKey;
|
|
21465
|
-
var PRIVATE_KEY_BYTES = 32;
|
|
21466
|
-
var ETHEREUM_ADDRESS_BYTES = 20;
|
|
21467
|
-
var PUBLIC_KEY_BYTES = 64;
|
|
21468
|
-
var SIGNATURE_OFFSETS_SERIALIZED_SIZE = 11;
|
|
21469
|
-
var SECP256K1_INSTRUCTION_LAYOUT = BufferLayout.struct([BufferLayout.u8("numSignatures"), BufferLayout.u16("signatureOffset"), BufferLayout.u8("signatureInstructionIndex"), BufferLayout.u16("ethAddressOffset"), BufferLayout.u8("ethAddressInstructionIndex"), BufferLayout.u16("messageDataOffset"), BufferLayout.u16("messageDataSize"), BufferLayout.u8("messageInstructionIndex"), BufferLayout.blob(20, "ethAddress"), BufferLayout.blob(64, "signature"), BufferLayout.u8("recoveryId")]);
|
|
21470
|
-
var Secp256k1Program = class _Secp256k1Program {
|
|
21471
21234
|
/**
|
|
21472
21235
|
* @internal
|
|
21473
21236
|
*/
|
|
21474
|
-
|
|
21237
|
+
static splitInstruction(params) {
|
|
21238
|
+
const {
|
|
21239
|
+
stakePubkey,
|
|
21240
|
+
authorizedPubkey,
|
|
21241
|
+
splitStakePubkey,
|
|
21242
|
+
lamports
|
|
21243
|
+
} = params;
|
|
21244
|
+
const type2 = STAKE_INSTRUCTION_LAYOUTS.Split;
|
|
21245
|
+
const data = encodeData(type2, {
|
|
21246
|
+
lamports
|
|
21247
|
+
});
|
|
21248
|
+
return new TransactionInstruction({
|
|
21249
|
+
keys: [{
|
|
21250
|
+
pubkey: stakePubkey,
|
|
21251
|
+
isSigner: false,
|
|
21252
|
+
isWritable: true
|
|
21253
|
+
}, {
|
|
21254
|
+
pubkey: splitStakePubkey,
|
|
21255
|
+
isSigner: false,
|
|
21256
|
+
isWritable: true
|
|
21257
|
+
}, {
|
|
21258
|
+
pubkey: authorizedPubkey,
|
|
21259
|
+
isSigner: true,
|
|
21260
|
+
isWritable: false
|
|
21261
|
+
}],
|
|
21262
|
+
programId: this.programId,
|
|
21263
|
+
data
|
|
21264
|
+
});
|
|
21475
21265
|
}
|
|
21476
21266
|
/**
|
|
21477
|
-
*
|
|
21478
|
-
*/
|
|
21479
|
-
/**
|
|
21480
|
-
* Construct an Ethereum address from a secp256k1 public key buffer.
|
|
21481
|
-
* @param {Buffer} publicKey a 64 byte secp256k1 public key buffer
|
|
21267
|
+
* Generate a Transaction that splits Stake tokens into another stake account
|
|
21482
21268
|
*/
|
|
21483
|
-
static
|
|
21484
|
-
|
|
21485
|
-
|
|
21486
|
-
|
|
21487
|
-
|
|
21488
|
-
|
|
21489
|
-
|
|
21269
|
+
static split(params, rentExemptReserve) {
|
|
21270
|
+
const transaction = new Transaction();
|
|
21271
|
+
transaction.add(SystemProgram.createAccount({
|
|
21272
|
+
fromPubkey: params.authorizedPubkey,
|
|
21273
|
+
newAccountPubkey: params.splitStakePubkey,
|
|
21274
|
+
lamports: rentExemptReserve,
|
|
21275
|
+
space: this.space,
|
|
21276
|
+
programId: this.programId
|
|
21277
|
+
}));
|
|
21278
|
+
return transaction.add(this.splitInstruction(params));
|
|
21490
21279
|
}
|
|
21491
21280
|
/**
|
|
21492
|
-
*
|
|
21493
|
-
*
|
|
21281
|
+
* Generate a Transaction that splits Stake tokens into another account
|
|
21282
|
+
* derived from a base public key and seed
|
|
21494
21283
|
*/
|
|
21495
|
-
static
|
|
21284
|
+
static splitWithSeed(params, rentExemptReserve) {
|
|
21496
21285
|
const {
|
|
21497
|
-
|
|
21498
|
-
|
|
21499
|
-
|
|
21500
|
-
|
|
21501
|
-
|
|
21286
|
+
stakePubkey,
|
|
21287
|
+
authorizedPubkey,
|
|
21288
|
+
splitStakePubkey,
|
|
21289
|
+
basePubkey,
|
|
21290
|
+
seed,
|
|
21291
|
+
lamports
|
|
21502
21292
|
} = params;
|
|
21503
|
-
|
|
21504
|
-
|
|
21505
|
-
|
|
21506
|
-
|
|
21507
|
-
|
|
21508
|
-
|
|
21509
|
-
|
|
21293
|
+
const transaction = new Transaction();
|
|
21294
|
+
transaction.add(SystemProgram.allocate({
|
|
21295
|
+
accountPubkey: splitStakePubkey,
|
|
21296
|
+
basePubkey,
|
|
21297
|
+
seed,
|
|
21298
|
+
space: this.space,
|
|
21299
|
+
programId: this.programId
|
|
21300
|
+
}));
|
|
21301
|
+
if (rentExemptReserve && rentExemptReserve > 0) {
|
|
21302
|
+
transaction.add(SystemProgram.transfer({
|
|
21303
|
+
fromPubkey: params.authorizedPubkey,
|
|
21304
|
+
toPubkey: splitStakePubkey,
|
|
21305
|
+
lamports: rentExemptReserve
|
|
21306
|
+
}));
|
|
21307
|
+
}
|
|
21308
|
+
return transaction.add(this.splitInstruction({
|
|
21309
|
+
stakePubkey,
|
|
21310
|
+
authorizedPubkey,
|
|
21311
|
+
splitStakePubkey,
|
|
21312
|
+
lamports
|
|
21313
|
+
}));
|
|
21510
21314
|
}
|
|
21511
21315
|
/**
|
|
21512
|
-
*
|
|
21513
|
-
* must be a hex string or a buffer that is 20 bytes long.
|
|
21316
|
+
* Generate a Transaction that merges Stake accounts.
|
|
21514
21317
|
*/
|
|
21515
|
-
static
|
|
21318
|
+
static merge(params) {
|
|
21516
21319
|
const {
|
|
21517
|
-
|
|
21518
|
-
|
|
21519
|
-
|
|
21520
|
-
recoveryId,
|
|
21521
|
-
instructionIndex = 0
|
|
21320
|
+
stakePubkey,
|
|
21321
|
+
sourceStakePubKey,
|
|
21322
|
+
authorizedPubkey
|
|
21522
21323
|
} = params;
|
|
21523
|
-
|
|
21524
|
-
|
|
21525
|
-
|
|
21526
|
-
|
|
21527
|
-
|
|
21528
|
-
|
|
21529
|
-
|
|
21530
|
-
|
|
21531
|
-
|
|
21532
|
-
|
|
21533
|
-
|
|
21534
|
-
|
|
21535
|
-
|
|
21536
|
-
|
|
21537
|
-
|
|
21538
|
-
|
|
21539
|
-
|
|
21540
|
-
|
|
21541
|
-
|
|
21542
|
-
|
|
21543
|
-
|
|
21544
|
-
|
|
21545
|
-
|
|
21546
|
-
|
|
21547
|
-
|
|
21548
|
-
|
|
21549
|
-
signature: toBuffer(signature),
|
|
21550
|
-
ethAddress: toBuffer(ethAddress),
|
|
21551
|
-
recoveryId
|
|
21552
|
-
}, instructionData);
|
|
21553
|
-
instructionData.fill(toBuffer(message), SECP256K1_INSTRUCTION_LAYOUT.span);
|
|
21554
|
-
return new TransactionInstruction({
|
|
21555
|
-
keys: [],
|
|
21556
|
-
programId: _Secp256k1Program.programId,
|
|
21557
|
-
data: instructionData
|
|
21324
|
+
const type2 = STAKE_INSTRUCTION_LAYOUTS.Merge;
|
|
21325
|
+
const data = encodeData(type2);
|
|
21326
|
+
return new Transaction().add({
|
|
21327
|
+
keys: [{
|
|
21328
|
+
pubkey: stakePubkey,
|
|
21329
|
+
isSigner: false,
|
|
21330
|
+
isWritable: true
|
|
21331
|
+
}, {
|
|
21332
|
+
pubkey: sourceStakePubKey,
|
|
21333
|
+
isSigner: false,
|
|
21334
|
+
isWritable: true
|
|
21335
|
+
}, {
|
|
21336
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
21337
|
+
isSigner: false,
|
|
21338
|
+
isWritable: false
|
|
21339
|
+
}, {
|
|
21340
|
+
pubkey: SYSVAR_STAKE_HISTORY_PUBKEY,
|
|
21341
|
+
isSigner: false,
|
|
21342
|
+
isWritable: false
|
|
21343
|
+
}, {
|
|
21344
|
+
pubkey: authorizedPubkey,
|
|
21345
|
+
isSigner: true,
|
|
21346
|
+
isWritable: false
|
|
21347
|
+
}],
|
|
21348
|
+
programId: this.programId,
|
|
21349
|
+
data
|
|
21558
21350
|
});
|
|
21559
21351
|
}
|
|
21560
21352
|
/**
|
|
21561
|
-
*
|
|
21562
|
-
* must be a buffer that is 32 bytes long.
|
|
21353
|
+
* Generate a Transaction that withdraws deactivated Stake tokens.
|
|
21563
21354
|
*/
|
|
21564
|
-
static
|
|
21355
|
+
static withdraw(params) {
|
|
21565
21356
|
const {
|
|
21566
|
-
|
|
21567
|
-
|
|
21568
|
-
|
|
21357
|
+
stakePubkey,
|
|
21358
|
+
authorizedPubkey,
|
|
21359
|
+
toPubkey,
|
|
21360
|
+
lamports,
|
|
21361
|
+
custodianPubkey
|
|
21569
21362
|
} = params;
|
|
21570
|
-
|
|
21571
|
-
|
|
21572
|
-
|
|
21573
|
-
|
|
21574
|
-
|
|
21575
|
-
|
|
21576
|
-
|
|
21577
|
-
|
|
21578
|
-
|
|
21579
|
-
|
|
21580
|
-
|
|
21581
|
-
|
|
21582
|
-
|
|
21583
|
-
|
|
21584
|
-
|
|
21585
|
-
|
|
21363
|
+
const type2 = STAKE_INSTRUCTION_LAYOUTS.Withdraw;
|
|
21364
|
+
const data = encodeData(type2, {
|
|
21365
|
+
lamports
|
|
21366
|
+
});
|
|
21367
|
+
const keys = [{
|
|
21368
|
+
pubkey: stakePubkey,
|
|
21369
|
+
isSigner: false,
|
|
21370
|
+
isWritable: true
|
|
21371
|
+
}, {
|
|
21372
|
+
pubkey: toPubkey,
|
|
21373
|
+
isSigner: false,
|
|
21374
|
+
isWritable: true
|
|
21375
|
+
}, {
|
|
21376
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
21377
|
+
isSigner: false,
|
|
21378
|
+
isWritable: false
|
|
21379
|
+
}, {
|
|
21380
|
+
pubkey: SYSVAR_STAKE_HISTORY_PUBKEY,
|
|
21381
|
+
isSigner: false,
|
|
21382
|
+
isWritable: false
|
|
21383
|
+
}, {
|
|
21384
|
+
pubkey: authorizedPubkey,
|
|
21385
|
+
isSigner: true,
|
|
21386
|
+
isWritable: false
|
|
21387
|
+
}];
|
|
21388
|
+
if (custodianPubkey) {
|
|
21389
|
+
keys.push({
|
|
21390
|
+
pubkey: custodianPubkey,
|
|
21391
|
+
isSigner: true,
|
|
21392
|
+
isWritable: false
|
|
21586
21393
|
});
|
|
21587
|
-
} catch (error) {
|
|
21588
|
-
throw new Error(`Error creating instruction; ${error}`);
|
|
21589
21394
|
}
|
|
21395
|
+
return new Transaction().add({
|
|
21396
|
+
keys,
|
|
21397
|
+
programId: this.programId,
|
|
21398
|
+
data
|
|
21399
|
+
});
|
|
21590
21400
|
}
|
|
21591
|
-
};
|
|
21592
|
-
Secp256k1Program.programId = new PublicKey("KeccakSecp256k11111111111111111111111111111");
|
|
21593
|
-
var _Lockup;
|
|
21594
|
-
var STAKE_CONFIG_ID = new PublicKey("StakeConfig11111111111111111111111111111111");
|
|
21595
|
-
var Lockup = class {
|
|
21596
21401
|
/**
|
|
21597
|
-
*
|
|
21402
|
+
* Generate a Transaction that deactivates Stake tokens.
|
|
21598
21403
|
*/
|
|
21599
|
-
|
|
21600
|
-
|
|
21601
|
-
|
|
21602
|
-
|
|
21603
|
-
|
|
21604
|
-
|
|
21605
|
-
|
|
21404
|
+
static deactivate(params) {
|
|
21405
|
+
const {
|
|
21406
|
+
stakePubkey,
|
|
21407
|
+
authorizedPubkey
|
|
21408
|
+
} = params;
|
|
21409
|
+
const type2 = STAKE_INSTRUCTION_LAYOUTS.Deactivate;
|
|
21410
|
+
const data = encodeData(type2);
|
|
21411
|
+
return new Transaction().add({
|
|
21412
|
+
keys: [{
|
|
21413
|
+
pubkey: stakePubkey,
|
|
21414
|
+
isSigner: false,
|
|
21415
|
+
isWritable: true
|
|
21416
|
+
}, {
|
|
21417
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
21418
|
+
isSigner: false,
|
|
21419
|
+
isWritable: false
|
|
21420
|
+
}, {
|
|
21421
|
+
pubkey: authorizedPubkey,
|
|
21422
|
+
isSigner: true,
|
|
21423
|
+
isWritable: false
|
|
21424
|
+
}],
|
|
21425
|
+
programId: this.programId,
|
|
21426
|
+
data
|
|
21427
|
+
});
|
|
21606
21428
|
}
|
|
21607
|
-
/**
|
|
21608
|
-
* Default, inactive Lockup value
|
|
21609
|
-
*/
|
|
21610
21429
|
};
|
|
21611
|
-
|
|
21612
|
-
|
|
21613
|
-
var
|
|
21614
|
-
|
|
21430
|
+
StakeProgram.programId = new PublicKey("Stake11111111111111111111111111111111111111");
|
|
21431
|
+
StakeProgram.space = 200;
|
|
21432
|
+
var VOTE_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
21433
|
+
InitializeAccount: {
|
|
21615
21434
|
index: 0,
|
|
21616
|
-
layout: BufferLayout.struct([BufferLayout.u32("instruction"),
|
|
21435
|
+
layout: BufferLayout.struct([BufferLayout.u32("instruction"), voteInit()])
|
|
21617
21436
|
},
|
|
21618
21437
|
Authorize: {
|
|
21619
21438
|
index: 1,
|
|
21620
|
-
layout: BufferLayout.struct([BufferLayout.u32("instruction"), publicKey("newAuthorized"), BufferLayout.u32("
|
|
21621
|
-
},
|
|
21622
|
-
Delegate: {
|
|
21623
|
-
index: 2,
|
|
21624
|
-
layout: BufferLayout.struct([BufferLayout.u32("instruction")])
|
|
21439
|
+
layout: BufferLayout.struct([BufferLayout.u32("instruction"), publicKey("newAuthorized"), BufferLayout.u32("voteAuthorizationType")])
|
|
21625
21440
|
},
|
|
21626
|
-
|
|
21441
|
+
Withdraw: {
|
|
21627
21442
|
index: 3,
|
|
21628
21443
|
layout: BufferLayout.struct([BufferLayout.u32("instruction"), BufferLayout.ns64("lamports")])
|
|
21629
21444
|
},
|
|
21630
|
-
|
|
21445
|
+
UpdateValidatorIdentity: {
|
|
21631
21446
|
index: 4,
|
|
21632
|
-
layout: BufferLayout.struct([BufferLayout.u32("instruction"), BufferLayout.ns64("lamports")])
|
|
21633
|
-
},
|
|
21634
|
-
Deactivate: {
|
|
21635
|
-
index: 5,
|
|
21636
|
-
layout: BufferLayout.struct([BufferLayout.u32("instruction")])
|
|
21637
|
-
},
|
|
21638
|
-
Merge: {
|
|
21639
|
-
index: 7,
|
|
21640
21447
|
layout: BufferLayout.struct([BufferLayout.u32("instruction")])
|
|
21641
21448
|
},
|
|
21642
21449
|
AuthorizeWithSeed: {
|
|
21643
|
-
index:
|
|
21644
|
-
layout: BufferLayout.struct([BufferLayout.u32("instruction"),
|
|
21450
|
+
index: 10,
|
|
21451
|
+
layout: BufferLayout.struct([BufferLayout.u32("instruction"), voteAuthorizeWithSeedArgs()])
|
|
21645
21452
|
}
|
|
21646
21453
|
});
|
|
21647
|
-
var
|
|
21648
|
-
|
|
21454
|
+
var VoteAuthorizationLayout = Object.freeze({
|
|
21455
|
+
Voter: {
|
|
21649
21456
|
index: 0
|
|
21650
21457
|
},
|
|
21651
21458
|
Withdrawer: {
|
|
21652
21459
|
index: 1
|
|
21653
21460
|
}
|
|
21654
21461
|
});
|
|
21655
|
-
var
|
|
21462
|
+
var VoteProgram = class _VoteProgram {
|
|
21656
21463
|
/**
|
|
21657
21464
|
* @internal
|
|
21658
21465
|
*/
|
|
21659
21466
|
constructor() {
|
|
21660
21467
|
}
|
|
21661
21468
|
/**
|
|
21662
|
-
* Public key that identifies the
|
|
21469
|
+
* Public key that identifies the Vote program
|
|
21663
21470
|
*/
|
|
21664
21471
|
/**
|
|
21665
|
-
* Generate an Initialize instruction
|
|
21472
|
+
* Generate an Initialize instruction.
|
|
21666
21473
|
*/
|
|
21667
|
-
static
|
|
21474
|
+
static initializeAccount(params) {
|
|
21668
21475
|
const {
|
|
21669
|
-
|
|
21670
|
-
|
|
21671
|
-
|
|
21476
|
+
votePubkey,
|
|
21477
|
+
nodePubkey,
|
|
21478
|
+
voteInit: voteInit2
|
|
21672
21479
|
} = params;
|
|
21673
|
-
const
|
|
21674
|
-
const type2 = STAKE_INSTRUCTION_LAYOUTS.Initialize;
|
|
21480
|
+
const type2 = VOTE_INSTRUCTION_LAYOUTS.InitializeAccount;
|
|
21675
21481
|
const data = encodeData(type2, {
|
|
21676
|
-
|
|
21677
|
-
|
|
21678
|
-
|
|
21679
|
-
|
|
21680
|
-
|
|
21681
|
-
unixTimestamp: lockup2.unixTimestamp,
|
|
21682
|
-
epoch: lockup2.epoch,
|
|
21683
|
-
custodian: toBuffer(lockup2.custodian.toBuffer())
|
|
21482
|
+
voteInit: {
|
|
21483
|
+
nodePubkey: toBuffer(voteInit2.nodePubkey.toBuffer()),
|
|
21484
|
+
authorizedVoter: toBuffer(voteInit2.authorizedVoter.toBuffer()),
|
|
21485
|
+
authorizedWithdrawer: toBuffer(voteInit2.authorizedWithdrawer.toBuffer()),
|
|
21486
|
+
commission: voteInit2.commission
|
|
21684
21487
|
}
|
|
21685
21488
|
});
|
|
21686
21489
|
const instructionData = {
|
|
21687
21490
|
keys: [{
|
|
21688
|
-
pubkey:
|
|
21491
|
+
pubkey: votePubkey,
|
|
21689
21492
|
isSigner: false,
|
|
21690
21493
|
isWritable: true
|
|
21691
21494
|
}, {
|
|
21692
21495
|
pubkey: SYSVAR_RENT_PUBKEY,
|
|
21693
21496
|
isSigner: false,
|
|
21694
21497
|
isWritable: false
|
|
21498
|
+
}, {
|
|
21499
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
21500
|
+
isSigner: false,
|
|
21501
|
+
isWritable: false
|
|
21502
|
+
}, {
|
|
21503
|
+
pubkey: nodePubkey,
|
|
21504
|
+
isSigner: true,
|
|
21505
|
+
isWritable: false
|
|
21695
21506
|
}],
|
|
21696
21507
|
programId: this.programId,
|
|
21697
21508
|
data
|
|
@@ -21699,134 +21510,51 @@ var StakeProgram = class {
|
|
|
21699
21510
|
return new TransactionInstruction(instructionData);
|
|
21700
21511
|
}
|
|
21701
21512
|
/**
|
|
21702
|
-
* Generate a
|
|
21703
|
-
* an address generated with `from`, a seed, and the Stake programId
|
|
21704
|
-
*/
|
|
21705
|
-
static createAccountWithSeed(params) {
|
|
21706
|
-
const transaction = new Transaction();
|
|
21707
|
-
transaction.add(SystemProgram.createAccountWithSeed({
|
|
21708
|
-
fromPubkey: params.fromPubkey,
|
|
21709
|
-
newAccountPubkey: params.stakePubkey,
|
|
21710
|
-
basePubkey: params.basePubkey,
|
|
21711
|
-
seed: params.seed,
|
|
21712
|
-
lamports: params.lamports,
|
|
21713
|
-
space: this.space,
|
|
21714
|
-
programId: this.programId
|
|
21715
|
-
}));
|
|
21716
|
-
const {
|
|
21717
|
-
stakePubkey,
|
|
21718
|
-
authorized: authorized2,
|
|
21719
|
-
lockup: lockup2
|
|
21720
|
-
} = params;
|
|
21721
|
-
return transaction.add(this.initialize({
|
|
21722
|
-
stakePubkey,
|
|
21723
|
-
authorized: authorized2,
|
|
21724
|
-
lockup: lockup2
|
|
21725
|
-
}));
|
|
21726
|
-
}
|
|
21727
|
-
/**
|
|
21728
|
-
* Generate a Transaction that creates a new Stake account
|
|
21513
|
+
* Generate a transaction that creates a new Vote account.
|
|
21729
21514
|
*/
|
|
21730
21515
|
static createAccount(params) {
|
|
21731
21516
|
const transaction = new Transaction();
|
|
21732
21517
|
transaction.add(SystemProgram.createAccount({
|
|
21733
21518
|
fromPubkey: params.fromPubkey,
|
|
21734
|
-
newAccountPubkey: params.
|
|
21519
|
+
newAccountPubkey: params.votePubkey,
|
|
21735
21520
|
lamports: params.lamports,
|
|
21736
21521
|
space: this.space,
|
|
21737
21522
|
programId: this.programId
|
|
21738
21523
|
}));
|
|
21739
|
-
|
|
21740
|
-
|
|
21741
|
-
|
|
21742
|
-
|
|
21743
|
-
}
|
|
21744
|
-
return transaction.add(this.initialize({
|
|
21745
|
-
stakePubkey,
|
|
21746
|
-
authorized: authorized2,
|
|
21747
|
-
lockup: lockup2
|
|
21748
|
-
}));
|
|
21749
|
-
}
|
|
21750
|
-
/**
|
|
21751
|
-
* Generate a Transaction that delegates Stake tokens to a validator
|
|
21752
|
-
* Vote PublicKey. This transaction can also be used to redelegate Stake
|
|
21753
|
-
* to a new validator Vote PublicKey.
|
|
21754
|
-
*/
|
|
21755
|
-
static delegate(params) {
|
|
21756
|
-
const {
|
|
21757
|
-
stakePubkey,
|
|
21758
|
-
authorizedPubkey,
|
|
21759
|
-
votePubkey
|
|
21760
|
-
} = params;
|
|
21761
|
-
const type2 = STAKE_INSTRUCTION_LAYOUTS.Delegate;
|
|
21762
|
-
const data = encodeData(type2);
|
|
21763
|
-
return new Transaction().add({
|
|
21764
|
-
keys: [{
|
|
21765
|
-
pubkey: stakePubkey,
|
|
21766
|
-
isSigner: false,
|
|
21767
|
-
isWritable: true
|
|
21768
|
-
}, {
|
|
21769
|
-
pubkey: votePubkey,
|
|
21770
|
-
isSigner: false,
|
|
21771
|
-
isWritable: false
|
|
21772
|
-
}, {
|
|
21773
|
-
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
21774
|
-
isSigner: false,
|
|
21775
|
-
isWritable: false
|
|
21776
|
-
}, {
|
|
21777
|
-
pubkey: SYSVAR_STAKE_HISTORY_PUBKEY,
|
|
21778
|
-
isSigner: false,
|
|
21779
|
-
isWritable: false
|
|
21780
|
-
}, {
|
|
21781
|
-
pubkey: STAKE_CONFIG_ID,
|
|
21782
|
-
isSigner: false,
|
|
21783
|
-
isWritable: false
|
|
21784
|
-
}, {
|
|
21785
|
-
pubkey: authorizedPubkey,
|
|
21786
|
-
isSigner: true,
|
|
21787
|
-
isWritable: false
|
|
21788
|
-
}],
|
|
21789
|
-
programId: this.programId,
|
|
21790
|
-
data
|
|
21791
|
-
});
|
|
21524
|
+
return transaction.add(this.initializeAccount({
|
|
21525
|
+
votePubkey: params.votePubkey,
|
|
21526
|
+
nodePubkey: params.voteInit.nodePubkey,
|
|
21527
|
+
voteInit: params.voteInit
|
|
21528
|
+
}));
|
|
21792
21529
|
}
|
|
21793
21530
|
/**
|
|
21794
|
-
* Generate a
|
|
21795
|
-
* or Withdrawer on the Stake account.
|
|
21531
|
+
* Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account.
|
|
21796
21532
|
*/
|
|
21797
21533
|
static authorize(params) {
|
|
21798
21534
|
const {
|
|
21799
|
-
|
|
21535
|
+
votePubkey,
|
|
21800
21536
|
authorizedPubkey,
|
|
21801
21537
|
newAuthorizedPubkey,
|
|
21802
|
-
|
|
21803
|
-
custodianPubkey
|
|
21538
|
+
voteAuthorizationType
|
|
21804
21539
|
} = params;
|
|
21805
|
-
const type2 =
|
|
21540
|
+
const type2 = VOTE_INSTRUCTION_LAYOUTS.Authorize;
|
|
21806
21541
|
const data = encodeData(type2, {
|
|
21807
21542
|
newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
|
|
21808
|
-
|
|
21543
|
+
voteAuthorizationType: voteAuthorizationType.index
|
|
21809
21544
|
});
|
|
21810
21545
|
const keys = [{
|
|
21811
|
-
pubkey:
|
|
21546
|
+
pubkey: votePubkey,
|
|
21812
21547
|
isSigner: false,
|
|
21813
21548
|
isWritable: true
|
|
21814
21549
|
}, {
|
|
21815
21550
|
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
21816
21551
|
isSigner: false,
|
|
21817
|
-
isWritable:
|
|
21552
|
+
isWritable: false
|
|
21818
21553
|
}, {
|
|
21819
21554
|
pubkey: authorizedPubkey,
|
|
21820
21555
|
isSigner: true,
|
|
21821
21556
|
isWritable: false
|
|
21822
21557
|
}];
|
|
21823
|
-
if (custodianPubkey) {
|
|
21824
|
-
keys.push({
|
|
21825
|
-
pubkey: custodianPubkey,
|
|
21826
|
-
isSigner: true,
|
|
21827
|
-
isWritable: false
|
|
21828
|
-
});
|
|
21829
|
-
}
|
|
21830
21558
|
return new Transaction().add({
|
|
21831
21559
|
keys,
|
|
21832
21560
|
programId: this.programId,
|
|
@@ -21834,530 +21562,914 @@ var StakeProgram = class {
|
|
|
21834
21562
|
});
|
|
21835
21563
|
}
|
|
21836
21564
|
/**
|
|
21837
|
-
* Generate a
|
|
21838
|
-
* or Withdrawer
|
|
21565
|
+
* Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account
|
|
21566
|
+
* where the current Voter or Withdrawer authority is a derived key.
|
|
21839
21567
|
*/
|
|
21840
21568
|
static authorizeWithSeed(params) {
|
|
21841
21569
|
const {
|
|
21842
|
-
|
|
21843
|
-
|
|
21844
|
-
|
|
21845
|
-
authorityOwner,
|
|
21570
|
+
currentAuthorityDerivedKeyBasePubkey,
|
|
21571
|
+
currentAuthorityDerivedKeyOwnerPubkey,
|
|
21572
|
+
currentAuthorityDerivedKeySeed,
|
|
21846
21573
|
newAuthorizedPubkey,
|
|
21847
|
-
|
|
21848
|
-
|
|
21574
|
+
voteAuthorizationType,
|
|
21575
|
+
votePubkey
|
|
21849
21576
|
} = params;
|
|
21850
|
-
const type2 =
|
|
21577
|
+
const type2 = VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed;
|
|
21851
21578
|
const data = encodeData(type2, {
|
|
21852
|
-
|
|
21853
|
-
|
|
21854
|
-
|
|
21855
|
-
|
|
21579
|
+
voteAuthorizeWithSeedArgs: {
|
|
21580
|
+
currentAuthorityDerivedKeyOwnerPubkey: toBuffer(currentAuthorityDerivedKeyOwnerPubkey.toBuffer()),
|
|
21581
|
+
currentAuthorityDerivedKeySeed,
|
|
21582
|
+
newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
|
|
21583
|
+
voteAuthorizationType: voteAuthorizationType.index
|
|
21584
|
+
}
|
|
21856
21585
|
});
|
|
21857
21586
|
const keys = [{
|
|
21858
|
-
pubkey:
|
|
21587
|
+
pubkey: votePubkey,
|
|
21859
21588
|
isSigner: false,
|
|
21860
21589
|
isWritable: true
|
|
21861
21590
|
}, {
|
|
21862
|
-
pubkey:
|
|
21591
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
21592
|
+
isSigner: false,
|
|
21593
|
+
isWritable: false
|
|
21594
|
+
}, {
|
|
21595
|
+
pubkey: currentAuthorityDerivedKeyBasePubkey,
|
|
21863
21596
|
isSigner: true,
|
|
21864
21597
|
isWritable: false
|
|
21598
|
+
}];
|
|
21599
|
+
return new Transaction().add({
|
|
21600
|
+
keys,
|
|
21601
|
+
programId: this.programId,
|
|
21602
|
+
data
|
|
21603
|
+
});
|
|
21604
|
+
}
|
|
21605
|
+
/**
|
|
21606
|
+
* Generate a transaction to withdraw from a Vote account.
|
|
21607
|
+
*/
|
|
21608
|
+
static withdraw(params) {
|
|
21609
|
+
const {
|
|
21610
|
+
votePubkey,
|
|
21611
|
+
authorizedWithdrawerPubkey,
|
|
21612
|
+
lamports,
|
|
21613
|
+
toPubkey
|
|
21614
|
+
} = params;
|
|
21615
|
+
const type2 = VOTE_INSTRUCTION_LAYOUTS.Withdraw;
|
|
21616
|
+
const data = encodeData(type2, {
|
|
21617
|
+
lamports
|
|
21618
|
+
});
|
|
21619
|
+
const keys = [{
|
|
21620
|
+
pubkey: votePubkey,
|
|
21621
|
+
isSigner: false,
|
|
21622
|
+
isWritable: true
|
|
21865
21623
|
}, {
|
|
21866
|
-
pubkey:
|
|
21624
|
+
pubkey: toPubkey,
|
|
21867
21625
|
isSigner: false,
|
|
21626
|
+
isWritable: true
|
|
21627
|
+
}, {
|
|
21628
|
+
pubkey: authorizedWithdrawerPubkey,
|
|
21629
|
+
isSigner: true,
|
|
21868
21630
|
isWritable: false
|
|
21869
21631
|
}];
|
|
21870
|
-
|
|
21871
|
-
keys
|
|
21872
|
-
|
|
21873
|
-
|
|
21874
|
-
|
|
21632
|
+
return new Transaction().add({
|
|
21633
|
+
keys,
|
|
21634
|
+
programId: this.programId,
|
|
21635
|
+
data
|
|
21636
|
+
});
|
|
21637
|
+
}
|
|
21638
|
+
/**
|
|
21639
|
+
* Generate a transaction to withdraw safely from a Vote account.
|
|
21640
|
+
*
|
|
21641
|
+
* This function was created as a safeguard for vote accounts running validators, `safeWithdraw`
|
|
21642
|
+
* checks that the withdraw amount will not exceed the specified balance while leaving enough left
|
|
21643
|
+
* to cover rent. If you wish to close the vote account by withdrawing the full amount, call the
|
|
21644
|
+
* `withdraw` method directly.
|
|
21645
|
+
*/
|
|
21646
|
+
static safeWithdraw(params, currentVoteAccountBalance, rentExemptMinimum) {
|
|
21647
|
+
if (params.lamports > currentVoteAccountBalance - rentExemptMinimum) {
|
|
21648
|
+
throw new Error("Withdraw will leave vote account with insufficient funds.");
|
|
21649
|
+
}
|
|
21650
|
+
return _VoteProgram.withdraw(params);
|
|
21651
|
+
}
|
|
21652
|
+
/**
|
|
21653
|
+
* Generate a transaction to update the validator identity (node pubkey) of a Vote account.
|
|
21654
|
+
*/
|
|
21655
|
+
static updateValidatorIdentity(params) {
|
|
21656
|
+
const {
|
|
21657
|
+
votePubkey,
|
|
21658
|
+
authorizedWithdrawerPubkey,
|
|
21659
|
+
nodePubkey
|
|
21660
|
+
} = params;
|
|
21661
|
+
const type2 = VOTE_INSTRUCTION_LAYOUTS.UpdateValidatorIdentity;
|
|
21662
|
+
const data = encodeData(type2);
|
|
21663
|
+
const keys = [{
|
|
21664
|
+
pubkey: votePubkey,
|
|
21665
|
+
isSigner: false,
|
|
21666
|
+
isWritable: true
|
|
21667
|
+
}, {
|
|
21668
|
+
pubkey: nodePubkey,
|
|
21669
|
+
isSigner: true,
|
|
21670
|
+
isWritable: false
|
|
21671
|
+
}, {
|
|
21672
|
+
pubkey: authorizedWithdrawerPubkey,
|
|
21673
|
+
isSigner: true,
|
|
21674
|
+
isWritable: false
|
|
21675
|
+
}];
|
|
21676
|
+
return new Transaction().add({
|
|
21677
|
+
keys,
|
|
21678
|
+
programId: this.programId,
|
|
21679
|
+
data
|
|
21680
|
+
});
|
|
21681
|
+
}
|
|
21682
|
+
};
|
|
21683
|
+
VoteProgram.programId = new PublicKey("Vote111111111111111111111111111111111111111");
|
|
21684
|
+
VoteProgram.space = 3762;
|
|
21685
|
+
var VALIDATOR_INFO_KEY = new PublicKey("Va1idator1nfo111111111111111111111111111111");
|
|
21686
|
+
var InfoString = type({
|
|
21687
|
+
name: string(),
|
|
21688
|
+
website: optional(string()),
|
|
21689
|
+
details: optional(string()),
|
|
21690
|
+
iconUrl: optional(string()),
|
|
21691
|
+
keybaseUsername: optional(string())
|
|
21692
|
+
});
|
|
21693
|
+
var VOTE_PROGRAM_ID = new PublicKey("Vote111111111111111111111111111111111111111");
|
|
21694
|
+
var VoteAccountLayout = BufferLayout.struct([
|
|
21695
|
+
publicKey("nodePubkey"),
|
|
21696
|
+
publicKey("authorizedWithdrawer"),
|
|
21697
|
+
BufferLayout.u8("commission"),
|
|
21698
|
+
BufferLayout.nu64(),
|
|
21699
|
+
// votes.length
|
|
21700
|
+
BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64("slot"), BufferLayout.u32("confirmationCount")]), BufferLayout.offset(BufferLayout.u32(), -8), "votes"),
|
|
21701
|
+
BufferLayout.u8("rootSlotValid"),
|
|
21702
|
+
BufferLayout.nu64("rootSlot"),
|
|
21703
|
+
BufferLayout.nu64(),
|
|
21704
|
+
// authorizedVoters.length
|
|
21705
|
+
BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64("epoch"), publicKey("authorizedVoter")]), BufferLayout.offset(BufferLayout.u32(), -8), "authorizedVoters"),
|
|
21706
|
+
BufferLayout.struct([BufferLayout.seq(BufferLayout.struct([publicKey("authorizedPubkey"), BufferLayout.nu64("epochOfLastAuthorizedSwitch"), BufferLayout.nu64("targetEpoch")]), 32, "buf"), BufferLayout.nu64("idx"), BufferLayout.u8("isEmpty")], "priorVoters"),
|
|
21707
|
+
BufferLayout.nu64(),
|
|
21708
|
+
// epochCredits.length
|
|
21709
|
+
BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64("epoch"), BufferLayout.nu64("credits"), BufferLayout.nu64("prevCredits")]), BufferLayout.offset(BufferLayout.u32(), -8), "epochCredits"),
|
|
21710
|
+
BufferLayout.struct([BufferLayout.nu64("slot"), BufferLayout.nu64("timestamp")], "lastTimestamp")
|
|
21711
|
+
]);
|
|
21712
|
+
|
|
21713
|
+
// src/http-client.ts
|
|
21714
|
+
var HttpClient = class {
|
|
21715
|
+
constructor(baseUrl, storage, logger2, appId, autoPayConfig) {
|
|
21716
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
21717
|
+
this.storage = storage;
|
|
21718
|
+
this.logger = logger2 || logger;
|
|
21719
|
+
this.appId = appId;
|
|
21720
|
+
this.autoPayConfig = {
|
|
21721
|
+
enabled: autoPayConfig?.enabled ?? false,
|
|
21722
|
+
maxAmountMinor: autoPayConfig?.maxAmountMinor ?? 1e5,
|
|
21723
|
+
maxRetries: autoPayConfig?.maxRetries ?? 1
|
|
21724
|
+
};
|
|
21725
|
+
}
|
|
21726
|
+
setAutoPayHandlers(input) {
|
|
21727
|
+
this.signerAddressProvider = input.signerAddressProvider;
|
|
21728
|
+
this.signTransactionHandler = input.signTransactionHandler;
|
|
21729
|
+
}
|
|
21730
|
+
async request(endpoint, options = {}) {
|
|
21731
|
+
return this.requestInternal(endpoint, options, 0);
|
|
21732
|
+
}
|
|
21733
|
+
async requestInternal(endpoint, options, attempt) {
|
|
21734
|
+
const url2 = `${this.baseUrl}${endpoint}`;
|
|
21735
|
+
const token = this.storage.get(TOKEN_KEY);
|
|
21736
|
+
this.logger.debug("HTTP request", {
|
|
21737
|
+
method: options.method || "GET",
|
|
21738
|
+
endpoint,
|
|
21739
|
+
url: url2,
|
|
21740
|
+
hasToken: !!token
|
|
21741
|
+
});
|
|
21742
|
+
const headers = {
|
|
21743
|
+
"Content-Type": "application/json",
|
|
21744
|
+
"X-SDK-Version": SDK_VERSION,
|
|
21745
|
+
...options.headers
|
|
21746
|
+
};
|
|
21747
|
+
if (this.appId) {
|
|
21748
|
+
headers["X-App-Id"] = this.appId;
|
|
21749
|
+
if (this.appId === "dim-agents") {
|
|
21750
|
+
headers["X-Dim-Agent"] = "1";
|
|
21751
|
+
}
|
|
21752
|
+
}
|
|
21753
|
+
if (token) {
|
|
21754
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
21755
|
+
}
|
|
21756
|
+
const response = await fetch(url2, {
|
|
21757
|
+
...options,
|
|
21758
|
+
headers
|
|
21759
|
+
});
|
|
21760
|
+
this.logger.debug("HTTP response", {
|
|
21761
|
+
method: options.method || "GET",
|
|
21762
|
+
endpoint,
|
|
21763
|
+
status: response.status,
|
|
21764
|
+
ok: response.ok
|
|
21765
|
+
});
|
|
21766
|
+
if (!response.ok) {
|
|
21767
|
+
if (response.status === 402 && this.autoPayConfig.enabled && !endpoint.startsWith("/payments/") && attempt < this.autoPayConfig.maxRetries) {
|
|
21768
|
+
const challenge = await this.extractPaymentChallenge(response);
|
|
21769
|
+
if (challenge && this.canAutoPayChallenge(challenge)) {
|
|
21770
|
+
const paymentProof = await this.payChallenge(challenge);
|
|
21771
|
+
const retryHeaders = {
|
|
21772
|
+
...options.headers,
|
|
21773
|
+
"PAYMENT-SIGNATURE": paymentProof
|
|
21774
|
+
};
|
|
21775
|
+
return this.requestInternal(
|
|
21776
|
+
endpoint,
|
|
21777
|
+
{ ...options, headers: retryHeaders },
|
|
21778
|
+
attempt + 1
|
|
21779
|
+
);
|
|
21780
|
+
}
|
|
21781
|
+
}
|
|
21782
|
+
if (response.status === 426) {
|
|
21783
|
+
let upgradeMessage = "SDK version outdated. Run: npm install @dimcool/sdk@latest";
|
|
21784
|
+
try {
|
|
21785
|
+
const errorData = await response.json();
|
|
21786
|
+
if (typeof errorData.message === "string") {
|
|
21787
|
+
upgradeMessage = errorData.message;
|
|
21788
|
+
}
|
|
21789
|
+
} catch {
|
|
21790
|
+
}
|
|
21791
|
+
this.logger.error("SDK upgrade required", {
|
|
21792
|
+
endpoint,
|
|
21793
|
+
sdkVersion: SDK_VERSION,
|
|
21794
|
+
message: upgradeMessage
|
|
21795
|
+
});
|
|
21796
|
+
const error2 = new Error(upgradeMessage);
|
|
21797
|
+
error2.code = "SDK_UPGRADE_REQUIRED";
|
|
21798
|
+
error2.statusCode = 426;
|
|
21799
|
+
throw error2;
|
|
21800
|
+
}
|
|
21801
|
+
if (response.status === 401) {
|
|
21802
|
+
this.logger.warn("Unauthorized response, clearing token", { endpoint });
|
|
21803
|
+
this.storage.delete(TOKEN_KEY);
|
|
21804
|
+
throw new Error("Unauthorized - please login again");
|
|
21805
|
+
}
|
|
21806
|
+
let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
|
|
21807
|
+
let errorCode;
|
|
21808
|
+
try {
|
|
21809
|
+
const errorData = await response.json();
|
|
21810
|
+
errorCode = errorData.code;
|
|
21811
|
+
if (typeof errorData.message === "string" && errorData.message.trim()) {
|
|
21812
|
+
errorMessage = errorData.message;
|
|
21813
|
+
} else if (Array.isArray(errorData.message) && errorData.message.length) {
|
|
21814
|
+
errorMessage = errorData.message.join(", ");
|
|
21815
|
+
} else if (typeof errorData.error === "string" && errorData.error.trim()) {
|
|
21816
|
+
errorMessage = errorData.error;
|
|
21817
|
+
}
|
|
21818
|
+
} catch {
|
|
21819
|
+
}
|
|
21820
|
+
this.logger.error("HTTP request failed", {
|
|
21821
|
+
endpoint,
|
|
21822
|
+
status: response.status,
|
|
21823
|
+
error: errorMessage,
|
|
21824
|
+
code: errorCode
|
|
21875
21825
|
});
|
|
21826
|
+
const error = new Error(errorMessage);
|
|
21827
|
+
error.code = errorCode;
|
|
21828
|
+
error.statusCode = response.status;
|
|
21829
|
+
throw error;
|
|
21876
21830
|
}
|
|
21877
|
-
|
|
21878
|
-
|
|
21879
|
-
|
|
21880
|
-
data
|
|
21831
|
+
const contentType = response.headers.get("content-type");
|
|
21832
|
+
if (contentType && contentType.includes("application/json")) {
|
|
21833
|
+
const data = await response.json();
|
|
21834
|
+
this.logger.debug("HTTP response parsed", { endpoint, hasData: !!data });
|
|
21835
|
+
return data;
|
|
21836
|
+
}
|
|
21837
|
+
this.logger.debug("HTTP response empty", { endpoint });
|
|
21838
|
+
return {};
|
|
21839
|
+
}
|
|
21840
|
+
get(endpoint, options) {
|
|
21841
|
+
return this.request(endpoint, { ...options, method: "GET" });
|
|
21842
|
+
}
|
|
21843
|
+
post(endpoint, data, options) {
|
|
21844
|
+
return this.request(endpoint, {
|
|
21845
|
+
...options,
|
|
21846
|
+
method: "POST",
|
|
21847
|
+
body: data ? JSON.stringify(data) : void 0
|
|
21881
21848
|
});
|
|
21882
21849
|
}
|
|
21883
|
-
|
|
21884
|
-
|
|
21885
|
-
|
|
21886
|
-
|
|
21887
|
-
|
|
21888
|
-
stakePubkey,
|
|
21889
|
-
authorizedPubkey,
|
|
21890
|
-
splitStakePubkey,
|
|
21891
|
-
lamports
|
|
21892
|
-
} = params;
|
|
21893
|
-
const type2 = STAKE_INSTRUCTION_LAYOUTS.Split;
|
|
21894
|
-
const data = encodeData(type2, {
|
|
21895
|
-
lamports
|
|
21850
|
+
patch(endpoint, data, options) {
|
|
21851
|
+
return this.request(endpoint, {
|
|
21852
|
+
...options,
|
|
21853
|
+
method: "PATCH",
|
|
21854
|
+
body: data ? JSON.stringify(data) : void 0
|
|
21896
21855
|
});
|
|
21897
|
-
|
|
21898
|
-
|
|
21899
|
-
|
|
21900
|
-
|
|
21901
|
-
|
|
21902
|
-
|
|
21903
|
-
|
|
21904
|
-
|
|
21905
|
-
|
|
21906
|
-
|
|
21907
|
-
|
|
21908
|
-
|
|
21909
|
-
|
|
21910
|
-
|
|
21911
|
-
|
|
21912
|
-
|
|
21856
|
+
}
|
|
21857
|
+
delete(endpoint, options) {
|
|
21858
|
+
return this.request(endpoint, { ...options, method: "DELETE" });
|
|
21859
|
+
}
|
|
21860
|
+
async upload(endpoint, formData) {
|
|
21861
|
+
const url2 = `${this.baseUrl}${endpoint}`;
|
|
21862
|
+
const token = this.storage.get(TOKEN_KEY);
|
|
21863
|
+
this.logger.debug("HTTP upload request", {
|
|
21864
|
+
method: "POST",
|
|
21865
|
+
endpoint,
|
|
21866
|
+
url: url2,
|
|
21867
|
+
hasToken: !!token
|
|
21868
|
+
});
|
|
21869
|
+
const headers = {
|
|
21870
|
+
"X-SDK-Version": SDK_VERSION
|
|
21871
|
+
};
|
|
21872
|
+
if (this.appId) {
|
|
21873
|
+
headers["X-App-Id"] = this.appId;
|
|
21874
|
+
}
|
|
21875
|
+
if (token) {
|
|
21876
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
21877
|
+
}
|
|
21878
|
+
const response = await fetch(url2, {
|
|
21879
|
+
method: "POST",
|
|
21880
|
+
headers,
|
|
21881
|
+
body: formData
|
|
21882
|
+
});
|
|
21883
|
+
this.logger.debug("HTTP upload response", {
|
|
21884
|
+
method: "POST",
|
|
21885
|
+
endpoint,
|
|
21886
|
+
status: response.status,
|
|
21887
|
+
ok: response.ok
|
|
21913
21888
|
});
|
|
21889
|
+
if (!response.ok) {
|
|
21890
|
+
if (response.status === 426) {
|
|
21891
|
+
let upgradeMessage = "SDK version outdated. Run: npm install @dimcool/sdk@latest";
|
|
21892
|
+
try {
|
|
21893
|
+
const errorData = await response.json();
|
|
21894
|
+
if (typeof errorData.message === "string") {
|
|
21895
|
+
upgradeMessage = errorData.message;
|
|
21896
|
+
}
|
|
21897
|
+
} catch {
|
|
21898
|
+
}
|
|
21899
|
+
this.logger.error("SDK upgrade required", {
|
|
21900
|
+
endpoint,
|
|
21901
|
+
sdkVersion: SDK_VERSION,
|
|
21902
|
+
message: upgradeMessage
|
|
21903
|
+
});
|
|
21904
|
+
const error = new Error(upgradeMessage);
|
|
21905
|
+
error.code = "SDK_UPGRADE_REQUIRED";
|
|
21906
|
+
error.statusCode = 426;
|
|
21907
|
+
throw error;
|
|
21908
|
+
}
|
|
21909
|
+
if (response.status === 401) {
|
|
21910
|
+
this.logger.warn("Unauthorized response, clearing token", { endpoint });
|
|
21911
|
+
this.storage.delete(TOKEN_KEY);
|
|
21912
|
+
throw new Error("Unauthorized - please login again");
|
|
21913
|
+
}
|
|
21914
|
+
let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
|
|
21915
|
+
try {
|
|
21916
|
+
const errorData = await response.json();
|
|
21917
|
+
errorMessage = errorData.error || errorMessage;
|
|
21918
|
+
} catch {
|
|
21919
|
+
}
|
|
21920
|
+
this.logger.error("HTTP upload failed", {
|
|
21921
|
+
endpoint,
|
|
21922
|
+
status: response.status,
|
|
21923
|
+
error: errorMessage
|
|
21924
|
+
});
|
|
21925
|
+
throw new Error(errorMessage);
|
|
21926
|
+
}
|
|
21927
|
+
const contentType = response.headers.get("content-type");
|
|
21928
|
+
if (contentType && contentType.includes("application/json")) {
|
|
21929
|
+
const data = await response.json();
|
|
21930
|
+
this.logger.debug("HTTP upload response parsed", {
|
|
21931
|
+
endpoint,
|
|
21932
|
+
hasData: !!data
|
|
21933
|
+
});
|
|
21934
|
+
return data;
|
|
21935
|
+
}
|
|
21936
|
+
this.logger.debug("HTTP upload response empty", { endpoint });
|
|
21937
|
+
return {};
|
|
21914
21938
|
}
|
|
21915
|
-
|
|
21916
|
-
|
|
21917
|
-
|
|
21918
|
-
|
|
21919
|
-
|
|
21920
|
-
|
|
21921
|
-
|
|
21922
|
-
|
|
21923
|
-
|
|
21924
|
-
|
|
21925
|
-
|
|
21926
|
-
|
|
21927
|
-
|
|
21939
|
+
async extractPaymentChallenge(response) {
|
|
21940
|
+
const encoded = response.headers.get("payment-required");
|
|
21941
|
+
if (encoded) {
|
|
21942
|
+
try {
|
|
21943
|
+
const decodedText = typeof Buffer !== "undefined" ? Buffer.from(encoded, "base64").toString("utf-8") : atob(encoded);
|
|
21944
|
+
const decoded = JSON.parse(decodedText);
|
|
21945
|
+
return decoded;
|
|
21946
|
+
} catch {
|
|
21947
|
+
}
|
|
21948
|
+
}
|
|
21949
|
+
try {
|
|
21950
|
+
const body = await response.json();
|
|
21951
|
+
return body.paymentRequired || null;
|
|
21952
|
+
} catch {
|
|
21953
|
+
return null;
|
|
21954
|
+
}
|
|
21928
21955
|
}
|
|
21929
|
-
|
|
21930
|
-
|
|
21931
|
-
|
|
21932
|
-
|
|
21933
|
-
|
|
21934
|
-
|
|
21935
|
-
|
|
21936
|
-
|
|
21937
|
-
|
|
21938
|
-
|
|
21939
|
-
|
|
21940
|
-
|
|
21941
|
-
}
|
|
21942
|
-
const
|
|
21943
|
-
|
|
21944
|
-
|
|
21945
|
-
|
|
21946
|
-
|
|
21947
|
-
|
|
21948
|
-
|
|
21949
|
-
|
|
21950
|
-
|
|
21951
|
-
|
|
21952
|
-
|
|
21953
|
-
|
|
21954
|
-
|
|
21955
|
-
|
|
21956
|
+
canAutoPayChallenge(challenge) {
|
|
21957
|
+
if (!this.signerAddressProvider || !this.signTransactionHandler) {
|
|
21958
|
+
return false;
|
|
21959
|
+
}
|
|
21960
|
+
if (challenge.amountMinor > this.autoPayConfig.maxAmountMinor) {
|
|
21961
|
+
return false;
|
|
21962
|
+
}
|
|
21963
|
+
return true;
|
|
21964
|
+
}
|
|
21965
|
+
async payChallenge(challenge) {
|
|
21966
|
+
if (!this.signerAddressProvider || !this.signTransactionHandler) {
|
|
21967
|
+
throw new Error("Auto-pay signer is not configured.");
|
|
21968
|
+
}
|
|
21969
|
+
const payerAddress = this.signerAddressProvider();
|
|
21970
|
+
if (!payerAddress) {
|
|
21971
|
+
throw new Error("Wallet signer address is required for auto-payment.");
|
|
21972
|
+
}
|
|
21973
|
+
const prepare = await this.post(
|
|
21974
|
+
"/payments/prepare",
|
|
21975
|
+
{
|
|
21976
|
+
paymentIntentId: challenge.paymentIntentId,
|
|
21977
|
+
payerAddress
|
|
21978
|
+
},
|
|
21979
|
+
{
|
|
21980
|
+
headers: {
|
|
21981
|
+
"X-Auto-Pay": "1"
|
|
21982
|
+
}
|
|
21983
|
+
}
|
|
21984
|
+
);
|
|
21985
|
+
const unsignedTx = Transaction.from(
|
|
21986
|
+
Buffer.from(prepare.transaction, "base64")
|
|
21987
|
+
);
|
|
21988
|
+
const signedTx = await this.signTransactionHandler(unsignedTx);
|
|
21989
|
+
const signedTransaction = signedTx.serialize({ requireAllSignatures: false }).toString("base64");
|
|
21990
|
+
const submitted = await this.post(
|
|
21991
|
+
"/payments/submit",
|
|
21992
|
+
{
|
|
21993
|
+
paymentIntentId: challenge.paymentIntentId,
|
|
21994
|
+
signedTransaction
|
|
21995
|
+
}
|
|
21996
|
+
);
|
|
21997
|
+
if (!submitted.paymentProof) {
|
|
21998
|
+
throw new Error("Payment proof missing from /payments/submit response.");
|
|
21999
|
+
}
|
|
22000
|
+
return submitted.paymentProof;
|
|
22001
|
+
}
|
|
22002
|
+
};
|
|
22003
|
+
|
|
22004
|
+
// src/auth.ts
|
|
22005
|
+
function toBase64(bytes) {
|
|
22006
|
+
if (typeof Buffer !== "undefined") {
|
|
22007
|
+
return Buffer.from(bytes).toString("base64");
|
|
22008
|
+
}
|
|
22009
|
+
let binary = "";
|
|
22010
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
22011
|
+
binary += String.fromCharCode(bytes[i]);
|
|
22012
|
+
}
|
|
22013
|
+
if (typeof btoa === "undefined") {
|
|
22014
|
+
throw new Error("Base64 encoding is not available in this environment");
|
|
22015
|
+
}
|
|
22016
|
+
return btoa(binary);
|
|
22017
|
+
}
|
|
22018
|
+
var Auth = class {
|
|
22019
|
+
constructor(http2, storage, wallet, logger2) {
|
|
22020
|
+
this.http = http2;
|
|
22021
|
+
this.storage = storage;
|
|
22022
|
+
this.wallet = wallet;
|
|
22023
|
+
this.logger = logger2 || logger;
|
|
22024
|
+
}
|
|
22025
|
+
async login(email, password) {
|
|
22026
|
+
this.logger.debug("Auth.login called", { email });
|
|
22027
|
+
const response = await this.http.post("/auth/login", {
|
|
22028
|
+
email,
|
|
22029
|
+
password
|
|
22030
|
+
});
|
|
22031
|
+
this.logger.debug("Login response received", {
|
|
22032
|
+
userId: response.user.id,
|
|
22033
|
+
hasToken: !!response.access_token,
|
|
22034
|
+
tokenLength: response.access_token?.length
|
|
22035
|
+
});
|
|
22036
|
+
if (!response.access_token) {
|
|
22037
|
+
throw new Error("Login response missing access_token");
|
|
21956
22038
|
}
|
|
21957
|
-
|
|
21958
|
-
|
|
21959
|
-
|
|
21960
|
-
|
|
21961
|
-
|
|
21962
|
-
|
|
21963
|
-
|
|
21964
|
-
|
|
21965
|
-
|
|
21966
|
-
|
|
21967
|
-
|
|
21968
|
-
|
|
21969
|
-
stakePubkey,
|
|
21970
|
-
sourceStakePubKey,
|
|
21971
|
-
authorizedPubkey
|
|
21972
|
-
} = params;
|
|
21973
|
-
const type2 = STAKE_INSTRUCTION_LAYOUTS.Merge;
|
|
21974
|
-
const data = encodeData(type2);
|
|
21975
|
-
return new Transaction().add({
|
|
21976
|
-
keys: [{
|
|
21977
|
-
pubkey: stakePubkey,
|
|
21978
|
-
isSigner: false,
|
|
21979
|
-
isWritable: true
|
|
21980
|
-
}, {
|
|
21981
|
-
pubkey: sourceStakePubKey,
|
|
21982
|
-
isSigner: false,
|
|
21983
|
-
isWritable: true
|
|
21984
|
-
}, {
|
|
21985
|
-
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
21986
|
-
isSigner: false,
|
|
21987
|
-
isWritable: false
|
|
21988
|
-
}, {
|
|
21989
|
-
pubkey: SYSVAR_STAKE_HISTORY_PUBKEY,
|
|
21990
|
-
isSigner: false,
|
|
21991
|
-
isWritable: false
|
|
21992
|
-
}, {
|
|
21993
|
-
pubkey: authorizedPubkey,
|
|
21994
|
-
isSigner: true,
|
|
21995
|
-
isWritable: false
|
|
21996
|
-
}],
|
|
21997
|
-
programId: this.programId,
|
|
21998
|
-
data
|
|
22039
|
+
this.storage.set(TOKEN_KEY, response.access_token);
|
|
22040
|
+
const storedToken = this.storage.get(TOKEN_KEY);
|
|
22041
|
+
if (!storedToken || storedToken !== response.access_token) {
|
|
22042
|
+
throw new Error(
|
|
22043
|
+
`Token storage failed! Expected: ${response.access_token.substring(0, 20)}..., Got: ${storedToken?.substring(0, 20)}...`
|
|
22044
|
+
);
|
|
22045
|
+
}
|
|
22046
|
+
this.logger.debug("Token stored in storage", {
|
|
22047
|
+
tokenKey: TOKEN_KEY,
|
|
22048
|
+
stored: !!storedToken,
|
|
22049
|
+
storedTokenLength: storedToken?.length,
|
|
22050
|
+
storageType: this.storage.constructor.name
|
|
21999
22051
|
});
|
|
22052
|
+
return response;
|
|
22000
22053
|
}
|
|
22001
|
-
|
|
22002
|
-
|
|
22003
|
-
|
|
22004
|
-
|
|
22005
|
-
|
|
22006
|
-
|
|
22007
|
-
|
|
22008
|
-
|
|
22009
|
-
|
|
22010
|
-
|
|
22011
|
-
|
|
22012
|
-
const type2 = STAKE_INSTRUCTION_LAYOUTS.Withdraw;
|
|
22013
|
-
const data = encodeData(type2, {
|
|
22014
|
-
lamports
|
|
22054
|
+
async generateHandshake(walletAddress) {
|
|
22055
|
+
this.logger.debug("Auth.generateHandshake called", { walletAddress });
|
|
22056
|
+
const response = await this.http.post(
|
|
22057
|
+
"/auth/handshake",
|
|
22058
|
+
{
|
|
22059
|
+
walletAddress
|
|
22060
|
+
}
|
|
22061
|
+
);
|
|
22062
|
+
this.logger.debug("Handshake generated", {
|
|
22063
|
+
hasMessage: !!response.message,
|
|
22064
|
+
hasNonce: !!response.nonce
|
|
22015
22065
|
});
|
|
22016
|
-
|
|
22017
|
-
|
|
22018
|
-
|
|
22019
|
-
|
|
22020
|
-
|
|
22021
|
-
|
|
22022
|
-
|
|
22023
|
-
|
|
22024
|
-
}, {
|
|
22025
|
-
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
22026
|
-
isSigner: false,
|
|
22027
|
-
isWritable: false
|
|
22028
|
-
}, {
|
|
22029
|
-
pubkey: SYSVAR_STAKE_HISTORY_PUBKEY,
|
|
22030
|
-
isSigner: false,
|
|
22031
|
-
isWritable: false
|
|
22032
|
-
}, {
|
|
22033
|
-
pubkey: authorizedPubkey,
|
|
22034
|
-
isSigner: true,
|
|
22035
|
-
isWritable: false
|
|
22036
|
-
}];
|
|
22037
|
-
if (custodianPubkey) {
|
|
22038
|
-
keys.push({
|
|
22039
|
-
pubkey: custodianPubkey,
|
|
22040
|
-
isSigner: true,
|
|
22041
|
-
isWritable: false
|
|
22042
|
-
});
|
|
22066
|
+
return response;
|
|
22067
|
+
}
|
|
22068
|
+
async loginWithWallet(options) {
|
|
22069
|
+
const address = this.wallet.getSignerAddress();
|
|
22070
|
+
if (!address) {
|
|
22071
|
+
throw new Error(
|
|
22072
|
+
"Wallet signer address is required for wallet login. Set sdk.wallet.setSigner({ address, signMessage, signTransaction })."
|
|
22073
|
+
);
|
|
22043
22074
|
}
|
|
22044
|
-
|
|
22045
|
-
|
|
22046
|
-
|
|
22047
|
-
|
|
22075
|
+
if (!this.wallet.hasSigner()) {
|
|
22076
|
+
throw new Error(
|
|
22077
|
+
"No signer configured. Call sdk.wallet.setSigner(...) before wallet login."
|
|
22078
|
+
);
|
|
22079
|
+
}
|
|
22080
|
+
const { message } = await this.generateHandshake(address);
|
|
22081
|
+
const signatureResult = await this.wallet.signMessage(message);
|
|
22082
|
+
const signedMessage = typeof signatureResult === "string" ? signatureResult : toBase64(signatureResult);
|
|
22083
|
+
this.logger.debug("Auth.loginWithWallet called", {
|
|
22084
|
+
address,
|
|
22085
|
+
walletMeta: options?.walletMeta
|
|
22086
|
+
});
|
|
22087
|
+
const response = await this.http.post("/auth/login-wallet", {
|
|
22088
|
+
signedMessage,
|
|
22089
|
+
address,
|
|
22090
|
+
referralCode: options?.referralCode,
|
|
22091
|
+
walletMeta: options?.walletMeta
|
|
22092
|
+
});
|
|
22093
|
+
this.logger.debug("Wallet login response received", {
|
|
22094
|
+
userId: response.user.id,
|
|
22095
|
+
hasToken: !!response.access_token
|
|
22048
22096
|
});
|
|
22097
|
+
this.storage.set(TOKEN_KEY, response.access_token);
|
|
22098
|
+
this.logger.debug("Token stored in storage", { tokenKey: TOKEN_KEY });
|
|
22099
|
+
return response;
|
|
22049
22100
|
}
|
|
22050
|
-
|
|
22051
|
-
|
|
22052
|
-
|
|
22053
|
-
|
|
22054
|
-
|
|
22055
|
-
|
|
22056
|
-
|
|
22057
|
-
|
|
22058
|
-
|
|
22059
|
-
|
|
22060
|
-
|
|
22061
|
-
|
|
22062
|
-
|
|
22063
|
-
|
|
22064
|
-
|
|
22065
|
-
|
|
22066
|
-
|
|
22067
|
-
|
|
22068
|
-
|
|
22069
|
-
|
|
22070
|
-
|
|
22071
|
-
|
|
22072
|
-
|
|
22073
|
-
|
|
22074
|
-
|
|
22075
|
-
|
|
22101
|
+
logout() {
|
|
22102
|
+
this.logger.debug("Auth.logout called");
|
|
22103
|
+
const hadToken = this.storage.get(TOKEN_KEY) !== null;
|
|
22104
|
+
this.storage.delete(TOKEN_KEY);
|
|
22105
|
+
this.logger.debug("Token removed from storage", { hadToken });
|
|
22106
|
+
}
|
|
22107
|
+
isAuthenticated() {
|
|
22108
|
+
const isAuth = this.storage.get(TOKEN_KEY) !== null;
|
|
22109
|
+
this.logger.debug("Auth.isAuthenticated called", {
|
|
22110
|
+
isAuthenticated: isAuth
|
|
22111
|
+
});
|
|
22112
|
+
return isAuth;
|
|
22113
|
+
}
|
|
22114
|
+
async getLatestSessions(limit) {
|
|
22115
|
+
this.logger.debug("Auth.getLatestSessions called", { limit });
|
|
22116
|
+
const params = new URLSearchParams();
|
|
22117
|
+
if (limit !== void 0) {
|
|
22118
|
+
params.append("limit", limit.toString());
|
|
22119
|
+
}
|
|
22120
|
+
const queryString = params.toString();
|
|
22121
|
+
const endpoint = queryString ? `/auth/sessions?${queryString}` : "/auth/sessions";
|
|
22122
|
+
const response = await this.http.get(endpoint);
|
|
22123
|
+
this.logger.debug("Latest sessions retrieved", { total: response.total });
|
|
22124
|
+
return response;
|
|
22125
|
+
}
|
|
22126
|
+
};
|
|
22127
|
+
|
|
22128
|
+
// src/admin.ts
|
|
22129
|
+
var Admin = class {
|
|
22130
|
+
constructor(http2, logger2) {
|
|
22131
|
+
this.http = http2;
|
|
22132
|
+
this.logger = logger2;
|
|
22133
|
+
}
|
|
22134
|
+
async getUserById(id) {
|
|
22135
|
+
return this.http.get(`/admin/users/${id}`);
|
|
22136
|
+
}
|
|
22137
|
+
async getStats() {
|
|
22138
|
+
return this.http.get("/admin/stats");
|
|
22139
|
+
}
|
|
22140
|
+
// Backward-compatible alias used in some consumers.
|
|
22141
|
+
async getAdminStats() {
|
|
22142
|
+
return this.getStats();
|
|
22143
|
+
}
|
|
22144
|
+
async getDailyStats(days) {
|
|
22145
|
+
const params = new URLSearchParams();
|
|
22146
|
+
if (days != null) params.append("days", String(days));
|
|
22147
|
+
const queryString = params.toString();
|
|
22148
|
+
const endpoint = queryString ? `/admin/stats/daily?${queryString}` : "/admin/stats/daily";
|
|
22149
|
+
return this.http.get(endpoint);
|
|
22150
|
+
}
|
|
22151
|
+
// Backward-compatible alias used in some consumers.
|
|
22152
|
+
async getAdminDailyStats(days) {
|
|
22153
|
+
return this.getDailyStats(days);
|
|
22154
|
+
}
|
|
22155
|
+
async getEscrowSweepPreview() {
|
|
22156
|
+
return this.http.post("/admin/escrow/sweep-preview");
|
|
22157
|
+
}
|
|
22158
|
+
async getEscrowSweeps(limit = 20) {
|
|
22159
|
+
return this.http.get(
|
|
22160
|
+
`/admin/escrow/sweeps?limit=${limit}`
|
|
22161
|
+
);
|
|
22162
|
+
}
|
|
22163
|
+
async executeEscrowSweep(amountUsdcMinor, idempotencyKey) {
|
|
22164
|
+
return this.http.post("/admin/escrow/sweep", {
|
|
22165
|
+
amountUsdcMinor,
|
|
22166
|
+
idempotencyKey
|
|
22076
22167
|
});
|
|
22077
22168
|
}
|
|
22169
|
+
async banUser(userId, reason) {
|
|
22170
|
+
return this.http.post(`/admin/users/${userId}/ban`, { reason });
|
|
22171
|
+
}
|
|
22172
|
+
async unbanUser(userId) {
|
|
22173
|
+
return this.http.post(`/admin/users/${userId}/unban`, {});
|
|
22174
|
+
}
|
|
22175
|
+
async getCriticalIncidentSummary(hours = 24) {
|
|
22176
|
+
return this.http.get(
|
|
22177
|
+
`/admin/critical-incidents/summary?hours=${hours}`
|
|
22178
|
+
);
|
|
22179
|
+
}
|
|
22180
|
+
async getCriticalIncidents(input) {
|
|
22181
|
+
const params = new URLSearchParams();
|
|
22182
|
+
if (input.page != null) params.append("page", String(input.page));
|
|
22183
|
+
if (input.limit != null) params.append("limit", String(input.limit));
|
|
22184
|
+
if (input.status) params.append("status", input.status);
|
|
22185
|
+
if (input.severity) params.append("severity", input.severity);
|
|
22186
|
+
if (input.category) params.append("category", input.category);
|
|
22187
|
+
const query = params.toString();
|
|
22188
|
+
return this.http.get(
|
|
22189
|
+
`/admin/critical-incidents${query ? `?${query}` : ""}`
|
|
22190
|
+
);
|
|
22191
|
+
}
|
|
22192
|
+
async resolveCriticalIncident(id, resolutionNote) {
|
|
22193
|
+
return this.http.patch(
|
|
22194
|
+
`/admin/critical-incidents/${id}/resolve`,
|
|
22195
|
+
{ resolutionNote }
|
|
22196
|
+
);
|
|
22197
|
+
}
|
|
22198
|
+
async getPlatformFees(input) {
|
|
22199
|
+
const params = new URLSearchParams();
|
|
22200
|
+
if (input?.page != null) params.append("page", String(input.page));
|
|
22201
|
+
if (input?.limit != null) params.append("limit", String(input.limit));
|
|
22202
|
+
if (input?.from) params.append("from", input.from);
|
|
22203
|
+
if (input?.to) params.append("to", input.to);
|
|
22204
|
+
if (input?.purpose) params.append("purpose", input.purpose);
|
|
22205
|
+
if (input?.appId) params.append("appId", input.appId);
|
|
22206
|
+
if (input?.payerUserId) params.append("payerUserId", input.payerUserId);
|
|
22207
|
+
if (input?.payerAddress) params.append("payerAddress", input.payerAddress);
|
|
22208
|
+
if (input?.minAmount != null)
|
|
22209
|
+
params.append("minAmount", String(input.minAmount));
|
|
22210
|
+
if (input?.maxAmount != null)
|
|
22211
|
+
params.append("maxAmount", String(input.maxAmount));
|
|
22212
|
+
const query = params.toString();
|
|
22213
|
+
return this.http.get(
|
|
22214
|
+
`/admin/platform-fees${query ? `?${query}` : ""}`
|
|
22215
|
+
);
|
|
22216
|
+
}
|
|
22078
22217
|
};
|
|
22079
|
-
|
|
22080
|
-
|
|
22081
|
-
var
|
|
22082
|
-
|
|
22083
|
-
|
|
22084
|
-
|
|
22085
|
-
},
|
|
22086
|
-
Authorize: {
|
|
22087
|
-
index: 1,
|
|
22088
|
-
layout: BufferLayout.struct([BufferLayout.u32("instruction"), publicKey("newAuthorized"), BufferLayout.u32("voteAuthorizationType")])
|
|
22089
|
-
},
|
|
22090
|
-
Withdraw: {
|
|
22091
|
-
index: 3,
|
|
22092
|
-
layout: BufferLayout.struct([BufferLayout.u32("instruction"), BufferLayout.ns64("lamports")])
|
|
22093
|
-
},
|
|
22094
|
-
UpdateValidatorIdentity: {
|
|
22095
|
-
index: 4,
|
|
22096
|
-
layout: BufferLayout.struct([BufferLayout.u32("instruction")])
|
|
22097
|
-
},
|
|
22098
|
-
AuthorizeWithSeed: {
|
|
22099
|
-
index: 10,
|
|
22100
|
-
layout: BufferLayout.struct([BufferLayout.u32("instruction"), voteAuthorizeWithSeedArgs()])
|
|
22218
|
+
|
|
22219
|
+
// src/users.ts
|
|
22220
|
+
var Users = class {
|
|
22221
|
+
constructor(http2, logger2) {
|
|
22222
|
+
this.http = http2;
|
|
22223
|
+
this.logger = logger2;
|
|
22101
22224
|
}
|
|
22102
|
-
|
|
22103
|
-
|
|
22104
|
-
|
|
22105
|
-
|
|
22106
|
-
|
|
22107
|
-
|
|
22108
|
-
|
|
22225
|
+
async getUsers(page, limit, username, address) {
|
|
22226
|
+
const params = new URLSearchParams();
|
|
22227
|
+
if (page !== void 0) params.append("page", page.toString());
|
|
22228
|
+
if (limit !== void 0) params.append("limit", limit.toString());
|
|
22229
|
+
if (username !== void 0) params.append("username", username);
|
|
22230
|
+
if (address !== void 0) params.append("address", address);
|
|
22231
|
+
const queryString = params.toString();
|
|
22232
|
+
const endpoint = queryString ? `/users?${queryString}` : "/users";
|
|
22233
|
+
return this.http.get(endpoint);
|
|
22109
22234
|
}
|
|
22110
|
-
|
|
22111
|
-
|
|
22112
|
-
/**
|
|
22113
|
-
* @internal
|
|
22114
|
-
*/
|
|
22115
|
-
constructor() {
|
|
22235
|
+
async getUserById(id) {
|
|
22236
|
+
return this.http.get(`/users/${id}`);
|
|
22116
22237
|
}
|
|
22117
|
-
|
|
22118
|
-
|
|
22119
|
-
|
|
22120
|
-
|
|
22121
|
-
|
|
22122
|
-
|
|
22123
|
-
static initializeAccount(params) {
|
|
22124
|
-
const {
|
|
22125
|
-
votePubkey,
|
|
22126
|
-
nodePubkey,
|
|
22127
|
-
voteInit: voteInit2
|
|
22128
|
-
} = params;
|
|
22129
|
-
const type2 = VOTE_INSTRUCTION_LAYOUTS.InitializeAccount;
|
|
22130
|
-
const data = encodeData(type2, {
|
|
22131
|
-
voteInit: {
|
|
22132
|
-
nodePubkey: toBuffer(voteInit2.nodePubkey.toBuffer()),
|
|
22133
|
-
authorizedVoter: toBuffer(voteInit2.authorizedVoter.toBuffer()),
|
|
22134
|
-
authorizedWithdrawer: toBuffer(voteInit2.authorizedWithdrawer.toBuffer()),
|
|
22135
|
-
commission: voteInit2.commission
|
|
22136
|
-
}
|
|
22137
|
-
});
|
|
22138
|
-
const instructionData = {
|
|
22139
|
-
keys: [{
|
|
22140
|
-
pubkey: votePubkey,
|
|
22141
|
-
isSigner: false,
|
|
22142
|
-
isWritable: true
|
|
22143
|
-
}, {
|
|
22144
|
-
pubkey: SYSVAR_RENT_PUBKEY,
|
|
22145
|
-
isSigner: false,
|
|
22146
|
-
isWritable: false
|
|
22147
|
-
}, {
|
|
22148
|
-
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
22149
|
-
isSigner: false,
|
|
22150
|
-
isWritable: false
|
|
22151
|
-
}, {
|
|
22152
|
-
pubkey: nodePubkey,
|
|
22153
|
-
isSigner: true,
|
|
22154
|
-
isWritable: false
|
|
22155
|
-
}],
|
|
22156
|
-
programId: this.programId,
|
|
22157
|
-
data
|
|
22158
|
-
};
|
|
22159
|
-
return new TransactionInstruction(instructionData);
|
|
22238
|
+
async isUsernameAvailable(username) {
|
|
22239
|
+
const params = new URLSearchParams();
|
|
22240
|
+
params.append("username", username);
|
|
22241
|
+
return this.http.get(
|
|
22242
|
+
`/users/username/availability?${params.toString()}`
|
|
22243
|
+
);
|
|
22160
22244
|
}
|
|
22161
|
-
|
|
22162
|
-
|
|
22163
|
-
*/
|
|
22164
|
-
static createAccount(params) {
|
|
22165
|
-
const transaction = new Transaction();
|
|
22166
|
-
transaction.add(SystemProgram.createAccount({
|
|
22167
|
-
fromPubkey: params.fromPubkey,
|
|
22168
|
-
newAccountPubkey: params.votePubkey,
|
|
22169
|
-
lamports: params.lamports,
|
|
22170
|
-
space: this.space,
|
|
22171
|
-
programId: this.programId
|
|
22172
|
-
}));
|
|
22173
|
-
return transaction.add(this.initializeAccount({
|
|
22174
|
-
votePubkey: params.votePubkey,
|
|
22175
|
-
nodePubkey: params.voteInit.nodePubkey,
|
|
22176
|
-
voteInit: params.voteInit
|
|
22177
|
-
}));
|
|
22245
|
+
async updateUsername(username) {
|
|
22246
|
+
return this.http.patch("/users/me/username", { username });
|
|
22178
22247
|
}
|
|
22179
|
-
|
|
22180
|
-
|
|
22181
|
-
*/
|
|
22182
|
-
static authorize(params) {
|
|
22183
|
-
const {
|
|
22184
|
-
votePubkey,
|
|
22185
|
-
authorizedPubkey,
|
|
22186
|
-
newAuthorizedPubkey,
|
|
22187
|
-
voteAuthorizationType
|
|
22188
|
-
} = params;
|
|
22189
|
-
const type2 = VOTE_INSTRUCTION_LAYOUTS.Authorize;
|
|
22190
|
-
const data = encodeData(type2, {
|
|
22191
|
-
newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
|
|
22192
|
-
voteAuthorizationType: voteAuthorizationType.index
|
|
22193
|
-
});
|
|
22194
|
-
const keys = [{
|
|
22195
|
-
pubkey: votePubkey,
|
|
22196
|
-
isSigner: false,
|
|
22197
|
-
isWritable: true
|
|
22198
|
-
}, {
|
|
22199
|
-
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
22200
|
-
isSigner: false,
|
|
22201
|
-
isWritable: false
|
|
22202
|
-
}, {
|
|
22203
|
-
pubkey: authorizedPubkey,
|
|
22204
|
-
isSigner: true,
|
|
22205
|
-
isWritable: false
|
|
22206
|
-
}];
|
|
22207
|
-
return new Transaction().add({
|
|
22208
|
-
keys,
|
|
22209
|
-
programId: this.programId,
|
|
22210
|
-
data
|
|
22211
|
-
});
|
|
22248
|
+
async getPublicUserByUsername(username) {
|
|
22249
|
+
return this.http.get(`/users/username/${username}`);
|
|
22212
22250
|
}
|
|
22213
22251
|
/**
|
|
22214
|
-
*
|
|
22215
|
-
*
|
|
22252
|
+
* Get a public user profile by ID.
|
|
22253
|
+
* Returns PublicUser with optional spectatorCount.
|
|
22216
22254
|
*/
|
|
22217
|
-
|
|
22218
|
-
|
|
22219
|
-
|
|
22220
|
-
|
|
22221
|
-
|
|
22222
|
-
|
|
22223
|
-
|
|
22224
|
-
|
|
22225
|
-
|
|
22226
|
-
|
|
22227
|
-
|
|
22228
|
-
|
|
22229
|
-
|
|
22230
|
-
|
|
22231
|
-
|
|
22232
|
-
|
|
22233
|
-
|
|
22234
|
-
|
|
22235
|
-
const
|
|
22236
|
-
|
|
22237
|
-
|
|
22238
|
-
|
|
22239
|
-
}
|
|
22240
|
-
|
|
22241
|
-
|
|
22242
|
-
|
|
22243
|
-
|
|
22244
|
-
|
|
22245
|
-
|
|
22246
|
-
|
|
22247
|
-
|
|
22248
|
-
return
|
|
22249
|
-
|
|
22250
|
-
|
|
22251
|
-
|
|
22252
|
-
|
|
22255
|
+
async getPublicUserById(userId) {
|
|
22256
|
+
return this.http.get(`/users/${userId}`);
|
|
22257
|
+
}
|
|
22258
|
+
async searchUsers(username, page, limit) {
|
|
22259
|
+
const params = new URLSearchParams();
|
|
22260
|
+
params.append("username", username);
|
|
22261
|
+
if (page !== void 0) params.append("page", page.toString());
|
|
22262
|
+
if (limit !== void 0) params.append("limit", limit.toString());
|
|
22263
|
+
return this.http.get(
|
|
22264
|
+
`/users/search?${params.toString()}`
|
|
22265
|
+
);
|
|
22266
|
+
}
|
|
22267
|
+
async getFriends(userId, page, limit, search) {
|
|
22268
|
+
const params = new URLSearchParams();
|
|
22269
|
+
if (page !== void 0) params.append("page", page.toString());
|
|
22270
|
+
if (limit !== void 0) params.append("limit", limit.toString());
|
|
22271
|
+
if (search !== void 0) params.append("search", search);
|
|
22272
|
+
const queryString = params.toString();
|
|
22273
|
+
const endpoint = queryString ? `/friends/${userId}?${queryString}` : `/friends/${userId}`;
|
|
22274
|
+
return this.http.get(endpoint);
|
|
22275
|
+
}
|
|
22276
|
+
async addFriend(userId) {
|
|
22277
|
+
return this.http.post(`/friends/${userId}`, {});
|
|
22278
|
+
}
|
|
22279
|
+
async removeFriend(userId) {
|
|
22280
|
+
return this.http.delete(`/friends/${userId}`);
|
|
22281
|
+
}
|
|
22282
|
+
async getIncomingFriendRequests() {
|
|
22283
|
+
return this.http.get("/friends/requests/incoming");
|
|
22284
|
+
}
|
|
22285
|
+
async getOutgoingFriendRequests() {
|
|
22286
|
+
return this.http.get("/friends/requests/outgoing");
|
|
22287
|
+
}
|
|
22288
|
+
async acceptFriendRequest(userId) {
|
|
22289
|
+
return this.http.post(
|
|
22290
|
+
`/friends/requests/${userId}/accept`,
|
|
22291
|
+
{}
|
|
22292
|
+
);
|
|
22293
|
+
}
|
|
22294
|
+
async declineFriendRequest(userId) {
|
|
22295
|
+
return this.http.post(
|
|
22296
|
+
`/friends/requests/${userId}/decline`,
|
|
22297
|
+
{}
|
|
22298
|
+
);
|
|
22299
|
+
}
|
|
22300
|
+
async cancelFriendRequest(userId) {
|
|
22301
|
+
return this.http.delete(`/friends/requests/${userId}`);
|
|
22302
|
+
}
|
|
22303
|
+
async updateProfile(data) {
|
|
22304
|
+
return this.http.patch("/users/me/profile", data);
|
|
22305
|
+
}
|
|
22306
|
+
async uploadAvatar(file) {
|
|
22307
|
+
const formData = new FormData();
|
|
22308
|
+
formData.append("file", file);
|
|
22309
|
+
return this.http.upload("/users/me/profile/avatar", formData);
|
|
22310
|
+
}
|
|
22311
|
+
async uploadCoverImage(file) {
|
|
22312
|
+
const formData = new FormData();
|
|
22313
|
+
formData.append("file", file);
|
|
22314
|
+
return this.http.upload("/users/me/profile/cover", formData);
|
|
22315
|
+
}
|
|
22316
|
+
async removeAvatar() {
|
|
22317
|
+
return this.http.delete("/users/me/profile/avatar");
|
|
22318
|
+
}
|
|
22319
|
+
async removeCoverImage() {
|
|
22320
|
+
return this.http.delete("/users/me/profile/cover");
|
|
22321
|
+
}
|
|
22322
|
+
// Admin file management methods
|
|
22323
|
+
async getAllFiles() {
|
|
22324
|
+
return this.http.get("/files");
|
|
22325
|
+
}
|
|
22326
|
+
async deleteFile(fileId) {
|
|
22327
|
+
return this.http.delete(`/files/${fileId}`);
|
|
22328
|
+
}
|
|
22329
|
+
async getGameHistory(userId) {
|
|
22330
|
+
return this.http.get(`/users/${userId}/game-history`);
|
|
22253
22331
|
}
|
|
22254
22332
|
/**
|
|
22255
|
-
*
|
|
22333
|
+
* Get user activity for spectate flow. Returns in_game (with gameId, gameType), in_lobby (with lobbyId, lobbyStatus), or idle.
|
|
22256
22334
|
*/
|
|
22257
|
-
|
|
22258
|
-
|
|
22259
|
-
|
|
22260
|
-
authorizedWithdrawerPubkey,
|
|
22261
|
-
lamports,
|
|
22262
|
-
toPubkey
|
|
22263
|
-
} = params;
|
|
22264
|
-
const type2 = VOTE_INSTRUCTION_LAYOUTS.Withdraw;
|
|
22265
|
-
const data = encodeData(type2, {
|
|
22266
|
-
lamports
|
|
22267
|
-
});
|
|
22268
|
-
const keys = [{
|
|
22269
|
-
pubkey: votePubkey,
|
|
22270
|
-
isSigner: false,
|
|
22271
|
-
isWritable: true
|
|
22272
|
-
}, {
|
|
22273
|
-
pubkey: toPubkey,
|
|
22274
|
-
isSigner: false,
|
|
22275
|
-
isWritable: true
|
|
22276
|
-
}, {
|
|
22277
|
-
pubkey: authorizedWithdrawerPubkey,
|
|
22278
|
-
isSigner: true,
|
|
22279
|
-
isWritable: false
|
|
22280
|
-
}];
|
|
22281
|
-
return new Transaction().add({
|
|
22282
|
-
keys,
|
|
22283
|
-
programId: this.programId,
|
|
22284
|
-
data
|
|
22335
|
+
async getUserActivity(userId) {
|
|
22336
|
+
return this.http.get(`/users/${userId}/activity`, {
|
|
22337
|
+
cache: "no-store"
|
|
22285
22338
|
});
|
|
22286
22339
|
}
|
|
22287
22340
|
/**
|
|
22288
|
-
*
|
|
22289
|
-
*
|
|
22290
|
-
* This function was created as a safeguard for vote accounts running validators, `safeWithdraw`
|
|
22291
|
-
* checks that the withdraw amount will not exceed the specified balance while leaving enough left
|
|
22292
|
-
* to cover rent. If you wish to close the vote account by withdrawing the full amount, call the
|
|
22293
|
-
* `withdraw` method directly.
|
|
22341
|
+
* Get the current active game for a user (if they are a player in one).
|
|
22342
|
+
* Returns null if the user is not in an active game.
|
|
22294
22343
|
*/
|
|
22295
|
-
|
|
22296
|
-
|
|
22297
|
-
|
|
22344
|
+
async getCurrentGame(userId) {
|
|
22345
|
+
return this.http.get(`/users/${userId}/current-game`, {
|
|
22346
|
+
cache: "no-store"
|
|
22347
|
+
});
|
|
22348
|
+
}
|
|
22349
|
+
async getUserStats(userId) {
|
|
22350
|
+
return this.http.get(`/users/${userId}/stats`);
|
|
22351
|
+
}
|
|
22352
|
+
};
|
|
22353
|
+
|
|
22354
|
+
// src/feature-flags.ts
|
|
22355
|
+
var FeatureFlags = class {
|
|
22356
|
+
constructor(http2, logger2) {
|
|
22357
|
+
this.http = http2;
|
|
22358
|
+
this.logger = logger2;
|
|
22359
|
+
this.flags = [];
|
|
22360
|
+
this.loaded = false;
|
|
22361
|
+
}
|
|
22362
|
+
async getFeatureFlags() {
|
|
22363
|
+
this.flags = await this.http.get("/feature-flags");
|
|
22364
|
+
this.loaded = true;
|
|
22365
|
+
return this.flags;
|
|
22366
|
+
}
|
|
22367
|
+
isEnabledFlag(name) {
|
|
22368
|
+
const flag = this.flags.find((f) => f.name === name);
|
|
22369
|
+
return flag?.enabled ?? false;
|
|
22370
|
+
}
|
|
22371
|
+
isLoaded() {
|
|
22372
|
+
return this.loaded;
|
|
22373
|
+
}
|
|
22374
|
+
async updateFeatureFlag(name, enabled) {
|
|
22375
|
+
const flag = await this.http.patch(`/feature-flags/${name}`, {
|
|
22376
|
+
enabled
|
|
22377
|
+
});
|
|
22378
|
+
const index = this.flags.findIndex((f) => f.name === name);
|
|
22379
|
+
if (index >= 0) {
|
|
22380
|
+
this.flags[index] = flag;
|
|
22381
|
+
} else {
|
|
22382
|
+
this.flags.push(flag);
|
|
22298
22383
|
}
|
|
22299
|
-
return
|
|
22384
|
+
return flag;
|
|
22385
|
+
}
|
|
22386
|
+
async createFeatureFlag(name, enabled) {
|
|
22387
|
+
const flag = await this.http.post("/feature-flags", {
|
|
22388
|
+
name,
|
|
22389
|
+
enabled
|
|
22390
|
+
});
|
|
22391
|
+
this.flags.push(flag);
|
|
22392
|
+
return flag;
|
|
22393
|
+
}
|
|
22394
|
+
};
|
|
22395
|
+
|
|
22396
|
+
// src/lobbies.ts
|
|
22397
|
+
var Lobbies = class {
|
|
22398
|
+
constructor(http2, logger2) {
|
|
22399
|
+
this.http = http2;
|
|
22400
|
+
this.logger = logger2;
|
|
22401
|
+
}
|
|
22402
|
+
async createLobby(gameType, betAmount) {
|
|
22403
|
+
return this.http.post("/lobbies", { gameType, betAmount });
|
|
22404
|
+
}
|
|
22405
|
+
async getLobby(lobbyId) {
|
|
22406
|
+
return this.http.get(`/lobbies/${lobbyId}`);
|
|
22407
|
+
}
|
|
22408
|
+
async inviteFriend(lobbyId, friendId) {
|
|
22409
|
+
return this.http.post(`/lobbies/${lobbyId}/invite`, {
|
|
22410
|
+
friendId
|
|
22411
|
+
});
|
|
22412
|
+
}
|
|
22413
|
+
async acceptInvite(lobbyId) {
|
|
22414
|
+
return this.http.post(`/lobbies/${lobbyId}/accept-invite`, {});
|
|
22415
|
+
}
|
|
22416
|
+
async joinLobby(lobbyId) {
|
|
22417
|
+
return this.http.post(`/lobbies/${lobbyId}/join`, {});
|
|
22418
|
+
}
|
|
22419
|
+
async removePlayer(lobbyId, userId) {
|
|
22420
|
+
return this.http.delete(
|
|
22421
|
+
`/lobbies/${lobbyId}/players/${userId}`
|
|
22422
|
+
);
|
|
22423
|
+
}
|
|
22424
|
+
async kickPlayer(lobbyId, userId) {
|
|
22425
|
+
return this.removePlayer(lobbyId, userId);
|
|
22426
|
+
}
|
|
22427
|
+
async leaveLobby(lobbyId) {
|
|
22428
|
+
return this.http.delete(`/lobbies/${lobbyId}`);
|
|
22429
|
+
}
|
|
22430
|
+
async joinQueue(lobbyId) {
|
|
22431
|
+
return this.http.post(`/lobbies/${lobbyId}/join-queue`, {});
|
|
22432
|
+
}
|
|
22433
|
+
async cancelQueue(lobbyId) {
|
|
22434
|
+
return this.http.delete(`/lobbies/${lobbyId}/queue`);
|
|
22435
|
+
}
|
|
22436
|
+
async updateBetAmount(lobbyId, betAmount) {
|
|
22437
|
+
return this.http.patch(`/lobbies/${lobbyId}/bet-amount`, {
|
|
22438
|
+
betAmount
|
|
22439
|
+
});
|
|
22440
|
+
}
|
|
22441
|
+
async playSound(lobbyId, sound) {
|
|
22442
|
+
return this.http.post(`/lobbies/${lobbyId}/sound`, {
|
|
22443
|
+
sound
|
|
22444
|
+
});
|
|
22445
|
+
}
|
|
22446
|
+
// Admin methods
|
|
22447
|
+
async getActiveLobbies() {
|
|
22448
|
+
return this.http.get("/lobbies/admin/active");
|
|
22449
|
+
}
|
|
22450
|
+
async getQueueStats() {
|
|
22451
|
+
return this.http.get("/lobbies/admin/queues");
|
|
22452
|
+
}
|
|
22453
|
+
async deleteLobby(lobbyId) {
|
|
22454
|
+
return this.http.delete(`/lobbies/admin/${lobbyId}`);
|
|
22300
22455
|
}
|
|
22301
22456
|
/**
|
|
22302
|
-
*
|
|
22457
|
+
* Play again: Create a new lobby, start deposits, and prepare deposit transaction
|
|
22458
|
+
* Returns the lobby and unsigned transaction that needs to be signed
|
|
22459
|
+
* @param gameType - The game type to play again
|
|
22460
|
+
* @param betAmount - The bet amount (same as previous game)
|
|
22461
|
+
* @param escrow - The escrow service instance (from sdk.escrow)
|
|
22303
22462
|
*/
|
|
22304
|
-
|
|
22305
|
-
const
|
|
22306
|
-
|
|
22307
|
-
|
|
22308
|
-
|
|
22309
|
-
|
|
22310
|
-
|
|
22311
|
-
|
|
22312
|
-
const keys = [{
|
|
22313
|
-
pubkey: votePubkey,
|
|
22314
|
-
isSigner: false,
|
|
22315
|
-
isWritable: true
|
|
22316
|
-
}, {
|
|
22317
|
-
pubkey: nodePubkey,
|
|
22318
|
-
isSigner: true,
|
|
22319
|
-
isWritable: false
|
|
22320
|
-
}, {
|
|
22321
|
-
pubkey: authorizedWithdrawerPubkey,
|
|
22322
|
-
isSigner: true,
|
|
22323
|
-
isWritable: false
|
|
22324
|
-
}];
|
|
22325
|
-
return new Transaction().add({
|
|
22326
|
-
keys,
|
|
22327
|
-
programId: this.programId,
|
|
22328
|
-
data
|
|
22329
|
-
});
|
|
22463
|
+
async playAgain(gameType, betAmount, escrow) {
|
|
22464
|
+
const lobby = await this.createLobby(gameType, betAmount);
|
|
22465
|
+
await escrow.startDeposits(lobby.id);
|
|
22466
|
+
const prepareResponse = await escrow.prepareDepositTransaction(lobby.id);
|
|
22467
|
+
return {
|
|
22468
|
+
lobby,
|
|
22469
|
+
unsignedTransaction: prepareResponse.transaction
|
|
22470
|
+
};
|
|
22330
22471
|
}
|
|
22331
22472
|
};
|
|
22332
|
-
VoteProgram.programId = new PublicKey("Vote111111111111111111111111111111111111111");
|
|
22333
|
-
VoteProgram.space = 3762;
|
|
22334
|
-
var VALIDATOR_INFO_KEY = new PublicKey("Va1idator1nfo111111111111111111111111111111");
|
|
22335
|
-
var InfoString = type({
|
|
22336
|
-
name: string(),
|
|
22337
|
-
website: optional(string()),
|
|
22338
|
-
details: optional(string()),
|
|
22339
|
-
iconUrl: optional(string()),
|
|
22340
|
-
keybaseUsername: optional(string())
|
|
22341
|
-
});
|
|
22342
|
-
var VOTE_PROGRAM_ID = new PublicKey("Vote111111111111111111111111111111111111111");
|
|
22343
|
-
var VoteAccountLayout = BufferLayout.struct([
|
|
22344
|
-
publicKey("nodePubkey"),
|
|
22345
|
-
publicKey("authorizedWithdrawer"),
|
|
22346
|
-
BufferLayout.u8("commission"),
|
|
22347
|
-
BufferLayout.nu64(),
|
|
22348
|
-
// votes.length
|
|
22349
|
-
BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64("slot"), BufferLayout.u32("confirmationCount")]), BufferLayout.offset(BufferLayout.u32(), -8), "votes"),
|
|
22350
|
-
BufferLayout.u8("rootSlotValid"),
|
|
22351
|
-
BufferLayout.nu64("rootSlot"),
|
|
22352
|
-
BufferLayout.nu64(),
|
|
22353
|
-
// authorizedVoters.length
|
|
22354
|
-
BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64("epoch"), publicKey("authorizedVoter")]), BufferLayout.offset(BufferLayout.u32(), -8), "authorizedVoters"),
|
|
22355
|
-
BufferLayout.struct([BufferLayout.seq(BufferLayout.struct([publicKey("authorizedPubkey"), BufferLayout.nu64("epochOfLastAuthorizedSwitch"), BufferLayout.nu64("targetEpoch")]), 32, "buf"), BufferLayout.nu64("idx"), BufferLayout.u8("isEmpty")], "priorVoters"),
|
|
22356
|
-
BufferLayout.nu64(),
|
|
22357
|
-
// epochCredits.length
|
|
22358
|
-
BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64("epoch"), BufferLayout.nu64("credits"), BufferLayout.nu64("prevCredits")]), BufferLayout.offset(BufferLayout.u32(), -8), "epochCredits"),
|
|
22359
|
-
BufferLayout.struct([BufferLayout.nu64("slot"), BufferLayout.nu64("timestamp")], "lastTimestamp")
|
|
22360
|
-
]);
|
|
22361
22473
|
|
|
22362
22474
|
// src/games.ts
|
|
22363
22475
|
var Games = class {
|
|
@@ -25192,8 +25304,20 @@ var SDK = class {
|
|
|
25192
25304
|
constructor(config) {
|
|
25193
25305
|
const baseUrl = config.baseUrl || "http://localhost:3000";
|
|
25194
25306
|
const logger2 = config.logger || logger;
|
|
25195
|
-
this.http = config.httpClient || new HttpClient(
|
|
25307
|
+
this.http = config.httpClient || new HttpClient(
|
|
25308
|
+
baseUrl,
|
|
25309
|
+
config.storage,
|
|
25310
|
+
logger2,
|
|
25311
|
+
config.appId,
|
|
25312
|
+
config.autoPay
|
|
25313
|
+
);
|
|
25196
25314
|
this.wallet = new Wallet(this.http, logger2);
|
|
25315
|
+
if (this.http instanceof HttpClient) {
|
|
25316
|
+
this.http.setAutoPayHandlers({
|
|
25317
|
+
signerAddressProvider: () => this.wallet.getSignerAddress(),
|
|
25318
|
+
signTransactionHandler: (transaction) => this.wallet.signTransaction(transaction)
|
|
25319
|
+
});
|
|
25320
|
+
}
|
|
25197
25321
|
this.auth = new Auth(this.http, config.storage, this.wallet, logger2);
|
|
25198
25322
|
this.admin = new Admin(this.http, logger2);
|
|
25199
25323
|
this.users = new Users(this.http, logger2);
|