@prifilabs/shield-ethereum-js
v0.6.1
Published
The Shield - customizable smart contract protection
Downloads
6
Readme
The Shield
API
Core functions
getDefaultFactory(signer: ethers.Signer, network: string): Promise<ethers.Contract>
: returns the Shield Factory contract deployed onnetwork
createShield(signer: ethers.Signer, name: string, roles: any[], users: any[], policy: any[], factory: ethers.Contract): Promise<{receipt: ethers.Transaction, shield: Shield}>
: deploys a shield and returns the corresponding shield object (see below)instantiateShield(signer: ethers.Signer, address: string): Promise<Shield>
: returns a shield object (see below) of an existing deployed shield ataddress
getShields(signer: ethers.Signer, factory: ethers.Contract): Promise<{ [address: string]: string }>
: returns the list of shield's addresses for which the useraddress
is one of the users
Methods of the Shield
object
Shield getters
getRoles(): Promise<string[]>
getUsers(): Promise<{[address: string]: string[]}>
getUser(address: string): Promise<string[]>
getPolicies(): Promise<{[label: string]: string[][]}>
getPolicy(label: string): Promise<string[][]>
getAssignedPolicies(): Promise<{[address: string]: {[func: string]: string}}>
getAssignedPolicy(to: string, func: string): Promise<string>
isPaused(): Promise<boolean>
getTransactionHash(credentials: Credentials): Promise<string>
Handling Shieldables
getShieldables(): Promise<string[]>
addInterface(address: string, iface: ethers.utils.Interface)
getInterface(address: string): Promise<ethers.utils.Interface>
Handling Credentials
getCredentials(): Promise<Array<Credentials>>
createCredentials(to: string, func: string, args: any[]): Promise<Credentials>
: returns a new credentials to call the functionfunc
from the contractto
with the argsargs
.approveCredentials(credentials: Credentials): Promise<Credentials>
: returns a newly approved credentialscheckCredentials(credentials: Credentials, full?: boolean):Promise<{to: string, func: string, args:any[], timestamp:number, approvals: string[]}>
executeCredentials(credentials: Credentials)
execute the credentialscancelCredentials(credentials: Credentials): Promise<ethers.Transaction>
isExecuted(credentials: Credentials):Promise<boolean>
isCanceled(credentials: Credentials):Promise<boolean>
createCredentials
wrappers
createCredentialsForAddRoles(roles: string[]): Promise<Credentials>
createCredentialsForSetUsers(users: Array<{ address: string; roles: string[] }>): Promise<Credentials>
createCredentialsForAddPolicy(label: string, policy: string[][]): Promise<Credentials>
createCredentialsForAssignPolicy(to: address, func: string, label: string)
createCredentialsForPause(): Promise<Credentials>
createCredentialsForUnpause()
Utils
Utils.signData(signer: Signer, types: string[], values: any[])
Utils.getSigner(types: string[], values: any[], signature: string)
Utils.encodeCredentials(credentials: Credentials): string
: returns the base-64 encoded version of credentialsUtils.decodeCredentials(encodedCredentials: string): Credential
returns the decoded credentials of the base-64 encoded stringUtils.getSignature(func, iface)
Utils.getFunction(sig, iface)
Utils.encodeCallData(func, args, iface)
Utils.decodeCallData(call, iface)
Utils.getBytesFromRoles(roles: any[], allRoles: any[])
Utils.getRolesFromBytes(bytes: any, allRoles: any[])