@epoch-protocol/inventory-sdk 1.0.1 → 1.0.3
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/kms-signing/index.d.ts +10 -0
- package/dist/kms-signing/index.d.ts.map +1 -0
- package/dist/kms-signing/index.js +52 -0
- package/dist/kms-signing/index.js.map +1 -0
- package/dist/kms-signing/models.d.ts +110 -0
- package/dist/kms-signing/models.d.ts.map +1 -0
- package/dist/kms-signing/models.js +4 -0
- package/dist/kms-signing/models.js.map +1 -0
- package/dist/safe-ops/index.d.ts +2 -0
- package/dist/safe-ops/index.d.ts.map +1 -1
- package/dist/safe-ops/index.js +43 -1
- package/dist/safe-ops/index.js.map +1 -1
- package/dist/token/index.d.ts +1 -1
- package/dist/token/index.d.ts.map +1 -1
- package/dist/token/index.js +13 -3
- package/dist/token/index.js.map +1 -1
- package/package.json +2 -2
- package/src/kms-signing/index.ts +50 -0
- package/src/kms-signing/models.ts +135 -0
- package/src/safe-ops/index.ts +52 -0
- package/src/token/index.ts +17 -6
- package/Dockerfile.dev +0 -19
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TransactionRequest } from "ethers";
|
|
2
|
+
export declare const getSignedMessageHashFromKms: (signingServiceUrl: string, messageHash: string) => Promise<{
|
|
3
|
+
signer: string;
|
|
4
|
+
signature: string;
|
|
5
|
+
}>;
|
|
6
|
+
export declare const getSignedTxFromKms: (transaction: TransactionRequest, signingServiceUrl: string) => Promise<{
|
|
7
|
+
signedTransaction: string;
|
|
8
|
+
transactionHash?: string;
|
|
9
|
+
}>;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/kms-signing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAG5C,eAAO,MAAM,2BAA2B,GAAU,mBAAmB,MAAM,EAAE,aAAa,MAAM,KAAG,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAqB/I,CAAC;AACF,eAAO,MAAM,kBAAkB,GAAI,aAAa,kBAAkB,EAAE,mBAAmB,MAAM;uBACjD,MAAM;sBAAoB,MAAM;EAuB3E,CAAA"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSignedTxFromKms = exports.getSignedMessageHashFromKms = void 0;
|
|
4
|
+
// getSignedMessageHashFromKms calls a signing service API to get the {signer, signature} for the given messageHash
|
|
5
|
+
const getSignedMessageHashFromKms = async (signingServiceUrl, messageHash) => {
|
|
6
|
+
try {
|
|
7
|
+
const response = await fetch(`${signingServiceUrl}/sign-message`, {
|
|
8
|
+
method: "POST",
|
|
9
|
+
headers: {
|
|
10
|
+
"Content-Type": "application/json",
|
|
11
|
+
},
|
|
12
|
+
body: JSON.stringify({ messageHash }),
|
|
13
|
+
});
|
|
14
|
+
if (!response.ok) {
|
|
15
|
+
const error = await response.json();
|
|
16
|
+
throw new Error(error.error || "Signing service error");
|
|
17
|
+
}
|
|
18
|
+
const { signer, signature } = await response.json();
|
|
19
|
+
return { signer, signature };
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
console.error("Error signing message:", error);
|
|
23
|
+
throw new Error(error.message || "Failed to sign message");
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
exports.getSignedMessageHashFromKms = getSignedMessageHashFromKms;
|
|
27
|
+
const getSignedTxFromKms = (transaction, signingServiceUrl) => {
|
|
28
|
+
return new Promise(async (resolve, reject) => {
|
|
29
|
+
try {
|
|
30
|
+
const response = await fetch(`${signingServiceUrl}/sign-transaction`, {
|
|
31
|
+
method: "POST",
|
|
32
|
+
headers: {
|
|
33
|
+
"Content-Type": "application/json",
|
|
34
|
+
},
|
|
35
|
+
body: JSON.stringify({ transaction }),
|
|
36
|
+
});
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
const error = await response.json();
|
|
39
|
+
reject(new Error(error.error || "Signing service error"));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const { signedTransaction, transactionHash } = await response.json();
|
|
43
|
+
resolve({ signedTransaction, transactionHash });
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
console.error("Error signing transaction:", error);
|
|
47
|
+
reject(new Error(error.message || "Failed to sign transaction"));
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
exports.getSignedTxFromKms = getSignedTxFromKms;
|
|
52
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/kms-signing/index.ts"],"names":[],"mappings":";;;AAEA,mHAAmH;AAC5G,MAAM,2BAA2B,GAAG,KAAK,EAAE,iBAAyB,EAAE,WAAmB,EAAkD,EAAE;IAChJ,IAAI,CAAC;QACD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,iBAAiB,eAAe,EAAE;YAC9D,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACL,cAAc,EAAE,kBAAkB;aACrC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,WAAW,EAAE,CAAC;SACxC,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACf,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,uBAAuB,CAAC,CAAC;QAC5D,CAAC;QAED,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACpD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IACjC,CAA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AAA;AAxBY,QAAA,kBAAkB,sBAwB9B"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { AccessListish, AddressLike, AuthorizationLike, BigNumberish, BlobLike, BlockTag, KzgLibraryLike } from "ethers";
|
|
2
|
+
export interface TransactionRequest {
|
|
3
|
+
/**
|
|
4
|
+
* The transaction type.
|
|
5
|
+
*/
|
|
6
|
+
type?: null | number;
|
|
7
|
+
/**
|
|
8
|
+
* The target of the transaction.
|
|
9
|
+
*/
|
|
10
|
+
to?: null | AddressLike;
|
|
11
|
+
/**
|
|
12
|
+
* The sender of the transaction.
|
|
13
|
+
*/
|
|
14
|
+
from?: null | AddressLike;
|
|
15
|
+
/**
|
|
16
|
+
* The nonce of the transaction, used to prevent replay attacks.
|
|
17
|
+
*/
|
|
18
|
+
nonce?: null | number;
|
|
19
|
+
/**
|
|
20
|
+
* The maximum amount of gas to allow this transaction to consume.
|
|
21
|
+
*/
|
|
22
|
+
gasLimit?: null | BigNumberish;
|
|
23
|
+
/**
|
|
24
|
+
* The gas price to use for legacy transactions or transactions on
|
|
25
|
+
* legacy networks.
|
|
26
|
+
*
|
|
27
|
+
* Most of the time the ``max*FeePerGas`` is preferred.
|
|
28
|
+
*/
|
|
29
|
+
gasPrice?: null | BigNumberish;
|
|
30
|
+
/**
|
|
31
|
+
* The [[link-eip-1559]] maximum priority fee to pay per gas.
|
|
32
|
+
*/
|
|
33
|
+
maxPriorityFeePerGas?: null | BigNumberish;
|
|
34
|
+
/**
|
|
35
|
+
* The [[link-eip-1559]] maximum total fee to pay per gas. The actual
|
|
36
|
+
* value used is protocol enforced to be the block's base fee.
|
|
37
|
+
*/
|
|
38
|
+
maxFeePerGas?: null | BigNumberish;
|
|
39
|
+
/**
|
|
40
|
+
* The transaction data.
|
|
41
|
+
*/
|
|
42
|
+
data?: null | string;
|
|
43
|
+
/**
|
|
44
|
+
* The transaction value (in wei).
|
|
45
|
+
*/
|
|
46
|
+
value?: null | BigNumberish;
|
|
47
|
+
/**
|
|
48
|
+
* The chain ID for the network this transaction is valid on.
|
|
49
|
+
*/
|
|
50
|
+
chainId?: null | BigNumberish;
|
|
51
|
+
/**
|
|
52
|
+
* The [[link-eip-2930]] access list. Storage slots included in the access
|
|
53
|
+
* list are //warmed// by pre-loading them, so their initial cost to
|
|
54
|
+
* fetch is guaranteed, but then each additional access is cheaper.
|
|
55
|
+
*/
|
|
56
|
+
accessList?: null | AccessListish;
|
|
57
|
+
/**
|
|
58
|
+
* A custom object, which can be passed along for network-specific
|
|
59
|
+
* values.
|
|
60
|
+
*/
|
|
61
|
+
customData?: any;
|
|
62
|
+
/**
|
|
63
|
+
* When using ``call`` or ``estimateGas``, this allows a specific
|
|
64
|
+
* block to be queried. Many backends do not support this and when
|
|
65
|
+
* unsupported errors are silently squelched and ``"latest"`` is used.
|
|
66
|
+
*/
|
|
67
|
+
blockTag?: BlockTag;
|
|
68
|
+
/**
|
|
69
|
+
* When using ``call``, this enables CCIP-read, which permits the
|
|
70
|
+
* provider to be redirected to web-based content during execution,
|
|
71
|
+
* which is then further validated by the contract.
|
|
72
|
+
*
|
|
73
|
+
* There are potential security implications allowing CCIP-read, as
|
|
74
|
+
* it could be used to expose the IP address or user activity during
|
|
75
|
+
* the fetch to unexpected parties.
|
|
76
|
+
*/
|
|
77
|
+
enableCcipRead?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* The blob versioned hashes (see [[link-eip-4844]]).
|
|
80
|
+
*/
|
|
81
|
+
blobVersionedHashes?: null | Array<string>;
|
|
82
|
+
/**
|
|
83
|
+
* The maximum fee per blob gas (see [[link-eip-4844]]).
|
|
84
|
+
*/
|
|
85
|
+
maxFeePerBlobGas?: null | BigNumberish;
|
|
86
|
+
/**
|
|
87
|
+
* Any blobs to include in the transaction (see [[link-eip-4844]]).
|
|
88
|
+
*/
|
|
89
|
+
blobs?: null | Array<BlobLike>;
|
|
90
|
+
/**
|
|
91
|
+
* An external library for computing the KZG commitments and
|
|
92
|
+
* proofs necessary for EIP-4844 transactions (see [[link-eip-4844]]).
|
|
93
|
+
*
|
|
94
|
+
* This is generally ``null``, unless you are creating BLOb
|
|
95
|
+
* transactions.
|
|
96
|
+
*/
|
|
97
|
+
kzg?: null | KzgLibraryLike;
|
|
98
|
+
/**
|
|
99
|
+
* The [[link-eip-7594]] BLOb Wrapper Version used for PeerDAS.
|
|
100
|
+
*
|
|
101
|
+
* For networks that use EIP-7594, this property is required to
|
|
102
|
+
* serialize the sidecar correctly.
|
|
103
|
+
*/
|
|
104
|
+
blobWrapperVersion?: null | number;
|
|
105
|
+
/**
|
|
106
|
+
* The [[link-eip-7702]] authorizations (if any).
|
|
107
|
+
*/
|
|
108
|
+
authorizationList?: null | Array<AuthorizationLike>;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../src/kms-signing/models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,iBAAiB,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAEzH,MAAM,WAAW,kBAAkB;IAC/B;;OAEG;IACH,IAAI,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;IAErB;;OAEG;IACH,EAAE,CAAC,EAAE,IAAI,GAAG,WAAW,CAAC;IAExB;;OAEG;IACH,IAAI,CAAC,EAAE,IAAI,GAAG,WAAW,CAAC;IAE1B;;OAEG;IACH,KAAK,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,EAAE,IAAI,GAAG,YAAY,CAAC;IAE/B;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,IAAI,GAAG,YAAY,CAAC;IAE/B;;OAEG;IACH,oBAAoB,CAAC,EAAE,IAAI,GAAG,YAAY,CAAC;IAE3C;;;OAGG;IACH,YAAY,CAAC,EAAE,IAAI,GAAG,YAAY,CAAC;IAEnC;;OAEG;IACH,IAAI,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;IAErB;;OAEG;IACH,KAAK,CAAC,EAAE,IAAI,GAAG,YAAY,CAAC;IAE5B;;OAEG;IACH,OAAO,CAAC,EAAE,IAAI,GAAG,YAAY,CAAC;IAE9B;;;;OAIG;IACH,UAAU,CAAC,EAAE,IAAI,GAAG,aAAa,CAAC;IAElC;;;OAGG;IACH,UAAU,CAAC,EAAE,GAAG,CAAC;IAIjB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAEpB;;;;;;;;OAQG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;OAEG;IACH,mBAAmB,CAAC,EAAE,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,CAAA;IAE1C;;OAEG;IACH,gBAAgB,CAAC,EAAE,IAAI,GAAG,YAAY,CAAC;IAEvC;;OAEG;IACH,KAAK,CAAC,EAAE,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;IAE/B;;;;;;OAMG;IACH,GAAG,CAAC,EAAE,IAAI,GAAG,cAAc,CAAC;IAE5B;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;IAEnC;;OAEG;IACH,iBAAiB,CAAC,EAAE,IAAI,GAAG,KAAK,CAAC,iBAAiB,CAAC,CAAC;CAIvD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/kms-signing/models.ts"],"names":[],"mappings":";;AAsIC,CAAC"}
|
package/dist/safe-ops/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export declare const createSafeTx: (safe: Safe, txList: Array<{
|
|
|
8
8
|
operation: number;
|
|
9
9
|
}>) => Promise<SafeTransaction>;
|
|
10
10
|
export declare const signSafeTx: (safe: Safe, safeTx: SafeTransaction) => Promise<SafeTransaction>;
|
|
11
|
+
export declare const getReadOnlySafeInstance: (safeAddress: string, rpcUrl: string) => Promise<Safe>;
|
|
12
|
+
export declare const signSafeTxFromKms: (safe: Safe, safeTx: SafeTransaction, signingServiceUrl: string) => Promise<SafeTransaction>;
|
|
11
13
|
export declare const getSafeInstance: (safeAddress: string, privateKey: string, rpcUrl: string) => Promise<Safe>;
|
|
12
14
|
export declare const deconstructSafeTx: (SafeTransaction: SafeTransaction) => Promise<{
|
|
13
15
|
safeTxElements: DeconstructedSafeTx;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/safe-ops/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAA0B,MAAM,2BAA2B,CAAC;AACnE,OAAO,EACL,aAAa,EACb,eAAe,EACf,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/safe-ops/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAA0B,MAAM,2BAA2B,CAAC;AACnE,OAAO,EACL,aAAa,EACb,eAAe,EACf,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAI3E,eAAO,MAAM,YAAY,GACvB,MAAM,IAAI,EACV,QAAQ,KAAK,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC,KACD,OAAO,CAAC,eAAe,CASzB,CAAC;AAEF,eAAO,MAAM,UAAU,GACrB,MAAM,IAAI,EACV,QAAQ,eAAe,KACtB,OAAO,CAAC,eAAe,CASzB,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAClC,aAAa,MAAM,EACnB,QAAQ,MAAM,KACb,OAAO,CAAC,IAAI,CAMd,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAU,MAAM,IAAI,EAAE,QAAQ,eAAe,EAAE,mBAAmB,MAAM,KAAG,OAAO,CAAC,eAAe,CAmB/H,CAAA;AAgBD,eAAO,MAAM,eAAe,GAC1B,aAAa,MAAM,EACnB,YAAY,MAAM,EAClB,QAAQ,MAAM,KACb,OAAO,CAAC,IAAI,CASd,CAAC;AAGF,eAAO,MAAM,iBAAiB,GAC5B,iBAAiB,eAAe,KAC/B,OAAO,CAAC;IACT,cAAc,EAAE,mBAAmB,CAAC;IACpC,UAAU,EAAE,0BAA0B,EAAE,CAAC;CAC1C,CAgBA,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,qBAAqB,mBAAmB,EACxC,6BAA6B,0BAA0B,EAAE,KACxD,OAAO,CAAC;IACT,MAAM,EAAE,mBAAmB,CAAC;IAC5B,cAAc,EAAE,aAAa,EAAE,CAAC;CACjC,CAgBA,CAAC"}
|
package/dist/safe-ops/index.js
CHANGED
|
@@ -33,8 +33,9 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.reconstructSafeTx = exports.deconstructSafeTx = exports.getSafeInstance = exports.signSafeTx = exports.createSafeTx = void 0;
|
|
36
|
+
exports.reconstructSafeTx = exports.deconstructSafeTx = exports.getSafeInstance = exports.signSafeTxFromKms = exports.getReadOnlySafeInstance = exports.signSafeTx = exports.createSafeTx = void 0;
|
|
37
37
|
const protocol_kit_1 = __importStar(require("@safe-global/protocol-kit"));
|
|
38
|
+
const kms_signing_1 = require("../kms-signing");
|
|
38
39
|
const createSafeTx = async (safe, txList) => {
|
|
39
40
|
try {
|
|
40
41
|
const safeTx = await safe.createTransaction({ transactions: txList });
|
|
@@ -59,12 +60,52 @@ const signSafeTx = async (safe, safeTx) => {
|
|
|
59
60
|
}
|
|
60
61
|
};
|
|
61
62
|
exports.signSafeTx = signSafeTx;
|
|
63
|
+
const getReadOnlySafeInstance = async (safeAddress, rpcUrl) => {
|
|
64
|
+
const safe = await protocol_kit_1.default.init({
|
|
65
|
+
safeAddress,
|
|
66
|
+
provider: rpcUrl,
|
|
67
|
+
});
|
|
68
|
+
return safe;
|
|
69
|
+
};
|
|
70
|
+
exports.getReadOnlySafeInstance = getReadOnlySafeInstance;
|
|
71
|
+
const signSafeTxFromKms = async (safe, safeTx, signingServiceUrl) => {
|
|
72
|
+
try {
|
|
73
|
+
// Make an API call to the signing service endpoint to sign the safeTx message hash.
|
|
74
|
+
// We'll use fetch to POST to signingServiceUrl, sending { messageHash } in the body.
|
|
75
|
+
// Assume the signing service exposes an endpoint like POST /sign-message.
|
|
76
|
+
// First, get the transaction hash for this SafeTx:
|
|
77
|
+
const txHash = await safe.getTransactionHash(safeTx);
|
|
78
|
+
// Call the signing service with the txHash:
|
|
79
|
+
const { signer, signature } = await (0, kms_signing_1.getSignedMessageHashFromKms)(signingServiceUrl, txHash);
|
|
80
|
+
// The signing service responds with { signature }
|
|
81
|
+
safeTx.addSignature(new protocol_kit_1.EthSafeSignature(signer, signature));
|
|
82
|
+
return safeTx;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
console.log("error", error);
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
exports.signSafeTxFromKms = signSafeTxFromKms;
|
|
90
|
+
const getSafeTxHash = async (safe, safeTx) => {
|
|
91
|
+
try {
|
|
92
|
+
const txHash = await safe.getTransactionHash(safeTx);
|
|
93
|
+
console.log("txHash", txHash);
|
|
94
|
+
return txHash;
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
console.log("error", error);
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
62
101
|
const getSafeInstance = async (safeAddress, privateKey, rpcUrl) => {
|
|
63
102
|
const safe = await protocol_kit_1.default.init({
|
|
64
103
|
safeAddress,
|
|
65
104
|
provider: rpcUrl,
|
|
66
105
|
signer: privateKey,
|
|
67
106
|
});
|
|
107
|
+
const safeProvider = safe.getSafeProvider();
|
|
108
|
+
console.log("safeProvider", safeProvider);
|
|
68
109
|
return safe;
|
|
69
110
|
};
|
|
70
111
|
exports.getSafeInstance = getSafeInstance;
|
|
@@ -73,6 +114,7 @@ const deconstructSafeTx = async (SafeTransaction) => {
|
|
|
73
114
|
const safeTxElements = SafeTransaction.data;
|
|
74
115
|
const signatures = [];
|
|
75
116
|
Array.from(SafeTransaction.signatures.entries()).forEach(([key, signature]) => {
|
|
117
|
+
console.log("[key, signature]: ", [key, signature]);
|
|
76
118
|
signatures.push({
|
|
77
119
|
signer: key,
|
|
78
120
|
signature: signature.data,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/safe-ops/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0EAAmE;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/safe-ops/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0EAAmE;AAQnE,gDAA6D;AAEtD,MAAM,YAAY,GAAG,KAAK,EAC/B,IAAU,EACV,MAKE,EACwB,EAAE;IAC5B,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC,CAAC;QACtE,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAC9B,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAC5B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CAAC;AAjBW,QAAA,YAA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AAE,SAAS,CAAC,EAAE,EAAE;QAC5E,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC;QACpD,UAAU,CAAC,IAAI,CAAC;YACd,MAAM,EAAE,GAAG;YACX,SAAS,EAAE,SAAS,CAAC,IAAI;YACzB,mBAAmB,EAAE,SAAS,CAAC,mBAAmB;SACnD,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,OAAO;QACL,cAAc;QACd,UAAU;KACX,CAAC;AACJ,CAAC,CAAC;AArBW,QAAA,iBAAiB,qBAqB5B;AAEK,MAAM,iBAAiB,GAAG,KAAK,EACpC,mBAAwC,EACxC,2BAAyD,EAIxD,EAAE;IACH,MAAM,MAAM,GAAwB,mBAAmB,CAAC;IACxD,MAAM,cAAc,GAAoB,EAAE,CAAC;IAC3C,2BAA2B,CAAC,OAAO,CAAC,CAAC,0BAA0B,EAAE,EAAE;QACjE,cAAc,CAAC,IAAI,CACjB,IAAI,+BAAgB,CAClB,0BAA0B,CAAC,MAAM,EACjC,0BAA0B,CAAC,SAAS,EACpC,0BAA0B,CAAC,mBAAmB,CAC/C,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,OAAO;QACL,MAAM;QACN,cAAc;KACf,CAAC;AACJ,CAAC,CAAC;AAtBW,QAAA,iBAAiB,qBAsB5B"}
|
package/dist/token/index.d.ts
CHANGED
|
@@ -4,6 +4,6 @@ import { SafeTransaction } from "@safe-global/types-kit";
|
|
|
4
4
|
import Safe from "@safe-global/protocol-kit";
|
|
5
5
|
export declare const getTokenBalance: (address: string, token: Token, provider: Provider) => Promise<TokenInfo>;
|
|
6
6
|
export declare const getMultipleTokenBalances: (tokens: Token[], address: string, provider: Provider) => Promise<Array<TokenInfo>>;
|
|
7
|
-
export declare const getSignedTransferCalldataForSafe: (safeInstance: Safe, tokenAddress: string, recipientAddress: string, amount: BigInt) => Promise<SafeTransaction>;
|
|
7
|
+
export declare const getSignedTransferCalldataForSafe: (safeInstance: Safe, tokenAddress: string, recipientAddress: string, amount: BigInt, useKms: boolean, signingServiceUrl?: string) => Promise<SafeTransaction>;
|
|
8
8
|
export declare const getDecimals: (token: Token, provider: Provider) => Promise<any>;
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/token/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/token/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,QAAQ,EAAU,MAAM,QAAQ,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAG5C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,IAAI,MAAM,2BAA2B,CAAC;AAE7C,eAAO,MAAM,eAAe,GAC1B,SAAS,MAAM,EACf,OAAO,KAAK,EACZ,UAAU,QAAQ,KACjB,OAAO,CAAC,SAAS,CAkCnB,CAAC;AAEF,eAAO,MAAM,wBAAwB,GACnC,QAAQ,KAAK,EAAE,EACf,SAAS,MAAM,EACf,UAAU,QAAQ,KACjB,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAQ1B,CAAC;AAEF,eAAO,MAAM,gCAAgC,GAC3C,cAAc,IAAI,EAClB,cAAc,MAAM,EACpB,kBAAkB,MAAM,EACxB,QAAQ,MAAM,EACd,QAAQ,OAAO,EACf,oBAAoB,MAAM,KACzB,OAAO,CAAC,eAAe,CAwCzB,CAAC;AAGF,eAAO,MAAM,WAAW,GAAU,OAAO,KAAK,EAAE,UAAU,QAAQ,iBAOjE,CAAC"}
|
package/dist/token/index.js
CHANGED
|
@@ -46,7 +46,7 @@ const getMultipleTokenBalances = async (tokens, address, provider) => {
|
|
|
46
46
|
return results;
|
|
47
47
|
};
|
|
48
48
|
exports.getMultipleTokenBalances = getMultipleTokenBalances;
|
|
49
|
-
const getSignedTransferCalldataForSafe = async (safeInstance, tokenAddress, recipientAddress, amount) => {
|
|
49
|
+
const getSignedTransferCalldataForSafe = async (safeInstance, tokenAddress, recipientAddress, amount, useKms, signingServiceUrl) => {
|
|
50
50
|
if (tokenAddress === "0x0000000000000000000000000000000000000000") {
|
|
51
51
|
let safeTx = await (0, safe_ops_1.createSafeTx)(safeInstance, [
|
|
52
52
|
{
|
|
@@ -56,7 +56,12 @@ const getSignedTransferCalldataForSafe = async (safeInstance, tokenAddress, reci
|
|
|
56
56
|
operation: 0,
|
|
57
57
|
},
|
|
58
58
|
]);
|
|
59
|
-
|
|
59
|
+
if (useKms && signingServiceUrl) {
|
|
60
|
+
safeTx = await (0, safe_ops_1.signSafeTxFromKms)(safeInstance, safeTx, signingServiceUrl);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
safeTx = await (0, safe_ops_1.signSafeTx)(safeInstance, safeTx);
|
|
64
|
+
}
|
|
60
65
|
return safeTx;
|
|
61
66
|
}
|
|
62
67
|
else {
|
|
@@ -71,7 +76,12 @@ const getSignedTransferCalldataForSafe = async (safeInstance, tokenAddress, reci
|
|
|
71
76
|
operation: 0,
|
|
72
77
|
},
|
|
73
78
|
]);
|
|
74
|
-
|
|
79
|
+
if (useKms && signingServiceUrl) {
|
|
80
|
+
safeTx = await (0, safe_ops_1.signSafeTxFromKms)(safeInstance, safeTx, signingServiceUrl);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
safeTx = await (0, safe_ops_1.signSafeTx)(safeInstance, safeTx);
|
|
84
|
+
}
|
|
75
85
|
console.log("safeTx signed", safeTx);
|
|
76
86
|
return safeTx;
|
|
77
87
|
}
|
package/dist/token/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/token/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot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
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@safe-global/protocol-kit": "^6.1.1",
|
|
20
|
-
"ethers": "
|
|
20
|
+
"ethers": "6.15.0"
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { TransactionRequest } from "ethers";
|
|
2
|
+
|
|
3
|
+
// getSignedMessageHashFromKms calls a signing service API to get the {signer, signature} for the given messageHash
|
|
4
|
+
export const getSignedMessageHashFromKms = async (signingServiceUrl: string, messageHash: string): Promise<{ signer: string; signature: string }> => {
|
|
5
|
+
try {
|
|
6
|
+
const response = await fetch(`${signingServiceUrl}/sign-message`, {
|
|
7
|
+
method: "POST",
|
|
8
|
+
headers: {
|
|
9
|
+
"Content-Type": "application/json",
|
|
10
|
+
},
|
|
11
|
+
body: JSON.stringify({ messageHash }),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
if (!response.ok) {
|
|
15
|
+
const error = await response.json();
|
|
16
|
+
throw new Error(error.error || "Signing service error");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const { signer, signature } = await response.json();
|
|
20
|
+
return { signer, signature };
|
|
21
|
+
} catch (error: any) {
|
|
22
|
+
console.error("Error signing message:", error);
|
|
23
|
+
throw new Error(error.message || "Failed to sign message");
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
export const getSignedTxFromKms = (transaction: TransactionRequest, signingServiceUrl: string) => {
|
|
27
|
+
return new Promise<{ signedTransaction: string; transactionHash?: string }>(async (resolve, reject) => {
|
|
28
|
+
try {
|
|
29
|
+
const response = await fetch(`${signingServiceUrl}/sign-transaction`, {
|
|
30
|
+
method: "POST",
|
|
31
|
+
headers: {
|
|
32
|
+
"Content-Type": "application/json",
|
|
33
|
+
},
|
|
34
|
+
body: JSON.stringify({ transaction }),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
const error = await response.json();
|
|
39
|
+
reject(new Error(error.error || "Signing service error"));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const { signedTransaction, transactionHash } = await response.json();
|
|
44
|
+
resolve({ signedTransaction, transactionHash });
|
|
45
|
+
} catch (error: any) {
|
|
46
|
+
console.error("Error signing transaction:", error);
|
|
47
|
+
reject(new Error(error.message || "Failed to sign transaction"));
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { AccessListish, AddressLike, AuthorizationLike, BigNumberish, BlobLike, BlockTag, KzgLibraryLike } from "ethers";
|
|
2
|
+
|
|
3
|
+
export interface TransactionRequest {
|
|
4
|
+
/**
|
|
5
|
+
* The transaction type.
|
|
6
|
+
*/
|
|
7
|
+
type?: null | number;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The target of the transaction.
|
|
11
|
+
*/
|
|
12
|
+
to?: null | AddressLike;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The sender of the transaction.
|
|
16
|
+
*/
|
|
17
|
+
from?: null | AddressLike;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The nonce of the transaction, used to prevent replay attacks.
|
|
21
|
+
*/
|
|
22
|
+
nonce?: null | number;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The maximum amount of gas to allow this transaction to consume.
|
|
26
|
+
*/
|
|
27
|
+
gasLimit?: null | BigNumberish;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The gas price to use for legacy transactions or transactions on
|
|
31
|
+
* legacy networks.
|
|
32
|
+
*
|
|
33
|
+
* Most of the time the ``max*FeePerGas`` is preferred.
|
|
34
|
+
*/
|
|
35
|
+
gasPrice?: null | BigNumberish;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The [[link-eip-1559]] maximum priority fee to pay per gas.
|
|
39
|
+
*/
|
|
40
|
+
maxPriorityFeePerGas?: null | BigNumberish;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The [[link-eip-1559]] maximum total fee to pay per gas. The actual
|
|
44
|
+
* value used is protocol enforced to be the block's base fee.
|
|
45
|
+
*/
|
|
46
|
+
maxFeePerGas?: null | BigNumberish;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The transaction data.
|
|
50
|
+
*/
|
|
51
|
+
data?: null | string;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The transaction value (in wei).
|
|
55
|
+
*/
|
|
56
|
+
value?: null | BigNumberish;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The chain ID for the network this transaction is valid on.
|
|
60
|
+
*/
|
|
61
|
+
chainId?: null | BigNumberish;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The [[link-eip-2930]] access list. Storage slots included in the access
|
|
65
|
+
* list are //warmed// by pre-loading them, so their initial cost to
|
|
66
|
+
* fetch is guaranteed, but then each additional access is cheaper.
|
|
67
|
+
*/
|
|
68
|
+
accessList?: null | AccessListish;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* A custom object, which can be passed along for network-specific
|
|
72
|
+
* values.
|
|
73
|
+
*/
|
|
74
|
+
customData?: any;
|
|
75
|
+
|
|
76
|
+
// Only meaningful when used for call
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* When using ``call`` or ``estimateGas``, this allows a specific
|
|
80
|
+
* block to be queried. Many backends do not support this and when
|
|
81
|
+
* unsupported errors are silently squelched and ``"latest"`` is used.
|
|
82
|
+
*/
|
|
83
|
+
blockTag?: BlockTag;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* When using ``call``, this enables CCIP-read, which permits the
|
|
87
|
+
* provider to be redirected to web-based content during execution,
|
|
88
|
+
* which is then further validated by the contract.
|
|
89
|
+
*
|
|
90
|
+
* There are potential security implications allowing CCIP-read, as
|
|
91
|
+
* it could be used to expose the IP address or user activity during
|
|
92
|
+
* the fetch to unexpected parties.
|
|
93
|
+
*/
|
|
94
|
+
enableCcipRead?: boolean;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The blob versioned hashes (see [[link-eip-4844]]).
|
|
98
|
+
*/
|
|
99
|
+
blobVersionedHashes?: null | Array<string>
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The maximum fee per blob gas (see [[link-eip-4844]]).
|
|
103
|
+
*/
|
|
104
|
+
maxFeePerBlobGas?: null | BigNumberish;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Any blobs to include in the transaction (see [[link-eip-4844]]).
|
|
108
|
+
*/
|
|
109
|
+
blobs?: null | Array<BlobLike>;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* An external library for computing the KZG commitments and
|
|
113
|
+
* proofs necessary for EIP-4844 transactions (see [[link-eip-4844]]).
|
|
114
|
+
*
|
|
115
|
+
* This is generally ``null``, unless you are creating BLOb
|
|
116
|
+
* transactions.
|
|
117
|
+
*/
|
|
118
|
+
kzg?: null | KzgLibraryLike;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The [[link-eip-7594]] BLOb Wrapper Version used for PeerDAS.
|
|
122
|
+
*
|
|
123
|
+
* For networks that use EIP-7594, this property is required to
|
|
124
|
+
* serialize the sidecar correctly.
|
|
125
|
+
*/
|
|
126
|
+
blobWrapperVersion?: null | number;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The [[link-eip-7702]] authorizations (if any).
|
|
130
|
+
*/
|
|
131
|
+
authorizationList?: null | Array<AuthorizationLike>;
|
|
132
|
+
|
|
133
|
+
// Todo?
|
|
134
|
+
//gasMultiplier?: number;
|
|
135
|
+
};
|
package/src/safe-ops/index.ts
CHANGED
|
@@ -5,6 +5,8 @@ import {
|
|
|
5
5
|
SafeTransactionData,
|
|
6
6
|
} from "@safe-global/types-kit";
|
|
7
7
|
import { DeconstructedSafeSignature, DeconstructedSafeTx } from "./models";
|
|
8
|
+
import { TypedDataEncoder } from "ethers";
|
|
9
|
+
import { getSignedMessageHashFromKms } from "../kms-signing";
|
|
8
10
|
|
|
9
11
|
export const createSafeTx = async (
|
|
10
12
|
safe: Safe,
|
|
@@ -39,6 +41,52 @@ export const signSafeTx = async (
|
|
|
39
41
|
}
|
|
40
42
|
};
|
|
41
43
|
|
|
44
|
+
export const getReadOnlySafeInstance = async (
|
|
45
|
+
safeAddress: string,
|
|
46
|
+
rpcUrl: string
|
|
47
|
+
): Promise<Safe> => {
|
|
48
|
+
const safe = await Safe.init({
|
|
49
|
+
safeAddress,
|
|
50
|
+
provider: rpcUrl,
|
|
51
|
+
});
|
|
52
|
+
return safe;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const signSafeTxFromKms = async (safe: Safe, safeTx: SafeTransaction, signingServiceUrl: string): Promise<SafeTransaction> => {
|
|
56
|
+
try {
|
|
57
|
+
// Make an API call to the signing service endpoint to sign the safeTx message hash.
|
|
58
|
+
// We'll use fetch to POST to signingServiceUrl, sending { messageHash } in the body.
|
|
59
|
+
// Assume the signing service exposes an endpoint like POST /sign-message.
|
|
60
|
+
|
|
61
|
+
// First, get the transaction hash for this SafeTx:
|
|
62
|
+
const txHash = await safe.getTransactionHash(safeTx);
|
|
63
|
+
|
|
64
|
+
// Call the signing service with the txHash:
|
|
65
|
+
const { signer, signature } = await getSignedMessageHashFromKms(signingServiceUrl, txHash);
|
|
66
|
+
// The signing service responds with { signature }
|
|
67
|
+
|
|
68
|
+
safeTx.addSignature(new EthSafeSignature(signer, signature));
|
|
69
|
+
return safeTx;
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.log("error", error);
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
const getSafeTxHash = async (safe: Safe, safeTx: SafeTransaction) => {
|
|
80
|
+
try {
|
|
81
|
+
const txHash = await safe.getTransactionHash(safeTx);
|
|
82
|
+
console.log("txHash", txHash);
|
|
83
|
+
return txHash;
|
|
84
|
+
} catch (error) {
|
|
85
|
+
console.log("error", error);
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
42
90
|
export const getSafeInstance = async (
|
|
43
91
|
safeAddress: string,
|
|
44
92
|
privateKey: string,
|
|
@@ -49,9 +97,12 @@ export const getSafeInstance = async (
|
|
|
49
97
|
provider: rpcUrl,
|
|
50
98
|
signer: privateKey,
|
|
51
99
|
});
|
|
100
|
+
const safeProvider = safe.getSafeProvider();
|
|
101
|
+
console.log("safeProvider", safeProvider);
|
|
52
102
|
return safe;
|
|
53
103
|
};
|
|
54
104
|
|
|
105
|
+
|
|
55
106
|
export const deconstructSafeTx = async (
|
|
56
107
|
SafeTransaction: SafeTransaction
|
|
57
108
|
): Promise<{
|
|
@@ -62,6 +113,7 @@ export const deconstructSafeTx = async (
|
|
|
62
113
|
const safeTxElements: DeconstructedSafeTx = SafeTransaction.data;
|
|
63
114
|
const signatures: DeconstructedSafeSignature[] = [];
|
|
64
115
|
Array.from(SafeTransaction.signatures.entries()).forEach(([key, signature]) => {
|
|
116
|
+
console.log("[key, signature]: ", [key, signature]);
|
|
65
117
|
signatures.push({
|
|
66
118
|
signer: key,
|
|
67
119
|
signature: signature.data,
|
package/src/token/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Contract,
|
|
1
|
+
import { Contract, Provider, Wallet } from "ethers";
|
|
2
2
|
import { Token, TokenInfo } from "./models";
|
|
3
3
|
import { ERC20_ABI } from "./erc20-abi";
|
|
4
|
-
import { createSafeTx, getSafeInstance, signSafeTx } from "../safe-ops";
|
|
4
|
+
import { createSafeTx, getSafeInstance, signSafeTx, signSafeTxFromKms } from "../safe-ops";
|
|
5
5
|
import { SafeTransaction } from "@safe-global/types-kit";
|
|
6
6
|
import Safe from "@safe-global/protocol-kit";
|
|
7
7
|
|
|
@@ -63,7 +63,9 @@ export const getSignedTransferCalldataForSafe = async (
|
|
|
63
63
|
safeInstance: Safe,
|
|
64
64
|
tokenAddress: string,
|
|
65
65
|
recipientAddress: string,
|
|
66
|
-
amount: BigInt
|
|
66
|
+
amount: BigInt,
|
|
67
|
+
useKms: boolean,
|
|
68
|
+
signingServiceUrl?: string
|
|
67
69
|
): Promise<SafeTransaction> => {
|
|
68
70
|
if (tokenAddress === "0x0000000000000000000000000000000000000000") {
|
|
69
71
|
let safeTx = await createSafeTx(safeInstance, [
|
|
@@ -74,8 +76,11 @@ export const getSignedTransferCalldataForSafe = async (
|
|
|
74
76
|
operation: 0,
|
|
75
77
|
},
|
|
76
78
|
]);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
if (useKms && signingServiceUrl) {
|
|
80
|
+
safeTx = await signSafeTxFromKms(safeInstance, safeTx, signingServiceUrl);
|
|
81
|
+
} else {
|
|
82
|
+
safeTx = await signSafeTx(safeInstance, safeTx);
|
|
83
|
+
}
|
|
79
84
|
return safeTx;
|
|
80
85
|
} else {
|
|
81
86
|
const tokenContract = new Contract(tokenAddress, ERC20_ABI);
|
|
@@ -93,11 +98,17 @@ export const getSignedTransferCalldataForSafe = async (
|
|
|
93
98
|
},
|
|
94
99
|
]);
|
|
95
100
|
|
|
96
|
-
|
|
101
|
+
if (useKms && signingServiceUrl) {
|
|
102
|
+
safeTx = await signSafeTxFromKms(safeInstance, safeTx, signingServiceUrl);
|
|
103
|
+
} else {
|
|
104
|
+
safeTx = await signSafeTx(safeInstance, safeTx);
|
|
105
|
+
}
|
|
97
106
|
console.log("safeTx signed", safeTx);
|
|
98
107
|
return safeTx;
|
|
99
108
|
}
|
|
100
109
|
};
|
|
110
|
+
|
|
111
|
+
|
|
101
112
|
export const getDecimals = async (token: Token, provider: Provider) => {
|
|
102
113
|
const erc20 = new Contract(token.address, ERC20_ABI, provider);
|
|
103
114
|
const decimals = await erc20?.decimals?.();
|
package/Dockerfile.dev
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# Development Dockerfile
|
|
2
|
-
FROM node:20-slim
|
|
3
|
-
|
|
4
|
-
WORKDIR /app
|
|
5
|
-
|
|
6
|
-
# Copy package files
|
|
7
|
-
COPY package.json package-lock.json* ./
|
|
8
|
-
|
|
9
|
-
# Install dependencies (including dev deps for build)
|
|
10
|
-
RUN npm install
|
|
11
|
-
|
|
12
|
-
# Copy source code
|
|
13
|
-
COPY . .
|
|
14
|
-
|
|
15
|
-
# Build the project
|
|
16
|
-
RUN npm run build
|
|
17
|
-
|
|
18
|
-
# This is an SDK/library, so no CMD needed
|
|
19
|
-
# It can be used as a base image or extended by other services
|