@rabby-wallet/gnosis-sdk 1.4.8-alpha-2 → 1.4.8-alpha-4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +35 -0
- package/dist/api.js +46 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +34 -1
- package/package.json +1 -1
- package/src/api.ts +89 -0
- package/src/index.ts +39 -1
package/dist/api.d.ts
CHANGED
|
@@ -73,6 +73,31 @@ export type SafeOpenApiService = {
|
|
|
73
73
|
operation?: number;
|
|
74
74
|
};
|
|
75
75
|
}) => Promise<string | undefined>;
|
|
76
|
+
getSafeMessages?: (params: {
|
|
77
|
+
txServiceUrl: string;
|
|
78
|
+
safeAddress: string;
|
|
79
|
+
options?: Record<string, any>;
|
|
80
|
+
}) => Promise<{
|
|
81
|
+
results: any[];
|
|
82
|
+
}>;
|
|
83
|
+
addSafeMessage?: (params: {
|
|
84
|
+
txServiceUrl: string;
|
|
85
|
+
safeAddress: string;
|
|
86
|
+
data: {
|
|
87
|
+
message: string | Record<string, any>;
|
|
88
|
+
signature: string;
|
|
89
|
+
safeAppId?: number;
|
|
90
|
+
};
|
|
91
|
+
}) => Promise<void>;
|
|
92
|
+
getSafeMessage?: (params: {
|
|
93
|
+
txServiceUrl: string;
|
|
94
|
+
messageHash: string;
|
|
95
|
+
}) => Promise<any>;
|
|
96
|
+
addSafeMessageSignature?: (params: {
|
|
97
|
+
txServiceUrl: string;
|
|
98
|
+
messageHash: string;
|
|
99
|
+
signature: string;
|
|
100
|
+
}) => Promise<void>;
|
|
76
101
|
};
|
|
77
102
|
export declare const GNOSIS_SUPPORT_CHAINS: string[];
|
|
78
103
|
export declare const HOST_MAP: Record<string, string>;
|
|
@@ -94,5 +119,15 @@ export default class RequestProvider {
|
|
|
94
119
|
getSafeInfo(safeAddress: string): Promise<SafeInfo>;
|
|
95
120
|
confirmTransaction(safeTransactionHash: string, data: Record<string, any>): Promise<void>;
|
|
96
121
|
getSafeTxGas(safeAddress: string, safeVersion: string, safeTxData: SafeTransactionDataPartial): Promise<string | undefined>;
|
|
122
|
+
getMessages(safeAddress: string, options?: Record<string, any>): Promise<{
|
|
123
|
+
results: any[];
|
|
124
|
+
}>;
|
|
125
|
+
addMessage(safeAddress: string, data: {
|
|
126
|
+
message: string | Record<string, any>;
|
|
127
|
+
signature: string;
|
|
128
|
+
safeAppId?: number;
|
|
129
|
+
}): Promise<void>;
|
|
130
|
+
getMessage(messageHash: string): Promise<any>;
|
|
131
|
+
addMessageSignature(messageHash: string, signature: string): Promise<void>;
|
|
97
132
|
}
|
|
98
133
|
export {};
|
package/dist/api.js
CHANGED
|
@@ -310,4 +310,50 @@ export default class RequestProvider {
|
|
|
310
310
|
console.error(e);
|
|
311
311
|
}
|
|
312
312
|
}
|
|
313
|
+
getMessages(safeAddress, options) {
|
|
314
|
+
const checksumAddress = ethers.utils.getAddress(safeAddress);
|
|
315
|
+
if (this.shouldUseOpenapiService && this.openapiService?.getSafeMessages) {
|
|
316
|
+
return this.openapiService.getSafeMessages({
|
|
317
|
+
txServiceUrl: this.prefix,
|
|
318
|
+
safeAddress: checksumAddress,
|
|
319
|
+
options,
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
return this.request.get(`/v1/safes/${checksumAddress}/messages/`, {
|
|
323
|
+
params: options,
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
addMessage(safeAddress, data) {
|
|
327
|
+
const checksumAddress = ethers.utils.getAddress(safeAddress);
|
|
328
|
+
if (this.shouldUseOpenapiService && this.openapiService?.addSafeMessage) {
|
|
329
|
+
return this.openapiService.addSafeMessage({
|
|
330
|
+
txServiceUrl: this.prefix,
|
|
331
|
+
safeAddress: checksumAddress,
|
|
332
|
+
data,
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
return this.request.post(`/v1/safes/${checksumAddress}/messages/`, data);
|
|
336
|
+
}
|
|
337
|
+
getMessage(messageHash) {
|
|
338
|
+
if (this.shouldUseOpenapiService && this.openapiService?.getSafeMessage) {
|
|
339
|
+
return this.openapiService.getSafeMessage({
|
|
340
|
+
txServiceUrl: this.prefix,
|
|
341
|
+
messageHash,
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
return this.request.get(`/v1/messages/${messageHash}/`);
|
|
345
|
+
}
|
|
346
|
+
addMessageSignature(messageHash, signature) {
|
|
347
|
+
if (this.shouldUseOpenapiService &&
|
|
348
|
+
this.openapiService?.addSafeMessageSignature) {
|
|
349
|
+
return this.openapiService.addSafeMessageSignature({
|
|
350
|
+
txServiceUrl: this.prefix,
|
|
351
|
+
messageHash,
|
|
352
|
+
signature,
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
return this.request.post(`/v1/messages/${messageHash}/signatures/`, {
|
|
356
|
+
signature,
|
|
357
|
+
});
|
|
358
|
+
}
|
|
313
359
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { AxiosAdapter } from "axios";
|
|
|
3
3
|
import { Contract, providers } from "ethers";
|
|
4
4
|
import { TransactionOptions, TransactionResult, SafeSignature, SafeTransaction, SafeTransactionDataPartial } from "@safe-global/types-kit";
|
|
5
5
|
import { EthSafeMessage, EthSafeTransaction } from "@safe-global/protocol-kit";
|
|
6
|
-
import SafeApiKit, { SafeMessage as ApiKitSafeMessage } from "@safe-global/api-kit";
|
|
6
|
+
import SafeApiKit, { GetSafeMessageListOptions, SafeMessage as ApiKitSafeMessage } from "@safe-global/api-kit";
|
|
7
7
|
import RequestProvider, { SafeInfo, SafeOpenApiService } from "./api";
|
|
8
8
|
declare class Safe {
|
|
9
9
|
contract: Contract;
|
|
@@ -28,6 +28,7 @@ declare class Safe {
|
|
|
28
28
|
static getPendingTransactions(safeAddress: string, network: string, nonce: number): Promise<{
|
|
29
29
|
results: import("./api").SafeTransactionItem[];
|
|
30
30
|
}>;
|
|
31
|
+
static getMessage(messageHash: string, network: string): Promise<any>;
|
|
31
32
|
static createSafeApiKit: (network: string) => SafeApiKit;
|
|
32
33
|
getPendingTransactions(): Promise<{
|
|
33
34
|
results: import("./api").SafeTransactionItem[];
|
|
@@ -75,6 +76,11 @@ declare class Safe {
|
|
|
75
76
|
addMessage({ safeMessage, }: {
|
|
76
77
|
safeMessage: EthSafeMessage;
|
|
77
78
|
}): Promise<void>;
|
|
79
|
+
getMessages(options?: GetSafeMessageListOptions): Promise<{
|
|
80
|
+
results: any[];
|
|
81
|
+
}>;
|
|
82
|
+
getMessage(messageHash: string): Promise<any>;
|
|
83
|
+
addMessageSignature(messageHash: string, signature: string): Promise<void>;
|
|
78
84
|
}
|
|
79
85
|
export default Safe;
|
|
80
86
|
export type BasicSafeInfo = Awaited<ReturnType<Safe["getBasicSafeInfo"]>>;
|
package/dist/index.js
CHANGED
|
@@ -84,6 +84,14 @@ class Safe {
|
|
|
84
84
|
const transactions = await request.getPendingTransactions(safeAddress, nonce);
|
|
85
85
|
return transactions;
|
|
86
86
|
}
|
|
87
|
+
static async getMessage(messageHash, network) {
|
|
88
|
+
const request = new RequestProvider({
|
|
89
|
+
networkId: network,
|
|
90
|
+
adapter: Safe.adapter,
|
|
91
|
+
openapiService: Safe.openapiService,
|
|
92
|
+
});
|
|
93
|
+
return request.getMessage(messageHash);
|
|
94
|
+
}
|
|
87
95
|
async getPendingTransactions() {
|
|
88
96
|
const nonce = await this.getNonce();
|
|
89
97
|
const transactions = await this.request.getPendingTransactions(this.safeAddress, nonce);
|
|
@@ -249,7 +257,7 @@ class Safe {
|
|
|
249
257
|
async addMessage({ safeMessage, }) {
|
|
250
258
|
const safeAddress = this.safeAddress;
|
|
251
259
|
try {
|
|
252
|
-
return this.
|
|
260
|
+
return this.request.addMessage(safeAddress, {
|
|
253
261
|
message: safeMessage.data,
|
|
254
262
|
signature: safeMessage.encodedSignatures(),
|
|
255
263
|
});
|
|
@@ -258,6 +266,31 @@ class Safe {
|
|
|
258
266
|
throw new Error("Could not add a new off-chain message to the Safe account");
|
|
259
267
|
}
|
|
260
268
|
}
|
|
269
|
+
async getMessages(options) {
|
|
270
|
+
const safeAddress = this.safeAddress;
|
|
271
|
+
try {
|
|
272
|
+
return this.request.getMessages(safeAddress, options);
|
|
273
|
+
}
|
|
274
|
+
catch (error) {
|
|
275
|
+
throw new Error("Could not get off-chain messages of the Safe account");
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
async getMessage(messageHash) {
|
|
279
|
+
try {
|
|
280
|
+
return this.request.getMessage(messageHash);
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
throw new Error("Could not get off-chain message of the Safe account");
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
async addMessageSignature(messageHash, signature) {
|
|
287
|
+
try {
|
|
288
|
+
return this.request.addMessageSignature(messageHash, signature);
|
|
289
|
+
}
|
|
290
|
+
catch (error) {
|
|
291
|
+
throw new Error("Could not add an off-chain message signature to the Safe account");
|
|
292
|
+
}
|
|
293
|
+
}
|
|
261
294
|
}
|
|
262
295
|
Safe.createSafeApiKit = (network) => {
|
|
263
296
|
return new SafeApiKit({
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -77,6 +77,29 @@ export type SafeOpenApiService = {
|
|
|
77
77
|
operation?: number;
|
|
78
78
|
};
|
|
79
79
|
}) => Promise<string | undefined>;
|
|
80
|
+
getSafeMessages?: (params: {
|
|
81
|
+
txServiceUrl: string;
|
|
82
|
+
safeAddress: string;
|
|
83
|
+
options?: Record<string, any>;
|
|
84
|
+
}) => Promise<{ results: any[] }>;
|
|
85
|
+
addSafeMessage?: (params: {
|
|
86
|
+
txServiceUrl: string;
|
|
87
|
+
safeAddress: string;
|
|
88
|
+
data: {
|
|
89
|
+
message: string | Record<string, any>;
|
|
90
|
+
signature: string;
|
|
91
|
+
safeAppId?: number;
|
|
92
|
+
};
|
|
93
|
+
}) => Promise<void>;
|
|
94
|
+
getSafeMessage?: (params: {
|
|
95
|
+
txServiceUrl: string;
|
|
96
|
+
messageHash: string;
|
|
97
|
+
}) => Promise<any>;
|
|
98
|
+
addSafeMessageSignature?: (params: {
|
|
99
|
+
txServiceUrl: string;
|
|
100
|
+
messageHash: string;
|
|
101
|
+
signature: string;
|
|
102
|
+
}) => Promise<void>;
|
|
80
103
|
};
|
|
81
104
|
|
|
82
105
|
type NetworkShortName = {
|
|
@@ -458,4 +481,70 @@ export default class RequestProvider {
|
|
|
458
481
|
console.error(e);
|
|
459
482
|
}
|
|
460
483
|
}
|
|
484
|
+
|
|
485
|
+
getMessages(
|
|
486
|
+
safeAddress: string,
|
|
487
|
+
options?: Record<string, any>
|
|
488
|
+
): Promise<{ results: any[] }> {
|
|
489
|
+
const checksumAddress = ethers.utils.getAddress(safeAddress);
|
|
490
|
+
if (this.shouldUseOpenapiService && this.openapiService?.getSafeMessages) {
|
|
491
|
+
return this.openapiService.getSafeMessages({
|
|
492
|
+
txServiceUrl: this.prefix,
|
|
493
|
+
safeAddress: checksumAddress,
|
|
494
|
+
options,
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
return this.request.get(`/v1/safes/${checksumAddress}/messages/`, {
|
|
499
|
+
params: options,
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
addMessage(
|
|
504
|
+
safeAddress: string,
|
|
505
|
+
data: {
|
|
506
|
+
message: string | Record<string, any>;
|
|
507
|
+
signature: string;
|
|
508
|
+
safeAppId?: number;
|
|
509
|
+
}
|
|
510
|
+
): Promise<void> {
|
|
511
|
+
const checksumAddress = ethers.utils.getAddress(safeAddress);
|
|
512
|
+
if (this.shouldUseOpenapiService && this.openapiService?.addSafeMessage) {
|
|
513
|
+
return this.openapiService.addSafeMessage({
|
|
514
|
+
txServiceUrl: this.prefix,
|
|
515
|
+
safeAddress: checksumAddress,
|
|
516
|
+
data,
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
return this.request.post(`/v1/safes/${checksumAddress}/messages/`, data);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
getMessage(messageHash: string): Promise<any> {
|
|
524
|
+
if (this.shouldUseOpenapiService && this.openapiService?.getSafeMessage) {
|
|
525
|
+
return this.openapiService.getSafeMessage({
|
|
526
|
+
txServiceUrl: this.prefix,
|
|
527
|
+
messageHash,
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
return this.request.get(`/v1/messages/${messageHash}/`);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
addMessageSignature(messageHash: string, signature: string): Promise<void> {
|
|
535
|
+
if (
|
|
536
|
+
this.shouldUseOpenapiService &&
|
|
537
|
+
this.openapiService?.addSafeMessageSignature
|
|
538
|
+
) {
|
|
539
|
+
return this.openapiService.addSafeMessageSignature({
|
|
540
|
+
txServiceUrl: this.prefix,
|
|
541
|
+
messageHash,
|
|
542
|
+
signature,
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
return this.request.post(`/v1/messages/${messageHash}/signatures/`, {
|
|
547
|
+
signature,
|
|
548
|
+
});
|
|
549
|
+
}
|
|
461
550
|
}
|
package/src/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
import { EthSafeMessage, EthSafeTransaction } from "@safe-global/protocol-kit";
|
|
13
13
|
import { calculateSafeMessageHash } from "@safe-global/protocol-kit/dist/src/utils";
|
|
14
14
|
import SafeApiKit, {
|
|
15
|
+
GetSafeMessageListOptions,
|
|
15
16
|
SafeMessage as ApiKitSafeMessage,
|
|
16
17
|
} from "@safe-global/api-kit";
|
|
17
18
|
// import { getTransactionServiceUrl } from "@safe-global/api-kit/dist/src/utils/config";
|
|
@@ -104,6 +105,15 @@ class Safe {
|
|
|
104
105
|
return transactions;
|
|
105
106
|
}
|
|
106
107
|
|
|
108
|
+
static async getMessage(messageHash: string, network: string) {
|
|
109
|
+
const request = new RequestProvider({
|
|
110
|
+
networkId: network,
|
|
111
|
+
adapter: Safe.adapter,
|
|
112
|
+
openapiService: Safe.openapiService,
|
|
113
|
+
});
|
|
114
|
+
return request.getMessage(messageHash);
|
|
115
|
+
}
|
|
116
|
+
|
|
107
117
|
static createSafeApiKit = (network: string) => {
|
|
108
118
|
return new SafeApiKit({
|
|
109
119
|
chainId: BigInt(network),
|
|
@@ -402,7 +412,7 @@ class Safe {
|
|
|
402
412
|
const safeAddress = this.safeAddress;
|
|
403
413
|
|
|
404
414
|
try {
|
|
405
|
-
return this.
|
|
415
|
+
return this.request.addMessage(safeAddress, {
|
|
406
416
|
message: safeMessage.data as string | ApiKitEIP712TypedData,
|
|
407
417
|
signature: safeMessage.encodedSignatures(),
|
|
408
418
|
});
|
|
@@ -412,6 +422,34 @@ class Safe {
|
|
|
412
422
|
);
|
|
413
423
|
}
|
|
414
424
|
}
|
|
425
|
+
|
|
426
|
+
async getMessages(options?: GetSafeMessageListOptions) {
|
|
427
|
+
const safeAddress = this.safeAddress;
|
|
428
|
+
|
|
429
|
+
try {
|
|
430
|
+
return this.request.getMessages(safeAddress, options);
|
|
431
|
+
} catch (error) {
|
|
432
|
+
throw new Error("Could not get off-chain messages of the Safe account");
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
async getMessage(messageHash: string) {
|
|
437
|
+
try {
|
|
438
|
+
return this.request.getMessage(messageHash);
|
|
439
|
+
} catch (error) {
|
|
440
|
+
throw new Error("Could not get off-chain message of the Safe account");
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
async addMessageSignature(messageHash: string, signature: string) {
|
|
445
|
+
try {
|
|
446
|
+
return this.request.addMessageSignature(messageHash, signature);
|
|
447
|
+
} catch (error) {
|
|
448
|
+
throw new Error(
|
|
449
|
+
"Could not add an off-chain message signature to the Safe account",
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
415
453
|
}
|
|
416
454
|
|
|
417
455
|
export default Safe;
|