Skip to content

Commit

Permalink
Merge pull request #26 from DIG-Network/release/v0.0.1-alpha.27
Browse files Browse the repository at this point in the history
Release/v0.0.1 alpha.27
  • Loading branch information
MichaelTaylor3D authored Sep 18, 2024
2 parents 82d2eb4 + 5301faa commit c447a25
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [0.0.1-alpha.26](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.25...v0.0.1-alpha.26) (2024-09-18)


### Features

* add payment hint generator ([0a3da7b](https://github.com/DIG-Network/dig-chia-sdk/commit/0a3da7bbdc7bf4d42511a62feecc29dd31fd3709))

### [0.0.1-alpha.25](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.24...v0.0.1-alpha.25) (2024-09-18)


Expand Down
95 changes: 93 additions & 2 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dignetwork/dig-sdk",
"version": "0.0.1-alpha.25",
"version": "0.0.1-alpha.26",
"description": "",
"type": "commonjs",
"main": "./dist/index.js",
Expand All @@ -25,6 +25,7 @@
"LICENSE"
],
"dependencies": {
"@dignetwork/datalayer-driver": "^0.1.24",
"bip39": "^3.1.0",
"chia-bls": "^1.0.2",
"chia-config-loader": "^1.0.1",
Expand Down
48 changes: 42 additions & 6 deletions src/DigNetwork/DigPeer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ export class DigPeer {
public static sendEqualBulkPayments(
walletName: string,
addresses: string[],
totalAmount: bigint
totalAmount: bigint,
memo: string[]
): Promise<void> {
// Use a Set to ensure unique addresses
const uniqueAddresses = Array.from(new Set(addresses));
Expand All @@ -213,6 +214,7 @@ export class DigPeer {
(puzzleHash) => ({
puzzleHash,
amount: amountPerPuzzleHash,
memo,
})
);

Expand Down Expand Up @@ -241,7 +243,12 @@ export class DigPeer {
walletName
);

const coinSpends = await sendXch(publicSyntheticKey, coins, outputs, totalFee);
const coinSpends = await sendXch(
publicSyntheticKey,
coins,
outputs,
totalFee
);

const sig = signCoinSpends(
coinSpends,
Expand All @@ -258,11 +265,40 @@ export class DigPeer {
await FullNodePeer.waitForConfirmation(getCoinId(coins[0]));
}

public async sendPayment(walletName: string, amount: bigint): Promise<void> {
public async sendPayment(
walletName: string,
amount: bigint,
memo: string[] = []
): Promise<void> {
const paymentAddress = await this.contentServer.getPaymentAddress();
const paymentAddressPuzzleHash = addressToPuzzleHash(paymentAddress);
return DigPeer.sendBulkPayments(walletName, [
{ puzzleHash: paymentAddressPuzzleHash, amount },
]);
const output: { puzzleHash: Buffer; amount: bigint; memo: string[] } = {
puzzleHash: paymentAddressPuzzleHash,
amount,
memo,
};

return DigPeer.sendBulkPayments(walletName, [output]);
}

public createPaymentHint(storeId: Buffer) {
// Ensure the input is a 32-byte buffer
if (!Buffer.isBuffer(storeId) || storeId.length !== 32) {
throw new Error("Invalid input. Must be a 32-byte buffer.");
}

// Define the seed
const seed = "dig";

// Combine the seed and the original buffer
const combinedBuffer = Buffer.concat([Buffer.from(seed), storeId]);

// Apply SHA-256 hash to the combined buffer
const hash = crypto.createHash("sha256");
hash.update(combinedBuffer);
const transformedBuffer = hash.digest();

// Return the 32-byte hash as a hex string
return transformedBuffer.toString("hex");
}
}

0 comments on commit c447a25

Please sign in to comment.