Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/application/blinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { OwnedInput } from 'liquidjs-lib';
import { Pset, AssetHash, Blinder, ZKPGenerator, ZKPValidator } from 'liquidjs-lib';
import type { WalletRepository } from '../domain/repository';
import type { Confidential } from 'liquidjs-lib/src/confidential';
import { h2bReversed } from './utils';

export class BlinderService {
private zkpValidator: ZKPValidator;
Expand All @@ -23,8 +24,8 @@ export class BlinderService {
if (!unblindOutput || !unblindOutput.blindingData) continue;
ownedInputs.push({
asset: AssetHash.fromHex(unblindOutput.blindingData.asset).bytesWithoutPrefix,
assetBlindingFactor: Buffer.from(unblindOutput.blindingData.assetBlindingFactor, 'hex'),
valueBlindingFactor: Buffer.from(unblindOutput.blindingData.valueBlindingFactor, 'hex'),
assetBlindingFactor: h2bReversed(unblindOutput.blindingData.assetBlindingFactor),
valueBlindingFactor: h2bReversed(unblindOutput.blindingData.valueBlindingFactor),
value: unblindOutput.blindingData.value.toString(),
index: inputIndex,
});
Expand Down
5 changes: 3 additions & 2 deletions src/application/unblinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
} from '../domain/repository';
import { DefaultAssetRegistry } from '../port/asset-registry';
import type { UnblindingData } from 'marina-provider';
import { b2hReversed } from './utils';

const slip77 = SLIP77Factory(ecc);

Expand Down Expand Up @@ -61,8 +62,8 @@ export class WalletRepositoryUnblinder implements Unblinder {
unblindingResults.push({
value: parseInt(unblinded.value, 10),
asset: AssetHash.fromBytes(unblinded.asset).hex,
assetBlindingFactor: unblinded.assetBlindingFactor.toString('hex'),
valueBlindingFactor: unblinded.valueBlindingFactor.toString('hex'),
assetBlindingFactor: b2hReversed(unblinded.assetBlindingFactor),
valueBlindingFactor: b2hReversed(unblinded.valueBlindingFactor),
});
} catch (e: unknown) {
if (e instanceof Error) {
Expand Down
8 changes: 8 additions & 0 deletions src/application/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
export function h2b(hex: string): Buffer {
return Buffer.from(hex, 'hex');
}

export function b2hReversed(buffer: Buffer): string {
return Buffer.from(buffer).reverse().toString('hex');
}

export function h2bReversed(hex: string): Buffer {
return h2b(hex).reverse();
}
4 changes: 2 additions & 2 deletions src/domain/pset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ function castTopupData(raw: RawTopupWithAssetData): TopupWithAssetReply {
inBlindingData: raw.inBlindingData.map((data) => ({
asset: data.asset,
value: parseInt(data.value, 10),
assetBlindingFactor: Buffer.from(data.assetBlinder, 'base64').reverse().toString('hex'),
valueBlindingFactor: Buffer.from(data.valueBlinder, 'base64').reverse().toString('hex'),
assetBlindingFactor: Buffer.from(data.assetBlinder, 'base64').toString('hex'),
valueBlindingFactor: Buffer.from(data.valueBlinder, 'base64').toString('hex'),
})),
topup: {
topupId: raw.topup.topupId,
Expand Down
6 changes: 1 addition & 5 deletions src/domain/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ export function computeBalances(utxos: UnblindedOutput[]): Record<string, number
return balances;
}

const reverseHex = (hex: string) => Buffer.from(hex, 'hex').reverse().toString('hex');

export async function makeURLwithBlinders(
transaction: Transaction,
appRepository: AppRepository,
Expand All @@ -63,9 +61,7 @@ export async function makeURLwithBlinders(
if (!data || !data.blindingData) continue;

blinders.push(
`${data.blindingData.value},${data.blindingData.asset},${reverseHex(
data.blindingData.valueBlindingFactor
)},${reverseHex(data.blindingData.assetBlindingFactor)}`
`${data.blindingData.value},${data.blindingData.asset},${data.blindingData.valueBlindingFactor},${data.blindingData.assetBlindingFactor}`
);
}

Expand Down
5 changes: 3 additions & 2 deletions test/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
import { TaxiStorageAPI } from '../src/infrastructure/storage/taxi-repository';
import { initWalletRepository } from '../src/domain/repository';
import { computeBalances, lockTransactionInputs } from '../src/domain/transaction';
import { h2bReversed } from '../src/application/utils';

// we need this to mock the browser.storage.local calls in repositories
// replace webextension-polyfill with a mock defined in __mocks__ folder
Expand Down Expand Up @@ -365,8 +366,8 @@ describe('Application Layer', () => {
.from(utxo.txid, utxo.vout, witnessUtxo!, {
asset: AssetHash.fromHex(utxo.blindingData!.asset).bytesWithoutPrefix,
value: utxo.blindingData!.value.toString(10),
assetBlindingFactor: Buffer.from(utxo.blindingData!.assetBlindingFactor, 'hex'),
valueBlindingFactor: Buffer.from(utxo.blindingData!.valueBlindingFactor, 'hex'),
assetBlindingFactor: h2bReversed(utxo.blindingData!.assetBlindingFactor),
valueBlindingFactor: h2bReversed(utxo.blindingData!.valueBlindingFactor),
})
.functions.transferWithSum(8, 2, {
signTransaction: async (psetb64: string) => {
Expand Down