From 355737763146255f40a58127efbd7c3a73110d46 Mon Sep 17 00:00:00 2001 From: Oleksii Trukhanov Date: Wed, 19 Feb 2025 14:43:41 +0200 Subject: [PATCH] DASH-1194 Update tests and readme file. --- .env.example | 9 +++ README.md | 31 +++++++--- docs/functions/index.decryptContent.html | 2 +- docs/functions/index.encryptContent.html | 2 +- docs/functions/index.getPublicKey.html | 2 +- docs/functions/index.signNonce.html | 2 +- docs/functions/index.signTransaction.html | 2 +- docs/functions/index.verifySignature.html | 2 +- docs/index.html | 11 ++-- docs/modules/index.html | 2 +- docs/modules/types.html | 2 +- docs/types/types.BlockInfo.html | 2 +- docs/types/types.ChainInfo.html | 2 +- docs/types/types.Content.html | 2 +- docs/types/types.DataParams.html | 2 +- docs/types/types.DecryptedContent.html | 2 +- docs/types/types.ECSignatureType.html | 2 +- docs/types/types.RequestParamsItem.html | 2 +- .../types/types.RequestParamsTranasction.html | 2 +- docs/types/types.SignNonceParams.html | 2 +- docs/types/types.SignatureObject.html | 2 +- docs/types/types.SignedTransaction.html | 2 +- docs/types/types.Transaction.html | 2 +- docs/types/types.TransactionAction.html | 2 +- package-lock.json | 13 +++++ package.json | 1 + src/index.test.ts | 58 ++++++++++++++++--- 27 files changed, 123 insertions(+), 42 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..eea1c6c --- /dev/null +++ b/.env.example @@ -0,0 +1,9 @@ +WALLET1_PRIVATE_KEY=your_private_key_here +WALLET2_PRIVATE_KEY=your_private_key_here + +# FIO Handles should already exist on appropriate wallet +WALLET1_FIO_HANDLE=your_fio_handle_here +WALLET2_FIO_HANDLE=your_fio_handle_here + +# Encrypted content string to decrypt +ENCRYPTED_CONTENT_STRING=your_encrypted_content_string_here diff --git a/README.md b/README.md index 026f722..411e841 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ async function main() { }, }, ], - privateKey: '5JSTL6nnXztYTD1buYfYSqJkNZTBdS9MDZf5nZsFW7gZd1pxZXo', + privateKey: FIO_PRIVATE_KEY, // Get one for testing at: http://monitor.testnet.fioprotocol.io:3000/#createKey // And add tokens from faucet at: http://monitor.testnet.fioprotocol.io:3000/#faucet }; @@ -157,9 +157,11 @@ async function main() { try { const encryptedContent = encryptContent({ content, - encryptionPublicKey: 'FIO7MYkz3serGGGanVPnPPupE1xSm7t7t8mWJ3H7KEd2vS2ZZbXBF', + encryptionPublicKey: FIO_PUBLIC_KEY_RECIPIENT, // FIO Public key of the recipient wallet that will be used for encryption fioContentType: 'new_funds_content', // new_funds_content - FIO Request, or 'record_obt_data_content' - FIO Data - privateKey: '5JTmqev7ZsryGGkN6z4FRzd4ELQJLNZuhtQhobVVsJsBHnXxFCw' + privateKey: FIO_PRIVATE_KEY_SENDER // FIO Private key of the sender + // Get one for testing at: http://monitor.testnet.fioprotocol.io:3000/#createKey + // And add tokens from faucet at: http://monitor.testnet.fioprotocol.io:3000/#faucet }); console.log(encryptedContent); } catch (error) { @@ -192,7 +194,9 @@ async function main() { // URL of FIO Chain API node, see: https://bpmonitor.fio.net/nodes const apiUrl = 'https://test.fio.eosusa.io'; // No trailing slashes const params = { - fio_public_key: "FIO7MYkz3serGGGanVPnPPupE1xSm1t7t8mWJ3H7KEd2vS2ZZbXBF", + fio_public_key: FIO_PUBLIC_KEY_SENDER, // FIO Public key of the sender wallet that will be used for encryption. + // You need to have pending FIO Request from the sender to the recipient. + // You can make it using [/new_funds_request](https://dev.fio.net/reference/new_funds_request) action. limit: 1, offset: 0, }; @@ -206,15 +210,25 @@ async function main() { ); const sentFioRequests = await response.json(); const fioRequestToDecrypt = sentFioRequests.requests[0]; - const decryptedContent = decryptContent({ + const decryptedContentSender = decryptContent({ content: fioRequestToDecrypt.content, encryptionPublicKey: fioRequestToDecrypt.payer_fio_public_key, fioContentType: 'new_funds_content', // new_funds_content - FIO Request, or 'record_obt_data_content' - FIO Data - privateKey: '5JTmqev7ZsryGGkN6z4FRzd4ELQJLNZuhtQhobVVsJsBHnXxFCw', + privateKey: FIO_PRIVATE_KEY_SENDER, // FIO Private key of the sender // Get one for testing at: http://monitor.testnet.fioprotocol.io:3000/#createKey // And add tokens from faucet at: http://monitor.testnet.fioprotocol.io:3000/#faucet }); - console.log(decryptedContent); + + const decryptedContentRecipient = decryptContent({ + content: fioRequestToDecrypt.content, + encryptionPublicKey: fioRequestToDecrypt.payee_fio_public_key, + fioContentType: 'new_funds_content', // new_funds_content - FIO Request, or 'record_obt_data_content' - FIO Data + privateKey: FIO_PRIVATE_KEY_RECIPIENT, // FIO Private key of the recipient + }); + + // Decrypted content should be the same for both sender and recipient + console.log(decryptedContentSender); + console.log(decryptedContentRecipient); } catch (error) { console.error("Error:", error); } @@ -250,7 +264,7 @@ import { signNonce, getPublicKey, verifySignature} from '@fioprotocol/fio-sdk-li import { createHmac, randomBytes } from 'crypto-browserify'; async function main() { - const privKey = '5JSTL6nnXztYTD1buYfYSqJkNZTBdS9MDZf5nZsFW7gZd1pxZXo'; + const privKey = FIO_PRIVATE_KEY; // Get one for testing at: http://monitor.testnet.fioprotocol.io:3000/#createKey // And add tokens from faucet at: http://monitor.testnet.fioprotocol.io:3000/#faucet const secret = 'nvjrf43dwmcsl'; @@ -287,6 +301,7 @@ main(); # Testing +To run tests, you need to have 2 FIO wallets with FIO Handles already created. Set it in `.env` file using `.env.example` as a template. Run tests using: ```bash diff --git a/docs/functions/index.decryptContent.html b/docs/functions/index.decryptContent.html index dac0f6e..3cf1294 100644 --- a/docs/functions/index.decryptContent.html +++ b/docs/functions/index.decryptContent.html @@ -1 +1 @@ -decryptContent | @fioprotocol/fio-sdk-lite - v1.0.1
  • Parameters

    • __namedParameters: {
          content: string;
          encryptionPublicKey: string;
          fioContentType: string;
          privateKey: string;
      }
      • content: string
      • encryptionPublicKey: string
      • fioContentType: string
      • privateKey: string

    Returns DecryptedContent

