1.1.1-beta.27 • Published 4 months ago

fsl-authorization v1.1.1-beta.27

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
4 months ago

FSL-ACCOUNT-SDK

What is FSL ID

Getting started

  • npm | yarn | pnpm install
import { FSLAuthorization } from 'fsl-authorization';

const fslAuthorization = FSLAuthorization.init({
  responseType: 'code', // 'code' | 'token'
  appKey: 'Your APP KEY',
  redirectUri: 'Your Redirect URL', // https://xxx.xxx.com
  scope: 'basic', // 'basic' | 'wallet'
  state: 'xyz',
  usePopup: true,
  isApp: true,
});

fSLAuthorization.signInV2().then(({ code }) => {
  if (code) {
    // todo your code
  }
});

callEvmSign

import { FSLAuthorization } from 'fsl-authorization';

// your Three-party login initialization
// ...

fSLAuthorization
  .callEvmSign({
    chainId: 80002,
    msg: 'Your Sign Message',
    chain: 'Amony', // Specify the test chain name
  })
  .then((res) => {
    console.log('signedTx', res);
    const address = FSLAuthorization.evmVerifyMessage('Your Sign Message', res);
    // Check whether the resolved address is the same as the user address
  });

If you don't want to pass object instances

// Make sure the user has logged in to fslid, you can do this again
// or

const args = {
  chainId: 137,
  msg: 'Your Sign Message',
};

const url = `https://id.fsl.com/authorization/sign?arguments=${JSON.stringify({
  ...args,
  appKey: 'Your App key',
})}`;

window.open(
  url,
  'signWindow',
  `left=${window.screen.width / 2 - 200},top=${
    window.screen.height / 2 - 500
  },width=500,height=800,popup=1`,
);

// If you want to get the result of the call
const handleMessage = (e: any) => {
  if (e.data.type === 'fsl_auth') {
    console.log(e.data.data);
    window.removeEventListener('message', handleMessage);
  }
};
window.addEventListener('message', handleMessage, false);

Types

interface IEvmSign {
  msg: string;
  rpc?: string;
  chainId: number;
}

callEvmContract

import { FSLAuthorization } from 'fsl-authorization';
import { ethers } from 'ethers';

// your Three-party login initialization
// ...

fSLAuthorization
  .callEvmContract({
    contractAddress: '0xc2132D05D31c914a87C6611C10748AEb04B58e8F',
    methodName: 'transfer',
    params: ['0x...', ethers.BigNumber.from(Math.floor(10 * Math.pow(10, 6)))],
    abi: [
      {
        constant: false,
        inputs: [
          { name: '_to', type: 'address' },
          { name: '_value', type: 'uint256' },
        ],
        name: 'transfer',
        outputs: [{ name: '', type: 'bool' }],
        payable: false,
        stateMutability: 'nonpayable',
        type: 'function',
      },
    ],
    gasLimit: '100000',
    to: '0x...',
    chainId: 137,
  })
  .then((res) => {
    console.log('TransactionReceipt', res);
  });

If you don't want to pass object instances

// Make sure the user has logged in to fslid, you can do this
// or
import { ethers } from 'ethers';

const args = {
  contractAddress: '0xc2132D05D31c914a87C6611C10748AEb04B58e8F',
  methodName: 'transfer',
  params: ['0x...', ethers.BigNumber.from(Math.floor(10 * Math.pow(10, 6)))],
  abi: [
    {
      constant: false,
      inputs: [
        { name: '_to', type: 'address' },
        { name: '_value', type: 'uint256' },
      ],
      name: 'transfer',
      outputs: [{ name: '', type: 'bool' }],
      payable: false,
      stateMutability: 'nonpayable',
      type: 'function',
    },
  ],
  gasLimit: '100000',
  to: '0x...',
  chainId: 137,
};
const url = `https://id.fsl.com/authorization/sign?arguments=${JSON.stringify({
  ...args,
  appKey: 'Your App key',
})}`;

