Skip to content

Commit

Permalink
feat: signature message verification (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinenerio authored Feb 3, 2025
1 parent 8d13b0d commit 843605e
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 15 deletions.
31 changes: 27 additions & 4 deletions dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2076,17 +2076,40 @@ class BrijPartnerClient {
}
return decrypted;
}
static currencyDecimals = {
// Crypto currencies
USDC: 6,
SOL: 9,
// Fiat currencies
USD: 2,
NGN: 2,
};
convertToDecimalPrecision(amount, currency) {
const decimals = BrijPartnerClient.currencyDecimals[currency];
if (decimals === undefined) {
throw new Error(`Unknown currency: ${currency}`);
}
return Math.round(amount * Math.pow(10, decimals)).toString();
}
createUserOnRampMessage({ cryptoAmount, cryptoCurrency, fiatAmount, fiatCurrency, }) {
return `${cryptoAmount}|${cryptoCurrency}|${fiatAmount}|${fiatCurrency}`;
const decimalCryptoAmount = this.convertToDecimalPrecision(cryptoAmount, cryptoCurrency);
const decimalFiatAmount = this.convertToDecimalPrecision(fiatAmount, fiatCurrency);
return `${decimalCryptoAmount}|${cryptoCurrency}|${decimalFiatAmount}|${fiatCurrency}`;
}
createUserOffRampMessage({ cryptoAmount, cryptoCurrency, fiatAmount, fiatCurrency, bankName, bankAccount, }) {
return `${cryptoAmount}|${cryptoCurrency}|${fiatAmount}|${fiatCurrency}|${bankName}|${bankAccount}`;
const decimalCryptoAmount = this.convertToDecimalPrecision(cryptoAmount, cryptoCurrency);
const decimalFiatAmount = this.convertToDecimalPrecision(fiatAmount, fiatCurrency);
return `${decimalCryptoAmount}|${cryptoCurrency}|${decimalFiatAmount}|${fiatCurrency}|${bankName}|${bankAccount}`;
}
createPartnerOnRampMessage({ cryptoAmount, cryptoCurrency, fiatAmount, fiatCurrency, bankName, bankAccount, }) {
return `${cryptoAmount}|${cryptoCurrency}|${fiatAmount}|${fiatCurrency}|${bankName}|${bankAccount}`;
const decimalCryptoAmount = this.convertToDecimalPrecision(cryptoAmount, cryptoCurrency);
const decimalFiatAmount = this.convertToDecimalPrecision(fiatAmount, fiatCurrency);
return `${decimalCryptoAmount}|${cryptoCurrency}|${decimalFiatAmount}|${fiatCurrency}|${bankName}|${bankAccount}`;
}
createPartnerOffRampMessage({ cryptoAmount, cryptoCurrency, fiatAmount, fiatCurrency, cryptoWalletAddress, }) {
return `${cryptoAmount}|${cryptoCurrency}|${fiatAmount}|${fiatCurrency}|${cryptoWalletAddress}`;
const decimalCryptoAmount = this.convertToDecimalPrecision(cryptoAmount, cryptoCurrency);
const decimalFiatAmount = this.convertToDecimalPrecision(fiatAmount, fiatCurrency);
return `${decimalCryptoAmount}|${cryptoCurrency}|${decimalFiatAmount}|${fiatCurrency}|${cryptoWalletAddress}`;
}
}

Expand Down
2 changes: 1 addition & 1 deletion dist/index.cjs.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ declare class BrijPartnerClient {
getUserInfo(publicKey: string): Promise<any>;
getUserSecretKey(publicKey: string): Promise<string>;
private decryptData;
private static readonly currencyDecimals;
private convertToDecimalPrecision;
private createUserOnRampMessage;
private createUserOffRampMessage;
private createPartnerOnRampMessage;
Expand Down
31 changes: 27 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "brij-partner-sdk",
"version": "0.6.1",
"version": "0.6.2",
"description": "",
"main": "dist/index.cjs",
"module": "dist/index.js",
Expand Down
35 changes: 31 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,25 @@ export class BrijPartnerClient {
return decrypted;
}

private static readonly currencyDecimals: Record<string, number> = {
// Crypto currencies
USDC: 6,
SOL: 9,
// Fiat currencies
USD: 2,
NGN: 2,
};

private convertToDecimalPrecision(amount: number, currency: string): string {
const decimals = BrijPartnerClient.currencyDecimals[currency];

if (decimals === undefined) {
throw new Error(`Unknown currency: ${currency}`);
}

return Math.round(amount * Math.pow(10, decimals)).toString();
}

private createUserOnRampMessage({
cryptoAmount,
cryptoCurrency,
Expand All @@ -589,7 +608,9 @@ export class BrijPartnerClient {
fiatAmount: number;
fiatCurrency: string;
}): string {
return `${cryptoAmount}|${cryptoCurrency}|${fiatAmount}|${fiatCurrency}`;
const decimalCryptoAmount = this.convertToDecimalPrecision(cryptoAmount, cryptoCurrency);
const decimalFiatAmount = this.convertToDecimalPrecision(fiatAmount, fiatCurrency);
return `${decimalCryptoAmount}|${cryptoCurrency}|${decimalFiatAmount}|${fiatCurrency}`;
}

private createUserOffRampMessage({
Expand All @@ -607,7 +628,9 @@ export class BrijPartnerClient {
bankName: string;
bankAccount: string;
}): string {
return `${cryptoAmount}|${cryptoCurrency}|${fiatAmount}|${fiatCurrency}|${bankName}|${bankAccount}`;
const decimalCryptoAmount = this.convertToDecimalPrecision(cryptoAmount, cryptoCurrency);
const decimalFiatAmount = this.convertToDecimalPrecision(fiatAmount, fiatCurrency);
return `${decimalCryptoAmount}|${cryptoCurrency}|${decimalFiatAmount}|${fiatCurrency}|${bankName}|${bankAccount}`;
}

private createPartnerOnRampMessage({
Expand All @@ -625,7 +648,9 @@ export class BrijPartnerClient {
bankName: string;
bankAccount: string;
}): string {
return `${cryptoAmount}|${cryptoCurrency}|${fiatAmount}|${fiatCurrency}|${bankName}|${bankAccount}`;
const decimalCryptoAmount = this.convertToDecimalPrecision(cryptoAmount, cryptoCurrency);
const decimalFiatAmount = this.convertToDecimalPrecision(fiatAmount, fiatCurrency);
return `${decimalCryptoAmount}|${cryptoCurrency}|${decimalFiatAmount}|${fiatCurrency}|${bankName}|${bankAccount}`;
}

private createPartnerOffRampMessage({
Expand All @@ -641,6 +666,8 @@ export class BrijPartnerClient {
fiatCurrency: string;
cryptoWalletAddress: string;
}): string {
return `${cryptoAmount}|${cryptoCurrency}|${fiatAmount}|${fiatCurrency}|${cryptoWalletAddress}`;
const decimalCryptoAmount = this.convertToDecimalPrecision(cryptoAmount, cryptoCurrency);
const decimalFiatAmount = this.convertToDecimalPrecision(fiatAmount, fiatCurrency);
return `${decimalCryptoAmount}|${cryptoCurrency}|${decimalFiatAmount}|${fiatCurrency}|${cryptoWalletAddress}`;
}
}

0 comments on commit 843605e

Please sign in to comment.