@ethsign/sign-sdk
TypeScript icon, indicating that this package has built-in type declarations

0.1.9 • Public • Published

sign-sdk

Installation

npm install @ethsign/sign-sdk

Usage

server side

init
import { privateKeyToAccount } from 'viem/accounts';
import { SignClient } from '@ethsign/sign-sdk';
const privateKey = '0xxxxxx'; // eth private key
const tenantId = 'xxxx'; //sent us your publicKey to get it
const client = new SignClient({
  account: privateKeyToAccount(privateKey),
  tenantId: tenantId,
});

check contract status

const contractId = 'xxxx'; // main contract id
const userAddress = '0xxxxxx'; // eth address

const contractInfo = await client.checkContractStatus(contractId, userAddress);

generate webApiKey

const contractId = contractInfo.contractId; // come from checkContractStatus response
const webApiKey = await client.generateWebApiKey(contractId);

client side

init

import { SignWebClient } from '@ethsign/sign-sdk';

const webClient = new SignWebClient({
  getApiKey: async () => {
    return await getWebApiKey(); // request server side to get webApikey
  },
});
generate previewUrl
const contractId = contractInfo.contractId; // come from checkContractStatus response
const password = 'xxx'; //optional,if contract is password protected
const previewUrl = await webClient.generatePreviewUrl(contractId, password);
download contract
const contractId = contractInfo.contractId; // come from checkContractStatus response
const password = 'xxx'; //optional,if contract is password protected
const res = await webClient.downloadContract(contractId, password);
create contract
import { generateFileEncrypted,hashSha256 } from '@ethsign/sign-sdk';
import { createWalletClient, custom , privateKeyToAccount } from 'viem';
const file: File=;
const userAddress: string='0xabc';
const password: string='xxx';
const privateKey: string='0xabcxxx';
const fileEncrypted = await generateFileEncrypted({
  file,
  recipients: [
    {
      address: userAddress,
      chainType:'eth',
      email: '',
      x: 0,
      y: 0,
      page: 0,
      width: 100,
    },
  ],
  password,
});

const message = await hashSha256(fileEncrypted);
const account = privateKeyToAccount(privateKey);
const signature = await account.signMessage({ message });
const res = await client.createContract({
      creator: account.address,
      fileEncrypted,
      enableEncryption: !!password,
      enableExpiration: false,
      expireTime: 0,
      signature,
      title: file.name,
      recipients: [
        {
          address: account.address,
          email: '',
        },
      ],
 });
create share link
const timestamp = Date.now();
const account = privateKeyToAccount(privateKey); // owner of contract
const message = [contractId, timestamp].join(',');
const signature = await account.signMessage({ message });
const res = await client.createShareLink({
  contractId,
  timestamp,
  signature,
});
console.log(res, 'res');
get contract info
const timestamp = Date.now();
const account = privateKeyToAccount(privateKey);
const message = [contractId, timestamp].join(',');
const signature = await account.signMessage({ message });
const res = await client.getContractInfo({
  contractId,
  timestamp,
  signature,
});
console.log(res, 'res');

Readme

Keywords

none

Package Sidebar

Install

npm i @ethsign/sign-sdk

Weekly Downloads

44

Version

0.1.9

License

ISC

Unpacked Size

2.01 MB

Total Files

28

Last publish

Collaborators

  • evanyan
  • tinystone007
  • boyuanx
  • ethsign-jayhu