vechain / connex

The mono-repo contains libraries to help build dApps for VeChain.
https://docs.vechain.org/developer-resources/sdks-and-providers/connex
GNU Lesser General Public License v3.0
86 stars 3.58k forks source link

allow specify signer in options #148

Closed libotony closed 1 year ago

libotony commented 1 year ago

This PR is on top of #147, changed the options to

export type Options = {
    /** the base url of the thor node's thorREST API */
    node: string
    /**
     * the expected network of the node url. defaults to 'main' if omitted.
     * if it does not match with the actual network of the node url points to,
     * all subsequent request will fail.
     */
    network?: 'main' | 'test' | Connex.Thor.Block

    /** 
     * designated signer, either builtin signer or a new signer function
     * defaults to sync2 if omitted
     */
    signer?: BuiltinSigner | Connex.NewSigner
}

Which makes developers explicitly declare the signer they wish to connect. Sync, Sync2, VeworldExteions or custom if signer creation function is supported.

new Connex({node: 'https://...', network: 'main'}) // defaults to sync2 
new Connex({node: 'https://...', network: 'main', signer: Connex.BuiltinSigner.Sync}) // sync or vechainthor mobile wallet
new Connex({node: 'https://...', network: 'main', signer: Connex.BuiltinSigner.Sync2}) // sync2
new Connex({node: 'https://...', network: 'main', signer: Connex.BuiltinSigner.VeworldExtension}) // veworld extension
new Connex({node: 'https://...', network: 'main', signer: (genesisId)=>{return CustomConnexSigner({genesisId: genesisId})}) 

There is also another option, which is to enforce the signer as a arguments in the construction API

constructor(opts: Options, signer: BuiltinSigner | Connex.NewSigner = BuiltinSigner.Sync2)

new Connex({node: 'https://...', network: 'main'}, Connex.BuiltinSigner.VeworldExtension)
new Connex.Vendor('main', Connex.BuiltinSigner.Sync2)
claytonneal commented 1 year ago

hiya, this could be interesting for mocking, to be able have a custom signer function

libotony commented 1 year ago

Replaced by #153