transactions

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2025 License: Apache-2.0 Imports: 11 Imported by: 1

README

go-transactions

Go SDK for DIMO transactions

Limitations

  • Only small amount of DIMO protocol transactions is currently implemented
  • Requires already deployed AA wallet
  • Works only with entrypoint 0.7 and Kernel 3.1.0 accounts

Usage

Client creation
import (
    "github.com/DIMO-Network/go-transactions"
    "github.com/DIMO-Network/go-zerodev"
)

clientConfig := transactions.ClientConfig{
    AccountAddress:           <DEFAULT_SENDER_AA_WALLET_ADDRESS>,
    AccountPK:                <DEFAULT_SENDER_PK>,
    RpcURL:                   <RPC_URL>,
    PaymasterURL:             <PAYMASTER_URL>,
    BundlerURL:               <BUNDLER_URL>,
    ChainID:                  <CHAIN_ID>,
    RegistryAddress:          <DIMO_REGISTRY_CONTRACT_ADDRESS>,
    VehicleIdAddress:         <DIMO_VEHICLE_ID_CONTRACT_ADDRESS>,
    SyntheticDeviceIdAddress: <DIMO_SYNTHETIC_DEVICE_ID_CONTRACT_ADDRESS>,
}

client, err := transactions.NewClient(&clientConfig)
defer client.Close()
if err != nil {
    panic(err)
}
Wallet-based transactions

Those transactions are sent on behalf of the configured default AA wallet. Some of them require specific roles granted.

Minting a Vehicle ID
result, err := client.MintVehicleWithDdInput(<MINT_VEHIICLE_WITH_DD_INPUT>)
if err != nil {
    panic(err)
}

fmt.Println(hexutil.Encode(*result.TxHash))
Minting a Vehicle ID with Synthetic Device
vehicleToMint := <VEHICLE_TO_MINT_INPUT>

// Get TypedData for signing by SD Wallet	
typedSd := client.GetMintVehicleAndSdTypedData(...)

// Sign with SD Wallet
sdSignature := <SD_SIGNATURE>

// Add to payload
vehicleToMint.SyntheticDeviceSig = sdSignature

// Get TypedData for signing by Vehicle owner	
typedV := client.GetMintVehicleWithDeviceDefinitionTypedData(...)

// Sign with the owner
ownerSignature := <OWNER_SIGNATURE>

// Add to payload
vehicleToMint.VehicleOwnerSig = ownerSignature

// Mint the vehicle
result, err = client.MintVehicleAndSdWithDdInput(vehicleToMint)
if err != nil {
    panic(err)
}

fmt.Println(hexutil.Encode(*result.TxHash))
Minting Vehicle IDs with Synthetic Devices in batches

TODO

User-based transactions

Those transactions are sent on behalf of the user (e.g. Vehicle owner). They have to be signed by the User's AA.

Burn Vehicle ID by owner
// Get the UserOperation and its hash to sign
op, hash, err := client.GetBurnVehicleByOwnerUserOperationAndHash(ownerAAAddress, <Vehicle TokenID>)
if err != nil {
    panic(err)
}

// Get hash signature from the owner
signature := <USER_SIGNATURE>

// Add signature to UserOperation
op.Signature = signature

// Send updated UserOperation
result, err = client.SendSignedUserOperation(op)
if err != nil {
    panic(err)
}


fmt.Println(hexutil.Encode(*result.TxHash))
Burn Synthetic Device by owner
// Get the UserOperation and its hash to sign
op, hash, err := client.GetBurnSdByOwnerUserOperationAndHash(ownerAAAddress, <Synthetic Device TokenID>)
if err != nil {
    panic(err)
}

// Get hash signature from the owner
signature := <USER_SIGNATURE>

// Add signature to UserOperation
op.Signature = signature

// Send updated UserOperation
result, err = client.SendSignedUserOperation(op)
if err != nil {
    panic(err)
}


fmt.Println(hexutil.Encode(*result.TxHash))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	RegistryAddress          common.Address
	VehicleIdAddress         common.Address
	SyntheticDeviceIdAddress common.Address
	Registry                 *registry.Registry
	VehicleId                *vehicleid.Vehicleid
	SyntheticDeviceId        *sdid.Sdid
	ZerodevClient            *zerodev.Client
}

func NewClient

