File tree Expand file tree Collapse file tree
examples/address-book-actions Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ require ( 'dotenv' ) . config ( ) ;
2+ import { Defender } from '@openzeppelin/defender-sdk' ;
3+
4+ // Default timeout is not enough, using 15s timeout instead.
5+ jest . setTimeout ( 15 * 1000 ) ;
6+
7+ describe ( 'address-book' , ( ) => {
8+ const addressBookClient = new Defender ( {
9+ apiKey : process . env . API_KEY ,
10+ apiSecret : process . env . API_SECRET ,
11+ } ) . addressBook ;
12+
13+ it ( 'should list addresses' , async ( ) => {
14+ const result = await addressBookClient . list ( ) ;
15+ expect ( result ) . toBeDefined ( ) ;
16+ } ) ;
17+
18+ it ( 'should create and delete an address' , async ( ) => {
19+ const result = await addressBookClient . create ( {
20+ address : '0x1234567890123456789012345678901234567890' ,
21+ network : 'mainnet' ,
22+ type : 'EOA' ,
23+ alias : 'My Address' ,
24+ } ) ;
25+ expect ( result . addressBookId ) . toBe ( 'mainnet|0x1234567890123456789012345678901234567890' ) ;
26+
27+ const deleteResult = await addressBookClient . delete ( result . addressBookId ) ;
28+ expect ( deleteResult . message ) . toBe ( 'mainnet|0x1234567890123456789012345678901234567890 deleted' ) ;
29+ } ) ;
30+ } ) ;
Original file line number Diff line number Diff line change 1+ require ( 'dotenv' ) . config ( ) ;
2+
3+ const { Defender } = require ( '@openzeppelin/defender-sdk' ) ;
4+
5+ async function main ( ) {
6+ const client = new Defender ( {
7+ apiKey : process . env . API_KEY ,
8+ apiSecret : process . env . API_SECRET ,
9+ } ) ;
10+
11+ const addresses = await client . addressBook . list ( ) ;
12+ console . log ( 'addresses:' , addresses ) ;
13+
14+ const created = await client . addressBook . create ( {
15+ address : '0x1A8943463a20f55B8BC7a318dB77C4AEDBC3fae6' ,
16+ name : 'My EOA Address' ,
17+ network : 'sepolia' ,
18+ type : 'EOA' ,
19+ alias : 'Deployer EOA address' ,
20+ } ) ;
21+ console . log ( 'created address:' , created ) ;
22+
23+ const deleteRes = await client . addressBook . delete ( created . addressBookId ) ;
24+ console . log ( deleteRes ) ;
25+ }
26+
27+ if ( require . main === module ) {
28+ main ( ) . catch ( console . error ) ;
29+ }
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " @openzeppelin/defender-sdk-example-address-book-actions" ,
3+ "version" : " 1.14.4" ,
4+ "private" : true ,
5+ "main" : " index.js" ,
6+ "author" : " OpenZeppelin Defender <defender@openzeppelin.com>" ,
7+ "license" : " MIT" ,
8+ "scripts" : {
9+ "start" : " node index.js"
10+ },
11+ "dependencies" : {
12+ "@openzeppelin/defender-sdk" : " 1.15.0" ,
13+ "dotenv" : " ^16.3.1"
14+ }
15+ }
Original file line number Diff line number Diff line change 1+ # Defender SDK Address Book Client
2+
3+ The OpenZeppelin Defender provides a security operations (SecOps) platform for Ethereum with built-in best practices. Development teams implement Defender to ship faster and minimize security risks.
4+
5+ This library provides methods related to address book. See Examples for usage.
Original file line number Diff line number Diff line change 1+ module . exports = require ( '../../jest.config' ) ;
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " @openzeppelin/defender-sdk-address-book-client" ,
3+ "version" : " 1.15.0" ,
4+ "description" : " " ,
5+ "main" : " ./lib/index.js" ,
6+ "types" : " ./lib/index.d.ts" ,
7+ "scripts" : {
8+ "build" : " rm -rf lib && tsc" ,
9+ "test" : " npm run test:unit" ,
10+ "test:unit" : " jest --verbose --passWithNoTests --forceExit" ,
11+ "watch" : " tsc -w"
12+ },
13+ "files" : [
14+ " lib" ,
15+ " !*.test.js" ,
16+ " !*.test.js.map" ,
17+ " !*.test.d.ts" ,
18+ " !*__mocks__"
19+ ],
20+ "author" : " OpenZeppelin Defender <defender@openzeppelin.com>" ,
21+ "license" : " MIT" ,
22+ "dependencies" : {
23+ "@openzeppelin/defender-sdk-base-client" : " ^1.15.0" ,
24+ "lodash" : " ^4.17.21" ,
25+ "dotenv" : " ^16.3.1"
26+ },
27+ "publishConfig" : {
28+ "access" : " public"
29+ }
30+ }
Original file line number Diff line number Diff line change 1+ import { BaseApiClient } from '@openzeppelin/defender-sdk-base-client' ;
2+ import { AddressBookResponse , CreateAddressBookRequest } from '../models/address-book' ;
3+
4+ const PATH = '/address-book' ;
5+
6+ export class AddressBookClient extends BaseApiClient {
7+ protected getPoolId ( ) : string {
8+ return process . env . DEFENDER_POOL_ID ?? 'us-west-2_94f3puJWv' ;
9+ }
10+
11+ protected getPoolClientId ( ) : string {
12+ return process . env . DEFENDER_POOL_CLIENT_ID ?? '40e58hbc7pktmnp9i26hh5nsav' ;
13+ }
14+
15+ protected getApiUrl ( ) : string {
16+ return process . env . DEFENDER_API_URL ?? 'https://defender-api.openzeppelin.com/' ;
17+ }
18+
19+ public async list ( ) : Promise < AddressBookResponse [ ] > {
20+ return this . apiCall ( async ( api ) => api . get ( `${ PATH } ` ) ) ;
21+ }
22+
23+ public async create ( address : CreateAddressBookRequest ) : Promise < AddressBookResponse > {
24+ return this . apiCall ( async ( api ) => api . post ( `${ PATH } ` , address ) ) ;
25+ }
26+
27+ public async delete ( addressBookId : string ) : Promise < { message : string } > {
28+ const encodedId = encodeURIComponent ( addressBookId ) ;
29+ return this . apiCall ( async ( api ) => api . delete ( `${ PATH } /${ encodedId } ` ) ) ;
30+ }
31+ }
Original file line number Diff line number Diff line change 1+ export { AddressBookClient } from './api' ;
2+ export { AddressBookResponse } from './models/address-book' ;
3+
4+ // eslint-disable-next-line @typescript-eslint/no-var-requires
5+ export const VERSION = require ( '../package.json' ) . version ;
Original file line number Diff line number Diff line change 1+ export type AddressType =
2+ | 'EOA'
3+ | 'Contract'
4+ | 'Multisig'
5+ | 'Gnosis Safe'
6+ | 'Safe'
7+ | 'Gnosis Multisig'
8+ | 'Relayer'
9+ | 'Unknown'
10+ | 'Timelock Controller'
11+ | 'ERC20'
12+ | 'Governor'
13+ | 'Fireblocks' ;
14+
15+ export type AddressBookResponse = {
16+ addressBookId : string ;
17+ address : string ;
18+ network : string ;
19+ type : AddressType ;
20+ alias : string ;
21+ } ;
22+
23+ export type CreateAddressBookRequest = {
24+ address : string ;
25+ network : string ;
26+ type : AddressType ;
27+ alias ?: string ;
28+ symbol ?: string ;
29+ decimals ?: number ;
30+ } ;
Original file line number Diff line number Diff line change 1+ {
2+ "extends" : " code-style/tsconfig.json" ,
3+ "compilerOptions" : {
4+ "declaration" : true ,
5+ "outDir" : " ./lib" ,
6+ "skipLibCheck" : true ,
7+ "sourceMap" : false
8+ },
9+ "include" : [" ./src" ],
10+ "exclude" : [" **/*.test.ts" , " **/__mocks__/*" ]
11+ }
You can’t perform that action at this time.
0 commit comments