+decryptContent | @fioprotocol/fio-sdk-lite - v1.0.1
  • Parameters

    • __namedParameters: {
          content: string;
          encryptionPublicKey: string;
          fioContentType: string;
          privateKey: string;
      }
      • content: string
      • encryptionPublicKey: string
      • fioContentType: string
      • privateKey: string

    Returns DecryptedContent

diff --git a/docs/functions/index.encryptContent.html b/docs/functions/index.encryptContent.html index 21cc72a..8045f02 100644 --- a/docs/functions/index.encryptContent.html +++ b/docs/functions/index.encryptContent.html @@ -1 +1 @@ -encryptContent | @fioprotocol/fio-sdk-lite - v1.0.1
  • Parameters

    • __namedParameters: {
          content: undefined | Content;
          encryptionPublicKey: string;
          fioContentType: string;
          privateKey: string;
      }
      • content: undefined | Content
      • encryptionPublicKey: string
      • fioContentType: string
      • privateKey: string

    Returns string

+encryptContent | @fioprotocol/fio-sdk-lite - v1.0.1
  • Parameters

    • __namedParameters: {
          content: undefined | Content;
          encryptionPublicKey: string;
          fioContentType: string;
          privateKey: string;
      }
      • content: undefined | Content
      • encryptionPublicKey: string
      • fioContentType: string
      • privateKey: string

    Returns string

diff --git a/docs/functions/index.getPublicKey.html b/docs/functions/index.getPublicKey.html index 254a4e8..acc03f8 100644 --- a/docs/functions/index.getPublicKey.html +++ b/docs/functions/index.getPublicKey.html @@ -1 +1 @@ -getPublicKey | @fioprotocol/fio-sdk-lite - v1.0.1
  • Parameters

    • __namedParameters: {
          privateKey: string;
      }
      • privateKey: string

    Returns string

+getPublicKey | @fioprotocol/fio-sdk-lite - v1.0.1
  • Parameters

    • __namedParameters: {
          privateKey: string;
      }
      • privateKey: string

    Returns string

diff --git a/docs/functions/index.signNonce.html b/docs/functions/index.signNonce.html index 7d2a307..2c29ee6 100644 --- a/docs/functions/index.signNonce.html +++ b/docs/functions/index.signNonce.html @@ -1 +1 @@ -signNonce | @fioprotocol/fio-sdk-lite - v1.0.1
+signNonce | @fioprotocol/fio-sdk-lite - v1.0.1
diff --git a/docs/functions/index.signTransaction.html b/docs/functions/index.signTransaction.html index 91095cc..09f9132 100644 --- a/docs/functions/index.signTransaction.html +++ b/docs/functions/index.signTransaction.html @@ -1 +1 @@ -signTransaction | @fioprotocol/fio-sdk-lite - v1.0.1
+signTransaction | @fioprotocol/fio-sdk-lite - v1.0.1
diff --git a/docs/functions/index.verifySignature.html b/docs/functions/index.verifySignature.html index baca1f2..eb0b540 100644 --- a/docs/functions/index.verifySignature.html +++ b/docs/functions/index.verifySignature.html @@ -1 +1 @@ -verifySignature | @fioprotocol/fio-sdk-lite - v1.0.1
  • Parameters

    • __namedParameters: {
          data: string | Buffer;
          encoding?: BufferEncoding;
          publicKey: string;
          signature: string;
      }
      • data: string | Buffer
      • Optionalencoding?: BufferEncoding
      • publicKey: string
      • signature: string

    Returns boolean