func NewClient(config *ClientConfig) (*Client, error)

func (*Client) Close

func (c *Client) Close()

func (*Client) ExecuteUserOperation

func (c *Client) ExecuteUserOperation(callData []byte) (result *zerodev.UserOperationResult, err error)

func (*Client) GetBurnSdByOwnerUserOperationAndHash

func (c *Client) GetBurnSdByOwnerUserOperationAndHash(owner common.Address, syntheticDeviceTokenId *big.Int) (op *zerodev.UserOperation, hash *common.Hash, err error)

func (*Client) GetBurnSdTypedData

func (c *Client) GetBurnSdTypedData(vehicleNode *big.Int, syntheticDeviceNode *big.Int) *signer.TypedData

GetBurnSdTypedData generates TypedData for signing by Vehicle owner whenever SD is being burned

func (*Client) GetBurnVehicleByOwnerUserOperationAndHash

func (c *Client) GetBurnVehicleByOwnerUserOperationAndHash(owner common.Address, vehicleTokenId *big.Int) (op *zerodev.UserOperation, hash *common.Hash, err error)

func (*Client) GetMintVehicleAndSdTypedData

func (c *Client) GetMintVehicleAndSdTypedData(integrationNode *big.Int) *signer.TypedData

GetMintVehicleAndSdTypedData generates TypedData for signing by Synthetic Device (SD) whenever Vehicle with SD is minted

func (*Client) GetMintVehicleWithDeviceDefinitionTypedData

func (c *Client) GetMintVehicleWithDeviceDefinitionTypedData(manufacturerNode *big.Int, owner common.Address, deviceDefinitionId string, attributeInfoPairs []registry.AttributeInfoPair) *signer.TypedData

GetMintVehicleWithDeviceDefinitionTypedData generates TypedData for signing by Vehicle owner whenever Vehicle with Device Definition is minted

func (*Client) MintVehicleAndSdWithDdInput

func (c *Client) MintVehicleAndSdWithDdInput(data *registry.MintVehicleAndSdWithDdInput) (result *zerodev.UserOperationResult, err error)

MintVehicleAndSdWithDdInput mints a vehicle and paired synthetic device using data with a device definition. Requires SD signature of typed data returned by GetMintVehicleAndSdTypedData Requires Vehicle Owner signature of typed data returned by GetMintVehicleWithDeviceDefinitionTypedData

func (*Client) MintVehicleAndSdWithDdInputAndSacd

func (c *Client) MintVehicleAndSdWithDdInputAndSacd(data *registry.MintVehicleAndSdWithDdInput, sacdInput registry.SacdInput) (result *zerodev.UserOperationResult, err error)

MintVehicleAndSdWithDdInputAndSacd mints a vehicle and paired synthetic device using data with a device definition and separate SACD. Requires SD signature of typed data returned by GetMintVehicleAndSdTypedData Requires Vehicle Owner signature of typed data returned by GetMintVehicleWithDeviceDefinitionTypedData

func (*Client) MintVehicleAndSdWithDdInputBatch

func (c *Client) MintVehicleAndSdWithDdInputBatch(data []registry.MintVehicleAndSdWithDdInputBatch) (result *zerodev.UserOperationResult, err error)

MintVehicleAndSdWithDdInputBatch mints a vehicles and paired synthetic devices in batches using data with a device definition and SACD input. Requires SD signature of typed data returned by GetMintVehicleAndSdTypedData Requires Vehicle Owner signature of typed data returned by GetMintVehicleWithDeviceDefinitionTypedData

func (*Client) MintVehicleWithDdInput

func (c *Client) MintVehicleWithDdInput(data *registry.MintVehicleWithDeviceDefinition) (result *zerodev.UserOperationResult, err error)

func (*Client) SendSignedUserOperation

func (c *Client) SendSignedUserOperation(op *zerodev.UserOperation) (result *zerodev.UserOperationResult, err error)

type ClientConfig

type ClientConfig struct {
	AccountAddress           common.Address
	AccountPK                *ecdsa.PrivateKey
	RpcURL                   *url.URL
	PaymasterURL             *url.URL
	BundlerURL               *url.URL
	ChainID                  *big.Int
	RegistryAddress          common.Address
	VehicleIdAddress         common.Address
	SyntheticDeviceIdAddress common.Address
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL