0.1.9 • Published 8 months ago
@ethsign/sign-sdk v0.1.9
sign-sdk
Installation
npm install @ethsign/sign-sdkUsage
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');