+verifySignature | @fioprotocol/fio-sdk-lite - v1.0.1
  • Parameters

    • __namedParameters: {
          data: string | Buffer;
          encoding?: BufferEncoding;
          publicKey: string;
          signature: string;
      }
      • data: string | Buffer
      • Optionalencoding?: BufferEncoding
      • publicKey: string
      • signature: string

    Returns boolean

diff --git a/docs/index.html b/docs/index.html index 9dd60df..5cd225f 100644 --- a/docs/index.html +++ b/docs/index.html @@ -41,7 +41,7 @@

timeoutOffset - Not required. Time offset for transaction expiration in milliseconds. By default, this is set to 60000 milliseconds, equivalent to 1 minute.

-
import { signTransaction } from '@fioprotocol/fio-sdk-lite';

async function main() {
// URL of FIO Chain API node, see: https://bpmonitor.fio.net/nodes
const apiUrl = 'https://test.fio.eosusa.io'; // No trailing slashes

// Transaction data, see https://dev.fio.net/reference/fio-chain-actions-api
// actor is omitted as it will be inserted by the SDK.
const params = {
apiUrl,
actionParams: [
{
action: 'regaddress',
account: 'fio.address',
data: {
fio_address: `testing-fio-handle-${Date.now()}@regtest`,
owner_fio_public_key: '',
tpid: '',
max_fee: 1500000000000, // Obtain from https://dev.fio.net/reference/get_fee
},
},
],
privateKey: '5JSTL6nnXztYTD1buYfYSqJkNZTBdS9MDZf5nZsFW7gZd1pxZXo',
// Get one for testing at: http://monitor.testnet.fioprotocol.io:3000/#createKey
// And add tokens from faucet at: http://monitor.testnet.fioprotocol.io:3000/#faucet
};

try {
const signedTransactions = await signTransaction(params);
const signedTransactionsResult = JSON.parse(signedTransactions);

const pushTransactionResult = async (signedTransactionsResult: any) => {
const pushResult = await fetch(
apiUrl+'/v1/chain/push_transaction',
{
body: JSON.stringify(signedTransactionsResult),
method: 'POST',
}
);

if ([400, 403, 500].includes(pushResult.status)) {
const jsonResult = await pushResult.json();
const errorMessage = jsonResult.message || 'Something went wrong';

if (jsonResult.fields) {
const fieldErrors = jsonResult.fields.map(field => ({
name: field.name,
value: field.value,
error: field.error,
}));
throw new Error(`${errorMessage}: ${JSON.stringify(fieldErrors)}`);
} else if (jsonResult.error && jsonResult.error.what) {
throw new Error(jsonResult.error.what);
} else {
throw new Error(errorMessage);
}
}

return await pushResult.json();
};
const results = await Promise.allSettled(
signedTransactionsResult.successed.map(pushTransactionResult)
);
console.log(results);
const processedData = results[0].status === 'fulfilled' ? results[0].value.processed : null;
if (processedData) {
const response = JSON.parse(processedData.action_traces[0].receipt.response);
console.log('Processed Data Response:', JSON.stringify(response, null, 2));
}
} catch (error) {
console.error("Error:", error);
}
}

main(); +
import { signTransaction } from '@fioprotocol/fio-sdk-lite';

async function main() {
// URL of FIO Chain API node, see: https://bpmonitor.fio.net/nodes
const apiUrl = 'https://test.fio.eosusa.io'; // No trailing slashes

// Transaction data, see https://dev.fio.net/reference/fio-chain-actions-api
// actor is omitted as it will be inserted by the SDK.
const params = {
apiUrl,
actionParams: [
{
action: 'regaddress',
account: 'fio.address',
data: {
fio_address: `testing-fio-handle-${Date.now()}@regtest`,
owner_fio_public_key: '',
tpid: '',
max_fee: 1500000000000, // Obtain from https://dev.fio.net/reference/get_fee
},
},
],
privateKey: FIO_PRIVATE_KEY,
// Get one for testing at: http://monitor.testnet.fioprotocol.io:3000/#createKey
// And add tokens from faucet at: http://monitor.testnet.fioprotocol.io:3000/#faucet
};

try {
const signedTransactions = await signTransaction(params);
const signedTransactionsResult = JSON.parse(signedTransactions);

const pushTransactionResult = async (signedTransactionsResult: any) => {
const pushResult = await fetch(
apiUrl+'/v1/chain/push_transaction',
{
body: JSON.stringify(signedTransactionsResult),
method: 'POST',
}
);

if ([400, 403, 500].includes(pushResult.status)) {
const jsonResult = await pushResult.json();
const errorMessage = jsonResult.message || 'Something went wrong';

if (jsonResult.fields) {
const fieldErrors = jsonResult.fields.map(field => ({
name: field.name,
value: field.value,
error: field.error,
}));
throw new Error(`${errorMessage}: ${JSON.stringify(fieldErrors)}`);
} else if (jsonResult.error && jsonResult.error.what) {
throw new Error(jsonResult.error.what);
} else {
throw new Error(errorMessage);
}
}

return await pushResult.json();
};
const results = await Promise.allSettled(
signedTransactionsResult.successed.map(pushTransactionResult)
);
console.log(results);
const processedData = results[0].status === 'fulfilled' ? results[0].value.processed : null;
if (processedData) {
const response = JSON.parse(processedData.action_traces[0].receipt.response);
console.log('Processed Data Response:', JSON.stringify(response, null, 2));
}
} catch (error) {
console.error("Error:", error);
}
}

main();

Use this function to encrypt content for FIO Request or FIO Data..

@@ -64,7 +64,7 @@

privateKey - Required. FIO Private key of the sender.

