Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(relayer-signer): Predefine auth config type for relayer signer c… #599

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions examples/relayer-call-contract-function/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require('dotenv').config();

const { ethers, version } = require('ethers');
const BoxAbi = require('./box.json');
const { Defender } = require('@openzeppelin/defender-sdk');
const { Relayer } = require('@openzeppelin/defender-sdk-relay-signer-client');

function sleep(ms) {
return new Promise((resolve) => {
Expand All @@ -12,16 +12,16 @@ function sleep(ms) {

async function main() {
const creds = {
relayerApiKey: process.env.RELAYER_API_KEY,
relayerApiSecret: process.env.RELAYER_API_SECRET,
apiKey: process.env.RELAYER_API_KEY,
apiSecret: process.env.RELAYER_API_SECRET,
};
const validUntil = new Date(Date.now() + 120 * 1000).toISOString();

const client = new Defender(creds);
const client = new Relayer(creds);
console.log('using ethers version ', version);

const provider = client.relaySigner.getProvider({ ethersVersion: 'v6' });
const signer = await client.relaySigner.getSigner(provider, { speed: 'fast', validUntil, ethersVersion: 'v6' });
const provider = client.getProvider({ ethersVersion: 'v6' });
const signer = await client.getSigner(provider, { speed: 'fast', validUntil, ethersVersion: 'v6' });

const contractAddress = '0x1B9ec5Cc45977927fe6707f2A02F51e1415f2052';
const contract = new ethers.Contract(contractAddress, BoxAbi, signer);
Expand Down
2 changes: 1 addition & 1 deletion examples/relayer-call-contract-function/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"start": "node index.js"
},
"dependencies": {
"@openzeppelin/defender-sdk": "1.15.0",
"@openzeppelin/defender-sdk-relay-signer-client": "1.15.0",
"dotenv": "^16.3.1",
"ethers": "^6.9.0"
}
Expand Down
11 changes: 10 additions & 1 deletion packages/relay-signer/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,23 @@ import {
} from '../models/transactions';
import { JsonRpcResponse, SignMessagePayload, SignTypedDataPayload, SignedMessagePayload } from '../models/rpc';
import { AuthType } from '@openzeppelin/defender-sdk-base-client/lib/api/auth-v2';
import { isUndefined } from 'lodash';

export const getApiUrl = () => process.env.DEFENDER_API_URL || 'https://defender-api.openzeppelin.com/';

export class RelaySignerClient extends BaseApiClient implements IRelayer {
private jsonRpcRequestNextId: number;

public constructor(params: ApiRelayerParams) {
super(params);
super({
...params,
authConfig: {
type: 'relay',
useCredentialsCaching: isUndefined(params?.authConfig?.useCredentialsCaching)
? true
: params.authConfig.useCredentialsCaching,
},
});
this.jsonRpcRequestNextId = 1;
}

Expand Down
Loading