dsrv key management store. @dsrv/kms provides the following methods for Ethereum, Celo, Near, Solana, Cosmos, Aptos, Ton, Sui
- Through WELLDONE Docs, you may see a live demonstration of kms and a more thorough theoretical foundation.
Through getAccount method, you can get account of your mnemonic.
import { Account, CHAIN, Ethereum } from '@dsrv/kms';
/* Ethereum getAccount */
export const getEthereumAccount = (mnemonic: string): Account => {
const ethereumAccount = Ethereum.getAccount({
mnemonic,
path: { type: CHAIN.ETHEREUM, account: 0, index: 0 },
});
return ethereumAccount;
};
interface Account {
address: string;
publicKey: string;
}
typeof mnemonic === string; // "your private mnemonic"
-
By following this link, you can see the example code.
-
You can execute the example code through the command below.
git clone https://github.com/dsrvlabs/kms-monorepo
- Create the
mnemonic.json
file inside thepackages/examples
(follow the format of this link) yarn && yarn build
yarn start:example getAccountPlayground.ts
Through getPrivateKey method, you can get a private key of your mnemonic.
import { CHAIN, Ethereum } from '@dsrv/kms';
/* Ethereum getPrivateKey */
export const getEthereumPrivateKey = (mnemonic: string): string => {
const ethereumPrivateKey = Ethereum.getPrivateKey({
mnemonic,
path: { type: CHAIN.ETHEREUM, account: 0, index: 0 },
});
return ethereumPrivateKey;
};
typeof privateKey === string;
typeof mnemonic === string; // "your private mnemonic"
-
By following this link, you can see the example code.
-
You can execute the example code through the command below.
git clone https://github.com/dsrvlabs/kms-monorepo
- Create the
mnemonic.json
file inside thepackages/examples
(follow the format of this link) yarn && yarn build
yarn start:example getPrivateKeyPlayground.ts
Through signTx method, you can get a signature for the transaction.
import { CHAIN, Ethereum } from '@dsrv/kms';
const { signature } = Ethereum.signTx(
{
mnemonic,
path: { type: CHAIN.ETHEREUM, account: 0, index: 0 },
},
serializedTx, // must be hex string
);
interface SignedTx {
unsignedTx: string;
signature: string;
}
typeof serializedTx === string; // must be hex string
Through kms, you can get a signature for the transaction. The steps listed below should be followed in order to sign the transaction through kms.
- Create raw transactions for each chain using the SDK.
- To obtain a signature for the transaction, add the created raw transaction as a signTx method factor of kms.
- The raw transaction is joined with the signature from kms to create a signed transaction.
import { Ethereum } from '@dsrv/kms';
export const getEthereumSignedTx = async (mnemonic: string) => {
// 1. Create raw transactions for each chain using the SDK.
// getEthereumTx is a custom method created to get raw transaction back.
const { serializedTx, unSignedTx } = await getEthereumTx(mnemonic);
// 2. The signature value for transaction is received through the signTx method of kms.
const ethereumSignature = Ethereum.signTx(
{
mnemonic,
path: { type: CHAIN.ETHEREUM, account: 0, index: 0 },
},
serializedTx,
);
// 3.The raw transaction generated above and the signature received through kms are combined to create a signed transaction.
// createEthereumSignedTx is a custom method for returning signedTransaction by combining signature and raw transaction.
const ethereumSignedTx = createEthereumSignedTx({
unSignedTx,
signature: ethereumSignature.signature,
});
return { ethereumSignedTx, signature: ethereumSignature.signature };
};
-
By following this link, you can see the example code.
-
You can execute the example code through the command below.
git clone https://github.com/dsrvlabs/kms-monorepo
- Create the
mnemonic.json
file inside thepackages/examples
(follow the format of this link) yarn && yarn build
yarn start:example signTxPlayground.ts
Transactions can be transferred via the signedTransaction created above. However, a faucet is required to transmit the transaction.
-
By following this link, you can see the example code.
-
You can execute the example code through the command below.
git clone https://github.com/dsrvlabs/kms-monorepo
- Create the
mnemonic.json
file inside thepackages/examples
(follow the format of this link) yarn && yarn build
yarn start:example sendTransactionPlayground.ts
yarn && yarn build:kms
yarn test:examples