-
import { encryptContent } from '@fioprotocol/fio-sdk-lite';

async function main() {
const content = {
payee_public_address: 'purse@alice',
amount: '1',
chain_code: 'FIO',
token_code: 'FIO',
memo: 'Payment for services',
hash: '',
offline_url: ''
};

try {
const encryptedContent = encryptContent({
content,
encryptionPublicKey: 'FIO7MYkz3serGGGanVPnPPupE1xSm7t7t8mWJ3H7KEd2vS2ZZbXBF',
fioContentType: 'new_funds_content', // new_funds_content - FIO Request, or 'record_obt_data_content' - FIO Data
privateKey: '5JTmqev7ZsryGGkN6z4FRzd4ELQJLNZuhtQhobVVsJsBHnXxFCw'
});
console.log(encryptedContent);
} catch (error) {
console.error("Error:", error);
}
}

main(); +
import { encryptContent } from '@fioprotocol/fio-sdk-lite';

async function main() {
const content = {
payee_public_address: 'purse@alice',
amount: '1',
chain_code: 'FIO',
token_code: 'FIO',
memo: 'Payment for services',
hash: '',
offline_url: ''
};

try {
const encryptedContent = encryptContent({
content,
encryptionPublicKey: FIO_PUBLIC_KEY_RECIPIENT, // FIO Public key of the recipient wallet that will be used for encryption
fioContentType: 'new_funds_content', // new_funds_content - FIO Request, or 'record_obt_data_content' - FIO Data
privateKey: FIO_PRIVATE_KEY_SENDER // FIO Private key of the sender
// Get one for testing at: http://monitor.testnet.fioprotocol.io:3000/#createKey
// And add tokens from faucet at: http://monitor.testnet.fioprotocol.io:3000/#faucet
});
console.log(encryptedContent);
} catch (error) {
console.error("Error:", error);
}
}

main();

Use this function to decrypt content in FIO Requests or FIO Data.

@@ -87,7 +87,7 @@

privateKey - Required. FIO Private key.

-
import { decryptContent } from '@fioprotocol/fio-sdk-lite';

async function main() {
// URL of FIO Chain API node, see: https://bpmonitor.fio.net/nodes
const apiUrl = 'https://test.fio.eosusa.io'; // No trailing slashes
const params = {
fio_public_key: "FIO7MYkz3serGGGanVPnPPupE1xSm1t7t8mWJ3H7KEd2vS2ZZbXBF",
limit: 1,
offset: 0,
};

try {
const response = await fetch(apiUrl+'/v1/chain/get_sent_fio_requests',
{
body: JSON.stringify(params),
method: 'POST',
},
);
const sentFioRequests = await response.json();
const fioRequestToDecrypt = sentFioRequests.requests[0];
const decryptedContent = decryptContent({
content: fioRequestToDecrypt.content,
encryptionPublicKey: fioRequestToDecrypt.payer_fio_public_key,
fioContentType: 'new_funds_content', // new_funds_content - FIO Request, or 'record_obt_data_content' - FIO Data
privateKey: '5JTmqev7ZsryGGkN6z4FRzd4ELQJLNZuhtQhobVVsJsBHnXxFCw',
// Get one for testing at: http://monitor.testnet.fioprotocol.io:3000/#createKey
// And add tokens from faucet at: http://monitor.testnet.fioprotocol.io:3000/#faucet
});
console.log(decryptedContent);
} catch (error) {
console.error("Error:", error);
}
}

main(); +
import { decryptContent } from '@fioprotocol/fio-sdk-lite';

async function main() {
// URL of FIO Chain API node, see: https://bpmonitor.fio.net/nodes
const apiUrl = 'https://test.fio.eosusa.io'; // No trailing slashes
const params = {
fio_public_key: FIO_PUBLIC_KEY_SENDER, // FIO Public key of the sender wallet that will be used for encryption.
// You need to have pending FIO Request from the sender to the recipient.
// You can make it using [/new_funds_request](https://dev.fio.net/reference/new_funds_request) action.
limit: 1,
offset: 0,
};

try {
const response = await fetch(apiUrl+'/v1/chain/get_sent_fio_requests',
{
body: JSON.stringify(params),
method: 'POST',
},
);
const sentFioRequests = await response.json();
const fioRequestToDecrypt = sentFioRequests.requests[0];
const decryptedContentSender = decryptContent({
content: fioRequestToDecrypt.content,
encryptionPublicKey: fioRequestToDecrypt.payer_fio_public_key,
fioContentType: 'new_funds_content', // new_funds_content - FIO Request, or 'record_obt_data_content' - FIO Data
privateKey: FIO_PRIVATE_KEY_SENDER, // FIO Private key of the sender
// Get one for testing at: http://monitor.testnet.fioprotocol.io:3000/#createKey
// And add tokens from faucet at: http://monitor.testnet.fioprotocol.io:3000/#faucet
});

const decryptedContentRecipient = decryptContent({
content: fioRequestToDecrypt.content,
encryptionPublicKey: fioRequestToDecrypt.payee_fio_public_key,
fioContentType: 'new_funds_content', // new_funds_content - FIO Request, or 'record_obt_data_content' - FIO Data
privateKey: FIO_PRIVATE_KEY_RECIPIENT, // FIO Private key of the recipient
});

// Decrypted content should be the same for both sender and recipient
console.log(decryptedContentSender);
console.log(decryptedContentRecipient);
} catch (error) {
console.error("Error:", error);
}
}

main();

