Skip to main content

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:


_10
import * as sdk from '@onflow/sdk';
_10
_10
sdk.authorization(addr, signingFunction, keyId, sequenceNum);

Or import directly the specific function:


_10
import { authorization } from '@onflow/sdk';
_10
_10
authorization(addr, signingFunction, keyId, sequenceNum);

Usage


_28
import * as fcl from '@onflow/fcl';
_28
import { ec as EC } from 'elliptic';
_28
_28
// Create a signing function
_28
const 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
_28
const 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
_28
await 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:

_10
type SigningFn = (
_10
signable?: SignableMessage,
_10
) => SigningResult | Promise<SigningResult>;

  • Description: A function that produces signatures for the account

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)

Returns


_10
Partial<InteractionAccount>;

A partial interaction account object