Loopring Dev Docs
  • Introduction
  • Endpoints
  • SDK
    • SDK Guides
    • Test Mock Data
      • Mock Account
      • Mock provider
      • Mock ERC20 Token Map
      • Mock AMM MAP
      • Mock EIP712 Typed Data
      • Mock Generate eddsaKey
  • Glossary
  • 🗳️Loopring Account
    • Introduction
    • SDK Guides
      • Setup a Loopring Account
      • Unlock Account (Login)
    • API References
      • Get Account info
        • Sample code
      • Update EddsaKey
        • Sample code
      • Get apiKey
        • Sample code
      • Update apiKey
        • Sample code
  • 🎨CounterFactual NFT
    • Introduction
      • Compute NFT Address API
      • When to deploy counterfactual NFT contracts?
    • SDK Guides
      • Deposit NFT
      • Create Collection
      • Mint Counterfactual NFT
      • Transfer NFT
      • Deploy NFT
      • Withdraw NFT
      • Trade NFT
        • Validate NFT Order
      • Meta & IPFS
    • API References
      • NFT Collection
        • Create collection
          • Sample code
        • Edit collection
          • Sample code
        • Delete collection
          • Sample code
        • List owned collections
          • Sample code
        • List user's NFTs under one collection
          • Sample code
        • List user's NFT balances group by Collection ID
          • Sample code
        • List all NFTs of a collection
          • Sample code
        • Get collection by Collection ID
          • Sample code
        • Get collections by contract address
          • Sample code
      • Get NFT Assets
        • Sample code
      • Get NFT Balances
        • Sample code
      • Mint NFT
        • Sample code
      • Transfer NFT
        • Sample code
      • Validate NFT Order
        • Sample code
      • Trade NFT
        • Sample code
      • Deploy NFT TokenAddress
        • Sample code
      • Withdraw NFT
        • Sample code
      • Get NFT Transactions
        • Sample code
      • Get NFT Trade History
        • Sample code
      • Get AvailableBroker
        • Sample code
      • Get NFT Info
        • Sample code
      • Get NFT Data
        • Sample code
      • Get NFT Holders
        • Sample code
  • 🪙ERC20 Tokens
    • Introduction
    • SDK Guides
      • Transfer ERC20
      • Withdraw ERC20
      • Deposit ERC20
      • Order ERC20
    • API References
      • Get Assets
        • Sample code
      • Transfer
        • Sample code
      • Submit Order
        • Sample code
      • Cancel Order
        • Sample code
      • Withdraw
        • Sample code
      • Get Transactions
        • Sample code
      • Get Orders
        • Sample code
      • Get Trade History
        • Sample code
  • 🔬Resources
    • Advanced
      • UpdateAccount with custom seed
      • Pay payee updateAccount fee
      • Common error and solutions
      • Submit erc20 order
    • Common Info
      • Get relayer current time
        • Sample code
      • Get exchange info
        • Sample code
      • Get token info
        • Sample code
      • Get markets info
        • Sample code
    • Error codes
    • Fees
      • GET ERC20 Offchain Fee
        • Sample code
      • GET ERC20 Order Fee
        • Sample code
      • GET NFT Offchain Fee
        • Sample code
      • GET NFT Order Fee
        • Sample code
      • SDK Fees
    • Layer 2 block info
      • Get pending transactions
    • Request signing
      • Special API Request Signatures
      • Off-chain Request Signatures
      • Extra ECDSA authentic in header
    • Signature
      • ECDSA signature
        • ECDSA key generation
        • ECDSA sign
        • ECDSA verify signature
      • EdDSA signature
        • EdDSA key generation
        • EdDSA sign
        • EdDSA verify signature
      • SDK Signature
        • Mock Signature
    • Smart Contracts
    • Storage Id
      • Sample code
    • WebSocket
      • Account Notification
      • Order Notification
      • Orderbook Notification
      • Trade Notification
      • Ticker Notification
      • Candlestick Notification
      • AMM Pool Snapshot Notification
      • Block Generation Notification
    • Loopring Smart Wallet
      • Signature and verification
Powered by GitBook
On this page
  • Contract Wallet
  • Counterfactual Wallet
  • JS example
  • Test Env: Goerli

Was this helpful?

  1. Resources
  2. Loopring Smart Wallet

Signature and verification

The Loopring wallet is a smart contract wallet. Its address is a contract wallet address. There is an owner who controls the wallet.

The wallet signature is signed by the owner, and the contract records the owner. Although the signature is actually signed by the owner you cannot get the owner, so you need to verify the signature through the wallet contract.

Loopring also has a counterfactual wallet, which means the wallet's contract hasn't been deployed. To deploy the contract, you need to get the actual owner from the Loopring server.

You can verify the signature one by one (use contract wallet verification and counterfactual wallet verification), if one of the two passes the signature is verified.

The signature is a little different from EOA wallets, and it can also be verified by the wallet contract.

We append 02 or 03 after the signature, for example, the signature is: 0x05b49f99ac6d8f67d4519dfaf9b545dbc775dcc837441f85ef9aae74c83e5c2d700729cdba1d7a9cc818abb43a598cf1e4eeca547e4e6697ff18c4d2ac111ac21b02

  • 02 means the signature is sign the message directly: ecdsaSign(message)

  • 03 means the signature is like personal_sign in ethereum, ecdsaSign(sha256($ethereum_header + message))

Contract Wallet

There is a need to call the contract (wallet address) to verify the signature is EIP1271 standard:

https://eips.ethereum.org/EIPS/eip-1271

The verify flow:

1. encode the call data use:
			encodeInputs(
      "isValidSignature(bytes32,bytes)",
      {
        _data: hash,
        _signature: toBuffer(sig),
      }
  hash is the message, sig is the signature

2. If the return value is 0x1626ba7e, means verify success, else the signature is not correct or the wallet is locked can not use now.

Counterfactual Wallet

  1. Use the address to get owner info

Endpoint

(goerli is uat2.loopring.io, mainnet is api3.loopring.io):

https://uat2.loopring.io/api/v3/counterFactualInfo?address=0xf8989b0d3f5e2ee877dca8897748772a4ce83888

Response:

{
	"accountId": 12413,
	"wallet": "0xf8989b0d3f5e2ee877dca8897748772a4ce83888",
	"walletFactory": "0x8c3d4e1728f77abcd220323260da4a9306fb6433",
	"walletSalt": "1648381750",
	"walletOwner": "0xd9702ea86111c6efe0d3ae2851f994696527a9a4"
}
  1. So the signature is signed by the walletOwner. you can use ecrecover to verify the signature:

    • if the signature ends with 02: the recover message is the message

    • if the signature ends with 03: the recover message is sha256($ethereum_header + message)

Test Env: Goerli

Android apk:

PreviousLoopring Smart Wallet

Last updated 2 years ago

Was this helpful?

🔬
JS example