Parameters getPublicKey:

@@ -118,10 +118,11 @@

encoding - Not required. Is one of Buffer Encoding names: "ascii", "utf8", "utf-8", "utf16le", "utf-16le", "ucs2", "ucs-2", "base64", "base64url", "latin1", "binary", "hex". By default is automatically set as utf8.

-
import { signNonce, getPublicKey, verifySignature} from '@fioprotocol/fio-sdk-lite';
import { createHmac, randomBytes } from 'crypto-browserify';

async function main() {
const privKey = '5JSTL6nnXztYTD1buYfYSqJkNZTBdS9MDZf5nZsFW7gZd1pxZXo';
// Get one for testing at: http://monitor.testnet.fioprotocol.io:3000/#createKey
// And add tokens from faucet at: http://monitor.testnet.fioprotocol.io:3000/#faucet
const secret = 'nvjrf43dwmcsl';

try {
// Get public key from Private key
const publicKey = getPublicKey({ privateKey: privKey });
console.log('Public key', publicKey);

// Generate nonce
const stringToHash = randomBytes(8).toString('hex');
const nonce = createHmac('sha256', secret)
.update(stringToHash)
.digest('hex');

// Sign nonce
const singedNonce = signNonce({ nonce, privateKey: privKey });
console.log('Signed nonce', singedNonce);

// Verify nonce
const isSignatureVerified = verifySignature({
signature: singedNonce,
data: nonce,
publicKey,
});
console.log(isSignatureVerified);
} catch (error) {
console.error('Error:', error);
}
}

main(); +
import { signNonce, getPublicKey, verifySignature} from '@fioprotocol/fio-sdk-lite';
import { createHmac, randomBytes } from 'crypto-browserify';

async function main() {
const privKey = FIO_PRIVATE_KEY;
// Get one for testing at: http://monitor.testnet.fioprotocol.io:3000/#createKey
// And add tokens from faucet at: http://monitor.testnet.fioprotocol.io:3000/#faucet
const secret = 'nvjrf43dwmcsl';

try {
// Get public key from Private key
const publicKey = getPublicKey({ privateKey: privKey });
console.log('Public key', publicKey);

// Generate nonce
const stringToHash = randomBytes(8).toString('hex');
const nonce = createHmac('sha256', secret)
.update(stringToHash)
.digest('hex');

// Sign nonce
const singedNonce = signNonce({ nonce, privateKey: privKey });
console.log('Signed nonce', singedNonce);

// Verify nonce
const isSignatureVerified = verifySignature({
signature: singedNonce,
data: nonce,
publicKey,
});
console.log(isSignatureVerified);
} catch (error) {
console.error('Error:', error);
}
}

main();
-

Testing

Run tests using:

+

Testing

To run tests, you need to have 2 FIO wallets with FIO Handles already created. Set it in .env file using .env.example as a template. +Run tests using:

npm run test
 
diff --git a/docs/modules/index.html b/docs/modules/index.html index 2fd9617..de518c7 100644 --- a/docs/modules/index.html +++ b/docs/modules/index.html @@ -1,4 +1,4 @@ -index | @fioprotocol/fio-sdk-lite - v1.0.1

Index

Functions

decryptContent +index | @fioprotocol/fio-sdk-lite - v1.0.1

Index

Functions

decryptContent encryptContent getPublicKey signNonce diff --git a/docs/modules/types.html b/docs/modules/types.html index f7f5fa7..edb94f9 100644 --- a/docs/modules/types.html +++ b/docs/modules/types.html @@ -1,4 +1,4 @@ -types | @fioprotocol/fio-sdk-lite - v1.0.1

Index

Type Aliases

BlockInfo +types | @fioprotocol/fio-sdk-lite - v1.0.1

Index

Type Aliases

