authorization
Creates an authorization function for use in transactions.
An authorization function must produce the information of the user that is going to sign and a signing function to use the information to produce a signature.
Read more about authorization functions and transaction roles.
Import
You can import the entire package and access the function:
_10import * as sdk from "@onflow/sdk"_10_10sdk.authorization(addr, signingFunction, keyId, sequenceNum)
Or import directly the specific function:
_10import { authorization } from "@onflow/sdk"_10_10authorization(addr, signingFunction, keyId, sequenceNum)
Usage
_28import * as fcl from "@onflow/fcl";_28import { ec as EC } from "elliptic";_28_28// Create a signing function_28const signingFunction = ({ message }) => {_28 // Your signing logic here_28 return {_28 addr: "0x123456789abcdef0",_28 keyId: 0,_28 signature: "your_signature_here"_28 };_28};_28_28// Create authorization_28const authz = fcl.authorization(_28 "0x123456789abcdef0", // account address_28 signingFunction, // signing function_28 0, // key ID_28 42 // sequence number_28);_28_28// Use in transaction_28await fcl.mutate({_28 cadence: `transaction { prepare(acct: AuthAccount) {} }`,_28 proposer: authz,_28 payer: authz,_28 authorizations: [authz]_28});
Parameters
addr
- Type:
string
- Description: The address of the account that will sign the transaction
signingFunction
- Type:
SigningFn
- Description: A function that produces signatures for the account
_10type SigningFn = (_10 signable?: SignableMessage_10) => SigningResult | Promise<SigningResult>
keyId
(optional)
- Type:
string | number
- Description: The index of the key to use for signing (optional)
sequenceNum
(optional)
- Type:
number
- Description: The sequence number for the account key (optional)