@gelatonetwork/relay-sdk
Advanced tools
Comparing version 3.2.1 to 3.3.0
@@ -26,3 +26,3 @@ import { BigNumber, ethers } from "ethers"; | ||
* @param {SponsoredCallERC2771Request} request - SponsoredCallERC2771Request to be relayed by Gelato Executors | ||
* @param {ethers.providers.Web3Provider} provider - Web3Provider to sign the payload | ||
* @param {ethers.providers.Web3Provider | ethers.Wallet} walletOrProvider - Web3Provider [front-end] or Wallet [back-end] to sign the payload | ||
* @param {string} sponsorApiKey - Sponsor API key | ||
@@ -33,10 +33,10 @@ * @param {RelayRequestOptions} [options] - Optional Relay configuration | ||
*/ | ||
sponsoredCallERC2771: (request: SponsoredCallERC2771Request, provider: ethers.providers.Web3Provider, sponsorApiKey: string, options?: RelayRequestOptions | undefined) => Promise<RelayResponse>; | ||
sponsoredCallERC2771: (request: SponsoredCallERC2771Request, walletOrProvider: ethers.providers.Web3Provider | ethers.Wallet, sponsorApiKey: string, options?: RelayRequestOptions | undefined) => Promise<RelayResponse>; | ||
/** | ||
* @param {SponsoredCallERC2771Request} request - SponsoredCallERC2771Request to be relayed by Gelato Executors | ||
* @param {ethers.providers.Web3Provider} provider - Web3Provider to sign the payload | ||
* @param {ethers.providers.Web3Provider | ethers.Wallet} walletOrProvider - Web3Provider [front-end] or Wallet [back-end] to sign the payload | ||
* @returns {Promise<SignatureData>} Response object with taskId parameter | ||
* | ||
*/ | ||
getSignatureDataERC2771: (request: SponsoredCallERC2771Request, provider: ethers.providers.Web3Provider) => Promise<SignatureData>; | ||
getSignatureDataERC2771: (request: SponsoredCallERC2771Request, walletOrProvider: ethers.providers.Web3Provider | ethers.Wallet) => Promise<SignatureData>; | ||
/** | ||
@@ -43,0 +43,0 @@ * @param {SignatureData["struct"]} struct - Struct that can be obtained from getSignatureDataERC2771 |
@@ -44,3 +44,3 @@ "use strict"; | ||
* @param {SponsoredCallERC2771Request} request - SponsoredCallERC2771Request to be relayed by Gelato Executors | ||
* @param {ethers.providers.Web3Provider} provider - Web3Provider to sign the payload | ||
* @param {ethers.providers.Web3Provider | ethers.Wallet} walletOrProvider - Web3Provider [front-end] or Wallet [back-end] to sign the payload | ||
* @param {string} sponsorApiKey - Sponsor API key | ||
@@ -51,10 +51,10 @@ * @param {RelayRequestOptions} [options] - Optional Relay configuration | ||
*/ | ||
this.sponsoredCallERC2771 = (request, provider, sponsorApiKey, options) => library.relayWithSponsoredCallERC2771(request, provider, sponsorApiKey, options); | ||
this.sponsoredCallERC2771 = (request, walletOrProvider, sponsorApiKey, options) => library.relayWithSponsoredCallERC2771(request, walletOrProvider, sponsorApiKey, options); | ||
/** | ||
* @param {SponsoredCallERC2771Request} request - SponsoredCallERC2771Request to be relayed by Gelato Executors | ||
* @param {ethers.providers.Web3Provider} provider - Web3Provider to sign the payload | ||
* @param {ethers.providers.Web3Provider | ethers.Wallet} walletOrProvider - Web3Provider [front-end] or Wallet [back-end] to sign the payload | ||
* @returns {Promise<SignatureData>} Response object with taskId parameter | ||
* | ||
*/ | ||
this.getSignatureDataERC2771 = (request, provider) => library.getSignatureDataERC2771(request, provider); | ||
this.getSignatureDataERC2771 = (request, walletOrProvider) => library.getSignatureDataERC2771(request, walletOrProvider); | ||
/** | ||
@@ -61,0 +61,0 @@ * @param {SignatureData["struct"]} struct - Struct that can be obtained from getSignatureDataERC2771 |
import { ethers } from "ethers"; | ||
import { SignatureData, SponsoredCallERC2771Request } from "../types"; | ||
export declare const getSignatureDataERC2771: (request: SponsoredCallERC2771Request, provider: ethers.providers.Web3Provider) => Promise<SignatureData>; | ||
export declare const getSignatureDataERC2771: (request: SponsoredCallERC2771Request, walletOrProvider: ethers.providers.Web3Provider | ethers.Wallet) => Promise<SignatureData>; |
@@ -16,4 +16,7 @@ "use strict"; | ||
const utils_2 = require("../utils"); | ||
const getSignatureDataERC2771 = (request, provider) => __awaiter(void 0, void 0, void 0, function* () { | ||
const getSignatureDataERC2771 = (request, walletOrProvider) => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
if (!walletOrProvider.provider) { | ||
throw new Error(`Missing provider`); | ||
} | ||
const isSupported = yield (0, network_1.isNetworkSupported)(Number(request.chainId)); | ||
@@ -23,5 +26,5 @@ if (!isSupported) { | ||
} | ||
const parametersToOverride = yield (0, utils_1.populateOptionalUserParameters)(request, provider); | ||
const parametersToOverride = yield (0, utils_1.populateOptionalUserParameters)(request, walletOrProvider); | ||
const struct = yield (0, utils_2.mapRequestToStruct)(request, parametersToOverride); | ||
const signature = yield (0, utils_1.signTypedDataV4)(provider, request.user, (0, utils_2.getPayloadToSign)(struct)); | ||
const signature = yield (0, utils_1.signTypedDataV4)(walletOrProvider, request.user, (0, utils_2.getPayloadToSign)(struct, (0, utils_1.isWallet)(walletOrProvider))); | ||
return { | ||
@@ -28,0 +31,0 @@ struct, |
import { ethers } from "ethers"; | ||
import { RelayRequestOptions, RelayResponse } from "../../types"; | ||
import { SponsoredCallERC2771Request } from "../types"; | ||
export declare const relayWithSponsoredCallERC2771: (request: SponsoredCallERC2771Request, provider: ethers.providers.Web3Provider, sponsorApiKey: string, options?: RelayRequestOptions | undefined) => Promise<RelayResponse>; | ||
export declare const relayWithSponsoredCallERC2771: (request: SponsoredCallERC2771Request, walletOrProvider: ethers.providers.Web3Provider | ethers.Wallet, sponsorApiKey: string, options?: RelayRequestOptions | undefined) => Promise<RelayResponse>; |
@@ -17,8 +17,11 @@ "use strict"; | ||
const utils_2 = require("../utils"); | ||
const relayWithSponsoredCallERC2771 = (request, provider, sponsorApiKey, options) => __awaiter(void 0, void 0, void 0, function* () { | ||
return yield sponsoredCallERC2771(request, provider, sponsorApiKey, options); | ||
const relayWithSponsoredCallERC2771 = (request, walletOrProvider, sponsorApiKey, options) => __awaiter(void 0, void 0, void 0, function* () { | ||
return yield sponsoredCallERC2771(request, walletOrProvider, sponsorApiKey, options); | ||
}); | ||
exports.relayWithSponsoredCallERC2771 = relayWithSponsoredCallERC2771; | ||
const sponsoredCallERC2771 = (request, provider, sponsorApiKey, options) => __awaiter(void 0, void 0, void 0, function* () { | ||
const sponsoredCallERC2771 = (request, walletOrProvider, sponsorApiKey, options) => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
if (!walletOrProvider.provider) { | ||
throw new Error(`Missing provider`); | ||
} | ||
const isSupported = yield (0, network_1.isNetworkSupported)(Number(request.chainId)); | ||
@@ -28,5 +31,5 @@ if (!isSupported) { | ||
} | ||
const parametersToOverride = yield (0, utils_1.populateOptionalUserParameters)(request, provider); | ||
const parametersToOverride = yield (0, utils_1.populateOptionalUserParameters)(request, walletOrProvider); | ||
const struct = yield (0, utils_2.mapRequestToStruct)(request, parametersToOverride); | ||
const signature = yield (0, utils_1.signTypedDataV4)(provider, request.user, (0, utils_2.getPayloadToSign)(struct)); | ||
const signature = yield (0, utils_1.signTypedDataV4)(walletOrProvider, request.user, (0, utils_2.getPayloadToSign)(struct, (0, utils_1.isWallet)(walletOrProvider))); | ||
const postResponse = yield (0, utils_1.postSponsoredCall)(types_1.RelayCall.SponsoredCallERC2771, Object.assign(Object.assign(Object.assign({}, struct), options), { userSignature: signature, sponsorApiKey })); | ||
@@ -33,0 +36,0 @@ return postResponse; |
@@ -15,3 +15,3 @@ import { BigNumberish, BytesLike } from "ethers"; | ||
types: { | ||
EIP712Domain: { | ||
EIP712Domain?: { | ||
name: string; | ||
@@ -25,3 +25,3 @@ type: string; | ||
}; | ||
primaryType: "SponsoredCallERC2771"; | ||
primaryType?: "SponsoredCallERC2771"; | ||
message: SponsoredCallERC2771Struct; | ||
@@ -28,0 +28,0 @@ }; |
import { SponsoredCallERC2771PayloadToSign, SponsoredCallERC2771Struct } from "../types"; | ||
export declare const getPayloadToSign: (struct: SponsoredCallERC2771Struct) => SponsoredCallERC2771PayloadToSign; | ||
export declare const getPayloadToSign: (struct: SponsoredCallERC2771Struct, isWallet: boolean) => SponsoredCallERC2771PayloadToSign; |
@@ -7,4 +7,11 @@ "use strict"; | ||
const types_2 = require("../types"); | ||
const getPayloadToSign = (struct) => { | ||
const getPayloadToSign = (struct, isWallet) => { | ||
const domain = (0, utils_1.getEIP712Domain)(struct.chainId); | ||
if (isWallet) { | ||
return { | ||
domain, | ||
types: Object.assign({}, types_2.EIP712_SPONSORED_CALL_ERC2771_TYPE_DATA), | ||
message: struct, | ||
}; | ||
} | ||
return { | ||
@@ -11,0 +18,0 @@ domain, |
@@ -1,2 +0,2 @@ | ||
import { ethers, providers } from "ethers"; | ||
export declare const getUserNonce: (account: string, provider: providers.Web3Provider | ethers.providers.Provider) => Promise<any>; | ||
import { ethers } from "ethers"; | ||
export declare const getUserNonce: (account: string, walletOrProvider: ethers.providers.Web3Provider | ethers.Wallet) => Promise<any>; |
@@ -15,6 +15,6 @@ "use strict"; | ||
const constants_1 = require("../constants"); | ||
const getUserNonce = (account, provider) => __awaiter(void 0, void 0, void 0, function* () { | ||
const contract = new ethers_1.ethers.Contract(constants_1.GELATO_RELAY_ERC2771_ADDRESS, constants_1.USER_NONCE_ABI, provider); | ||
const getUserNonce = (account, walletOrProvider) => __awaiter(void 0, void 0, void 0, function* () { | ||
const contract = new ethers_1.ethers.Contract(constants_1.GELATO_RELAY_ERC2771_ADDRESS, constants_1.USER_NONCE_ABI, walletOrProvider); | ||
return yield contract.userNonce(account); | ||
}); | ||
exports.getUserNonce = getUserNonce; |
@@ -8,1 +8,2 @@ export * from "./signTypedDataV4"; | ||
export * from "./postAuthCall"; | ||
export * from "./isWallet"; |
@@ -20,1 +20,2 @@ "use strict"; | ||
__exportStar(require("./postAuthCall"), exports); | ||
__exportStar(require("./isWallet"), exports); |
@@ -1,3 +0,3 @@ | ||
import { ethers, providers } from "ethers"; | ||
import { ethers } from "ethers"; | ||
import { SponsoredCallERC2771Request, SponsoredCallERC2771RequestOptionalParameters } from "../lib/erc2771/types"; | ||
export declare const populateOptionalUserParameters: <Request extends SponsoredCallERC2771Request, OptionalParameters extends SponsoredCallERC2771RequestOptionalParameters>(request: Request, provider: providers.Web3Provider | ethers.providers.Provider) => Promise<Partial<OptionalParameters>>; | ||
export declare const populateOptionalUserParameters: <Request extends SponsoredCallERC2771Request, OptionalParameters extends SponsoredCallERC2771RequestOptionalParameters>(request: Request, walletOrProvider: ethers.providers.Web3Provider | ethers.Wallet) => Promise<Partial<OptionalParameters>>; |
@@ -17,3 +17,3 @@ "use strict"; | ||
const getUserNonce_1 = require("./getUserNonce"); | ||
const populateOptionalUserParameters = (request, provider) => __awaiter(void 0, void 0, void 0, function* () { | ||
const populateOptionalUserParameters = (request, walletOrProvider) => __awaiter(void 0, void 0, void 0, function* () { | ||
const parametersToOverride = {}; | ||
@@ -24,3 +24,3 @@ if (!request.userDeadline) { | ||
if (!request.userNonce) { | ||
parametersToOverride.userNonce = ethers_1.BigNumber.from((yield (0, getUserNonce_1.getUserNonce)(request.user, provider)).toNumber()).toString(); | ||
parametersToOverride.userNonce = ethers_1.BigNumber.from((yield (0, getUserNonce_1.getUserNonce)(request.user, walletOrProvider)).toNumber()).toString(); | ||
} | ||
@@ -27,0 +27,0 @@ return parametersToOverride; |
@@ -1,3 +0,3 @@ | ||
import { providers } from "ethers"; | ||
import { ethers } from "ethers"; | ||
import { SponsoredCallERC2771PayloadToSign } from "../lib/erc2771/types"; | ||
export declare const signTypedDataV4: (provider: providers.Web3Provider, address: string, payload: SponsoredCallERC2771PayloadToSign) => Promise<string>; | ||
export declare const signTypedDataV4: (walletOrProvider: ethers.providers.Web3Provider | ethers.Wallet, address: string, payload: SponsoredCallERC2771PayloadToSign) => Promise<string>; |
@@ -14,8 +14,12 @@ "use strict"; | ||
const constants_1 = require("../constants"); | ||
const signTypedDataV4 = (provider, address, payload) => __awaiter(void 0, void 0, void 0, function* () { | ||
const isWallet_1 = require("./isWallet"); | ||
const signTypedDataV4 = (walletOrProvider, address, payload) => __awaiter(void 0, void 0, void 0, function* () { | ||
if ((0, isWallet_1.isWallet)(walletOrProvider)) { | ||
return yield walletOrProvider._signTypedData(payload.domain, payload.types, payload.message); | ||
} | ||
// Magic Connect accepts payload as an object | ||
if (provider.provider.isMagic) { | ||
return yield provider.send(constants_1.SIGN_TYPED_DATA_V4, [address, payload]); | ||
if (walletOrProvider.provider.isMagic) { | ||
return yield walletOrProvider.send(constants_1.SIGN_TYPED_DATA_V4, [address, payload]); | ||
} | ||
const signature = yield provider.send(constants_1.SIGN_TYPED_DATA_V4, [ | ||
const signature = yield walletOrProvider.send(constants_1.SIGN_TYPED_DATA_V4, [ | ||
address, | ||
@@ -22,0 +26,0 @@ JSON.stringify(payload), |
{ | ||
"name": "@gelatonetwork/relay-sdk", | ||
"version": "3.2.1", | ||
"version": "3.3.0", | ||
"description": "SDK to integrate with Gelato Relay", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56520
60
1013