BlockInfo ChainInfo Content DataParams diff --git a/docs/types/types.BlockInfo.html b/docs/types/types.BlockInfo.html index 8fe64ac..4fb36df 100644 --- a/docs/types/types.BlockInfo.html +++ b/docs/types/types.BlockInfo.html @@ -1 +1 @@ -BlockInfo | @fioprotocol/fio-sdk-lite - v1.0.1
BlockInfo: {
    action_mroot: string;
    block_extensions: string[];
    block_num: number;
    confirmed: number;
    header_extensions: string[];
    id: string;
    new_producers: string[] | null;
    previous: string;
    producer: string;
    producer_signature: string;
    ref_block_prefix: number;
    schedule_version: number;
    timestamp: string;
    transaction_mroot: string;
    transactions: string[];
}
+BlockInfo | @fioprotocol/fio-sdk-lite - v1.0.1
BlockInfo: {
    action_mroot: string;
    block_extensions: string[];
    block_num: number;
    confirmed: number;
    header_extensions: string[];
    id: string;
    new_producers: string[] | null;
    previous: string;
    producer: string;
    producer_signature: string;
    ref_block_prefix: number;
    schedule_version: number;
    timestamp: string;
    transaction_mroot: string;
    transactions: string[];
}
diff --git a/docs/types/types.ChainInfo.html b/docs/types/types.ChainInfo.html index 4a553d0..3ecd542 100644 --- a/docs/types/types.ChainInfo.html +++ b/docs/types/types.ChainInfo.html @@ -1 +1 @@ -ChainInfo | @fioprotocol/fio-sdk-lite - v1.0.1
ChainInfo: {
    block_cpu_limit: number;
    block_net_limit: number;
    chain_id: string;
    fork_db_head_block_id: string;
    fork_db_head_block_num: number;
    head_block_id: string;
    head_block_num: number;
    head_block_producer: string;
    head_block_time: string;
    last_irreversible_block_id: string;
    last_irreversible_block_num: number;
    server_version: string;
    server_version_string: string;
    virtual_block_cpu_limit: number;
    virtual_block_net_limit: number;
}
+ChainInfo | @fioprotocol/fio-sdk-lite - v1.0.1
ChainInfo: {
    block_cpu_limit: number;
    block_net_limit: number;
    chain_id: string;
    fork_db_head_block_id: string;
    fork_db_head_block_num: number;
    head_block_id: string;
    head_block_num: number;
    head_block_producer: string;
    head_block_time: string;
    last_irreversible_block_id: string;
    last_irreversible_block_num: number;
    server_version: string;
    server_version_string: string;
    virtual_block_cpu_limit: number;
    virtual_block_net_limit: number;
}
diff --git a/docs/types/types.Content.html b/docs/types/types.Content.html index 900d683..36c8d6b 100644 --- a/docs/types/types.Content.html +++ b/docs/types/types.Content.html @@ -1 +1 @@ -Content | @fioprotocol/fio-sdk-lite - v1.0.1
Content: DecryptedContent | string
+Content | @fioprotocol/fio-sdk-lite - v1.0.1
Content: DecryptedContent | string
diff --git a/docs/types/types.DataParams.html b/docs/types/types.DataParams.html index 942b45a..fb27707 100644 --- a/docs/types/types.DataParams.html +++ b/docs/types/types.DataParams.html @@ -1 +1 @@ -DataParams | @fioprotocol/fio-sdk-lite - v1.0.1
DataParams: {
    amount?: string | number;
    bundle_sets?: number;
    chain_code?: string;
    content?: Content;
    fio_address?: string;
    fio_domain?: string;
    fio_request_id?: string;
    is_public?: number;
    max_fee: number;
    max_oracle_fee?: string;
    new_owner_fio_public_key?: string;
    nfts?: {
        chain_code: string;
        contract_address: string;
        hash?: string;
        metadata?: string;
        token_id: string;
        url?: string;
    }[];
    owner_fio_public_key?: string;
    payee_fio_address?: string;
    payee_public_key?: string;
    payer_fio_address?: string;
    public_address?: string;
    public_addresses?: {
        chain_code: string;
        public_address: string;
        token_code: string;
    }[];
    tpid: string;
}
+DataParams | @fioprotocol/fio-sdk-lite - v1.0.1
DataParams: {
    amount?: string | number;
    bundle_sets?: number;
    chain_code?: string;
    content?: Content;
    fio_address?: string;
    fio_domain?: string;
    fio_request_id?: string;
    is_public?: number;
    max_fee: number;
    max_oracle_fee?: string;
    new_owner_fio_public_key?: string;
    nfts?: {
        chain_code: string;
        contract_address: string;
        hash?: string;
        metadata?: string;
        token_id: string;
        url?: string;
    }[];
    owner_fio_public_key?: string;
    payee_fio_address?: string;
    payee_public_key?: string;
    payer_fio_address?: string;
    public_address?: string;
    public_addresses?: {
        chain_code: string;
        public_address: string;
        token_code: string;
    }[];
    tpid: string;
}
diff --git a/docs/types/types.DecryptedContent.html b/docs/types/types.DecryptedContent.html index ac1980f..8b59a47 100644 --- a/docs/types/types.DecryptedContent.html +++ b/docs/types/types.DecryptedContent.html @@ -1 +1 @@ -DecryptedContent | @fioprotocol/fio-sdk-lite - v1.0.1
DecryptedContent: {
    amount: string | number;
    chain_code: string;
    hash: string | null;
    memo: string | null;
    obt_id?: string;
    offline_url: string | null;
    payee_public_address: string;
    payer_public_address?: string;
    status?: string;
    token_code: string;
}
+DecryptedContent | @fioprotocol/fio-sdk-lite - v1.0.1
DecryptedContent: {
    amount: string | number;
    chain_code: string;
    hash: string | null;
    memo: string | null;
    obt_id?: string;
    offline_url: string | null;
    payee_public_address: string;
    payer_public_address?: string;
    status?: string;
    token_code: string;
}
diff --git a/docs/types/types.ECSignatureType.html b/docs/types/types.ECSignatureType.html index 93c1ed7..7dd2b19 100644 --- a/docs/types/types.ECSignatureType.html +++ b/docs/types/types.ECSignatureType.html @@ -1 +1 @@ -ECSignatureType | @fioprotocol/fio-sdk-lite - v1.0.1
ECSignatureType: {
    r: BigInteger;
    s: BigInteger;
    toDER: (() => Buffer);
}
+ECSignatureType | @fioprotocol/fio-sdk-lite - v1.0.1
ECSignatureType: {
    r: BigInteger;
    s: BigInteger;
    toDER: (() => Buffer);
}
diff --git a/docs/types/types.RequestParamsItem.html b/docs/types/types.RequestParamsItem.html index 2eeb171..fb5b947 100644 --- a/docs/types/types.RequestParamsItem.html +++ b/docs/types/types.RequestParamsItem.html @@ -1 +1 @@ -RequestParamsItem | @fioprotocol/fio-sdk-lite - v1.0.1
RequestParamsItem: {
    account: string;
    action: string;
    authActor?: string;
    contentType?: string;
    data: DataParams;
    dataActor?: string;
    id?: string;
    payeeFioPublicKey?: string;
    payerFioPublicKey?: string;
    timeoutOffset?: string;
}
+RequestParamsItem | @fioprotocol/fio-sdk-lite - v1.0.1
RequestParamsItem: {
    account: string;
    action: string;
    authActor?: string;
    contentType?: string;
    data: DataParams;
    dataActor?: string;
    id?: string;
    payeeFioPublicKey?: string;
    payerFioPublicKey?: string;
    timeoutOffset?: string;
}
diff --git a/docs/types/types.RequestParamsTranasction.html b/docs/types/types.RequestParamsTranasction.html index abe43ed..36853b6 100644 --- a/docs/types/types.RequestParamsTranasction.html +++ b/docs/types/types.RequestParamsTranasction.html @@ -1,3 +1,3 @@ RequestParamsTranasction | @fioprotocol/fio-sdk-lite - v1.0.1
RequestParamsTranasction: {
    actionParams: RequestParamsItem[];
    apiUrl: string;
    privateKey: string;
}

