npm install @ethsign/sign-sdk
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,
});
const contractId = 'xxxx'; // main contract id
const userAddress = '0xxxxxx'; // eth address
const contractInfo = await client.checkContractStatus(contractId, userAddress);
const contractId = contractInfo.contractId; // come from checkContractStatus response
const webApiKey = await client.generateWebApiKey(contractId);
import { SignWebClient } from '@ethsign/sign-sdk';
const webClient = new SignWebClient({
getApiKey: async () => {
return await getWebApiKey(); // request server side to get webApikey
},
});
const contractId = contractInfo.contractId; // come from checkContractStatus response
const password = 'xxx'; //optional,if contract is password protected
const previewUrl = await webClient.generatePreviewUrl(contractId, password);
const contractId = contractInfo.contractId; // come from checkContractStatus response
const password = 'xxx'; //optional,if contract is password protected
const res = await webClient.downloadContract(contractId, password);
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: '',
},
],
});
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');
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');