window.open(
  url,
  'callContractWindow',
  `left=${window.screen.width / 2 - 200},top=${
    window.screen.height / 2 - 500
  },width=500,height=800,popup=1`,
);

// If you want to get the result of the call
const handleMessage = (e: any) => {
  if (e.data.type === 'fsl_auth') {
    console.log(e.data.data);
    window.removeEventListener('message', handleMessage);
  }
};
window.addEventListener('message', handleMessage, false);

Types

interface IEvmContract {
  contractAddress: string;
  methodName: string;
  chainId: number;
  gasLimit: string;

  abi?: any; // If the abi is not recognized, you can pass it in manually
  value?: string;
  params?: any[];
  to?: string;
  rpc?: string;
  nonce?: number;

  maxPriorityFeePerGasValue?: ethers.BigNumber;
  maxFeePerGasValue?: ethers.BigNumber;
}

signTypedData

import { FSLAuthorization } from 'fsl-authorization';
import { ethers } from 'ethers';

// your Three-party login initialization
// ...

const domain = {
  name: 'ERC20Token',
  version: '1',
  chainId: 137,
  verifyingContract: '0x',
};

let spender = '0x';
let number = '100';

const types = {
  Storage: [
    { name: 'spender', type: 'address' },
    { name: 'number', type: 'uint256' },
  ],
};

const message = {
  spender,
  number,
};

fSLAuthorization
  .signTypedData({
    domain,
    types,
    message,
    chianId,
  })
  .then((res) => {
    console.log('signedTx', res);
    const address = FSLAuthorization.evmVerifyTypedData(
      domain,
      types,
      message,
      res,
    );
    // Check whether the resolved address is the same as the user address
  });

Types

interface IDomain {
  name: string;
  version: string;
  chainId: number;
  verifyingContract: string;
}

interface ITypes {
  [key: string]: Record<'name' | 'type', string>[];
}

interface IMessage {
  [key: string]: any;
}

callEvmContractByCallData

const args = {
  contractAddress: '0x',
  chainId: 137,
  gasLimit: 40000,
  callData:
    '0xa9059cbb00000000000000000000000091837ab8b09257975b3cb737d8d580aaba27b14b0000000000000000000000000000000000000000000000000000000005f5e100',
};
fSLAuthorization.callEvmContractByCallData(args).then((res) => {
  console.log('TransactionReceipt', res);
});

// If you don't want to pass object instances
const url = `https://id.fsl.com/authorization/call-data?arguments=${JSON.stringify(
  {
    ...args,
    appKey: 'Your App key',
  },
)}`;

window.open(url);

// If you want to get the result of the call
const handleMessage = (e: any) => {
  if (e.data.type === 'fsl_auth') {
    console.log(e.data.data);
    window.removeEventListener('message', handleMessage);
  }
};
window.addEventListener('message', handleMessage, false);

Types

interface IEvmCallDataParams {
  contractAddress: string;
  callData: string;
  chainId: number;
  gasLimit: string;
  rpc?: string;
  maxPriorityFeePerGasValue?: BigNumber;
  maxFeePerGasValue?: BigNumber;
}

signTransaction

import { FSLAuthorization } from 'fsl-authorization';
import { ethers } from 'ethers';

// your Three-party login initialization
// ...

fSLAuthorization
  .signTransaction({
    contractAddress: '0xc2132D05D31c914a87C6611C10748AEb04B58e8F',
    methodName: 'transfer',
    params: ['0x...', ethers.BigNumber.from(Math.floor(10 * Math.pow(10, 6)))],
    abi: [
      {
        constant: false,
        inputs: [
          { name: '_to', type: 'address' },
          { name: '_value', type: 'uint256' },
        ],
        name: 'transfer',
        outputs: [{ name: '', type: 'bool' }],
        payable: false,
        stateMutability: 'nonpayable',
        type: 'function',
      },
    ],
    gasLimit: '100000',
    to: '0x...',
    chainId: 137,
  })
  .then((signedTx) => {
    console.log('signedTx', signedTx);
  });