Type declaration

  • actionParams: RequestParamsItem[]
  • apiUrl: string

    The apiUrl is a FIO Action server URL e.g. mainnet - https://fio.blockpane.com;

  • privateKey: string

    The privateKey is a FIO Private key e.g. 5JTmqev7ZsryGGkN6z4FRzd4ELQJLNZuhtQhobVVsJsBHnXxFCw;

    -
+
diff --git a/docs/types/types.SignNonceParams.html b/docs/types/types.SignNonceParams.html index 9811f33..ac0f7de 100644 --- a/docs/types/types.SignNonceParams.html +++ b/docs/types/types.SignNonceParams.html @@ -1,2 +1,2 @@ SignNonceParams | @fioprotocol/fio-sdk-lite - v1.0.1
SignNonceParams: {
    nonce: string | Buffer;
    privateKey: string;
}

Type declaration

  • nonce: string | Buffer

    The nonce to be signed. Could be generated like this: `crypto.createHmac('sha256', config.secret).update(string).digest('hex');

    -
  • privateKey: string
+
  • privateKey: string
  • diff --git a/docs/types/types.SignatureObject.html b/docs/types/types.SignatureObject.html index 0deb1c7..ff69b34 100644 --- a/docs/types/types.SignatureObject.html +++ b/docs/types/types.SignatureObject.html @@ -1 +1 @@ -SignatureObject | @fioprotocol/fio-sdk-lite - v1.0.1
    SignatureObject: {
        i: number;
        r: BigInteger;
        s: BigInteger;
    }
    +SignatureObject | @fioprotocol/fio-sdk-lite - v1.0.1
    SignatureObject: {
        i: number;
        r: BigInteger;
        s: BigInteger;
    }
    diff --git a/docs/types/types.SignedTransaction.html b/docs/types/types.SignedTransaction.html index b3bd9fa..0aec07d 100644 --- a/docs/types/types.SignedTransaction.html +++ b/docs/types/types.SignedTransaction.html @@ -1 +1 @@ -SignedTransaction | @fioprotocol/fio-sdk-lite - v1.0.1
    SignedTransaction: {
        compression: number;
        packed_context_free_data: string;
        packed_trx: string;
        signatures: string[];
    }
    +SignedTransaction | @fioprotocol/fio-sdk-lite - v1.0.1
    SignedTransaction: {
        compression: number;
        packed_context_free_data: string;
        packed_trx: string;
        signatures: string[];
    }
    diff --git a/docs/types/types.Transaction.html b/docs/types/types.Transaction.html index 323148b..a665e2c 100644 --- a/docs/types/types.Transaction.html +++ b/docs/types/types.Transaction.html @@ -1 +1 @@ -Transaction | @fioprotocol/fio-sdk-lite - v1.0.1
    Transaction: {
        actions: TransactionAction[];
        expiration: string;
        ref_block_num: number;
        ref_block_prefix: number;
    }
    +Transaction | @fioprotocol/fio-sdk-lite - v1.0.1
    Transaction: {
        actions: TransactionAction[];
        expiration: string;
        ref_block_num: number;
        ref_block_prefix: number;
    }
    diff --git a/docs/types/types.TransactionAction.html b/docs/types/types.TransactionAction.html index 3700504..aa80210 100644 --- a/docs/types/types.TransactionAction.html +++ b/docs/types/types.TransactionAction.html @@ -1 +1 @@ -TransactionAction | @fioprotocol/fio-sdk-lite - v1.0.1
    TransactionAction: {
        account: string;
        authorization: {
            actor: string;
            permission: string;
        }[];
        data: DataParams | string;
        name: string;
    }
    +TransactionAction | @fioprotocol/fio-sdk-lite - v1.0.1
    TransactionAction: {
        account: string;
        authorization: {
            actor: string;
            permission: string;
        }[];
        data: DataParams | string;
        name: string;
    }
    diff --git a/package-lock.json b/package-lock.json index 9a6985a..2951d12 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,6 +31,7 @@ "@types/text-encoding": "0.0.39", "@typescript-eslint/eslint-plugin": "8.8.1", "@typescript-eslint/parser": "8.8.1", + "dotenv": "16.4.7", "eslint": "9.12.0", "eslint-config-prettier": "9.1.0", "eslint-plugin-prettier": "5.2.1", @@ -2524,6 +2525,18 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/dotenv": { + "version": "16.4.7", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz", + "integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/ecurve": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/ecurve/-/ecurve-1.0.6.tgz", diff --git a/package.json b/package.json index dd9e19b..2c970a9 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "@types/text-encoding": "0.0.39", "@typescript-eslint/eslint-plugin": "8.8.1", "@typescript-eslint/parser": "8.8.1", + "dotenv": "16.4.7", "eslint": "9.12.0", "eslint-config-prettier": "9.1.0", "eslint-plugin-prettier": "5.2.1", diff --git a/src/index.test.ts b/src/index.test.ts index 0c6273c..4dcb987 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -1,3 +1,5 @@ +import 'dotenv/config'; + import { decryptContent, encryptContent, @@ -11,15 +13,15 @@ const MEMO_PHRASE = 'Hello FIO SDK Lite'; const MEMO_PHRASE_ENCRYPTED = 'Hello FIO SDK Lite Encrypted'; const wallet1 = { - privateKey: '5JTmqev7ZsryGGkN6z4FRzd4ELQJLNZuhtQhobVVsJsBHnXxFCw', - publicKey: 'FIO7MYkz3serGGGanVPnPPupE1xSm1t7t8mWJ3H7KEd2vS2ZZbXBF', - fioHandle: 'fio-sdk-handle@regtest', + privateKey: process.env.WALLET1_PRIVATE_KEY!, + publicKey: getPublicKey({ privateKey: process.env.WALLET1_PRIVATE_KEY! }), + fioHandle: process.env.WALLET1_FIO_HANDLE!, }; const wallet2 = { - privateKey: '5JpWuB5YbjQBmoBcxbzTTuY9h2NNQNVD5Ct5yKU1d5QCowt1G8X', - publicKey: 'FIO8hnBb7aUDFs6cvCT2TCRQs9vV9jxJbKLCe5q23Zb8Wr36DxsUr', - fioHandle: 'fio-sdk-handle-2@regtest', + privateKey: process.env.WALLET2_PRIVATE_KEY!, + publicKey: getPublicKey({ privateKey: process.env.WALLET2_PRIVATE_KEY! }), + fioHandle: process.env.WALLET2_FIO_HANDLE!, }; const encryptContentParams = { @@ -70,9 +72,19 @@ const transactionActionParams = { privateKey: wallet1.privateKey, }; +/** + * Decrypt Content Parameters + * + * These parameters are used to decrypt content created by the main FIO SDK library. + * + * To create a new FIO request: + * 1. Visit https://dev.fio.net/reference/new_funds_request + * 2. Follow the API documentation instructions + * 3. Use matching FIO keys for sender and recipient wallets in .env file + * - This ensures content encryption/decryption works correctly across environments + */ const decryptContentParams = { - content: - 'FoyXu0rQyBSbkvI3gJ2FIz6PBylbhxetqTMQpa3BEcogvnFg1EpWEZY+QyQEA2Ckv1/m2bbs+SfCiZXjieFAF9xfUiCQ+MK66Ky1ctn1JNx8BmDFI+1Wnyn2uoxwP55fZK0MUBw0hKTu7WnUHvDWPgFHsNdIyDVlB0lb174U37Hm1c8BS/KMpqjpN/E2xN9D', + content: process.env.ENCRYPTED_CONTENT_STRING!, encryptionPublicKey: wallet2.publicKey, fioContentType: 'new_funds_content', privateKey: wallet1.privateKey, @@ -125,6 +137,10 @@ describe('Test methods', () => { }); it('check decrypted content', async () => { + if (!decryptContentParams.content) { + throw new Error('ENCRYPTED_CONTENT_STRING is not set'); + } + const result = decryptContent(decryptContentParams); expect(result.memo).toEqual(MEMO_PHRASE); @@ -147,6 +163,19 @@ describe('Test methods', () => { expect(decryptResult.memo).toEqual(encryptContentParams.content.memo); expect(decryptResult.amount).toEqual(encryptContentParams.content.amount); expect(decryptResult.payee_public_address).toEqual(wallet1.publicKey); + expect(decryptResult.payer_public_address).toEqual(wallet2.publicKey); + expect(decryptResult.chain_code).toEqual( + encryptContentParams.content.chain_code + ); + expect(decryptResult.token_code).toEqual( + encryptContentParams.content.token_code + ); + expect(decryptResult.status).toEqual(encryptContentParams.content.status); + expect(decryptResult.obt_id).toEqual(encryptContentParams.content.obt_id); + expect(decryptResult.hash).toEqual(encryptContentParams.content.hash); + expect(decryptResult.offline_url).toEqual( + encryptContentParams.content.offline_url + ); const decryptResult2 = decryptContent({ content: result, @@ -158,5 +187,18 @@ describe('Test methods', () => { expect(decryptResult2.memo).toEqual(encryptContentParams.content.memo); expect(decryptResult2.amount).toEqual(encryptContentParams.content.amount); expect(decryptResult2.payee_public_address).toEqual(wallet1.publicKey); + expect(decryptResult2.payer_public_address).toEqual(wallet2.publicKey); + expect(decryptResult2.chain_code).toEqual( + encryptContentParams.content.chain_code + ); + expect(decryptResult2.token_code).toEqual( + encryptContentParams.content.token_code + ); + expect(decryptResult2.status).toEqual(encryptContentParams.content.status); + expect(decryptResult2.obt_id).toEqual(encryptContentParams.content.obt_id); + expect(decryptResult2.hash).toEqual(encryptContentParams.content.hash); + expect(decryptResult2.offline_url).toEqual( + encryptContentParams.content.offline_url + ); }); });