// If you don't want to pass object instances
const url = `https://id.fsl.com/authorization/call-data?arguments=${JSON.stringify(
  {
    ...args,
    onlySign: 'onlySign',
    appKey: 'Your App key',
  },
)}`;

window.open(url);

// If you want to get the result of the call
const handleMessage = (e: any) => {
  if (e.data.type === 'fsl_auth') {
    console.log(e.data.data);
    window.removeEventListener('message', handleMessage);
  }
};
window.addEventListener('message', handleMessage, false);

signSolMessage

fSLAuthorization.signSolMessage({ msg }).then((res) => {
  console.log('signMessage', res);
});

callSolInstructions && signSolInstructions

const transferInstruction = createTransferInstruction();
fSLAuthorization
  .callSolInstructions({
    instructions: [transferInstruction],
    keypairs: [],
  })
  .then((res) => {
    console.log('hash', res);
  });

fSLAuthorization
  .signSolInstructions({
    instructions: [transferInstruction],
    keypairs: [],
  })
  .then((res) => {
    console.log('signMessage', res);
  });

signSolTransaction

const transactions = [new Transaction()];
signSolTransaction({ transactions }).then((res) => {
  console.log('signArrayTransactions', res);
});

Join as Developers

  • Please prepare the necessary stuff and talk to an FSL guy for your interest. Here are some step guides
  1. Register an FSL ID at https://id.fsl.com, and setup all necessary information. This will be your developer ID. Please make sure your 2FA and seed phrase backup is well and safely kept.

  2. Tell us about your App/product in a sheet

    1. Name
    2. Icon images in 128128px and 512512px
    3. App/product description
    4. Official website
    5. Social network links
  3. Go through the API references and provide your CALLBACK URL and host.

1.1.1-beta.27

4 months ago

1.1.1-beta.26

4 months ago

1.1.1-beta.25

4 months ago

1.1.1-beta.24

6 months ago

1.1.1-beta.23

6 months ago

1.1.1-beta.22

7 months ago

1.1.1-beta.21

7 months ago

1.1.1-beta.20

7 months ago

1.1.1-beta.16

8 months ago

1.1.1-beta.15

8 months ago

1.1.1-beta.18

8 months ago

1.1.1-beta.17

8 months ago

1.1.1-beta.12

8 months ago

1.1.1-beta.11

8 months ago

1.1.1-beta.14

8 months ago

1.1.1-beta.13

8 months ago

1.1.1-beta.19

8 months ago

1.1.1-beta.10

8 months ago

1.1.1-beta.8

8 months ago

1.1.1-beta.9

8 months ago

1.1.1-beta.6

8 months ago

1.1.1-beta.7

8 months ago

1.1.1-beta.3

9 months ago

1.1.1-beta.4

9 months ago

1.1.1-beta.5

9 months ago

1.1.1-beta.2

9 months ago

1.1.1-beta.1

9 months ago

1.1.1

9 months ago

1.2.0

9 months ago

1.1.0-beta.1

9 months ago

1.1.0

9 months ago

1.0.12-beta.5

9 months ago

1.0.12-beta.4

9 months ago

1.0.12-beta.3

9 months ago

1.0.12-beta.2

9 months ago

1.0.12-beta.1

10 months ago

1.0.12-beta.0

10 months ago

1.0.12

10 months ago

1.0.11

11 months ago

1.0.10

11 months ago

1.0.9

11 months ago

1.0.8

11 months ago

1.0.0-alpha.5

11 months ago

1.0.0-alpha.4

11 months ago

1.0.0-alpha.3

11 months ago

1.0.0-alpha.2

11 months ago

1.0.0-alpha.1

11 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago