@dignetwork/dig-sdk 0.0.1-alpha.24 → 0.0.1-alpha.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -14,11 +14,12 @@ export declare class DigPeer {
|
|
|
14
14
|
get IpAddress(): string;
|
|
15
15
|
validateStore(rootHash: string, keys: string[]): Promise<boolean>;
|
|
16
16
|
isSynced(): Promise<boolean>;
|
|
17
|
-
static sendEqualBulkPayments(walletName: string, addresses: string[], totalAmount: bigint): Promise<void>;
|
|
17
|
+
static sendEqualBulkPayments(walletName: string, addresses: string[], totalAmount: bigint, memo: string[]): Promise<void>;
|
|
18
18
|
static sendBulkPayments(walletName: string, outputs: {
|
|
19
19
|
puzzleHash: Buffer;
|
|
20
20
|
amount: bigint;
|
|
21
21
|
}[]): Promise<void>;
|
|
22
|
-
sendPayment(walletName: string, amount: bigint): Promise<void>;
|
|
22
|
+
sendPayment(walletName: string, amount: bigint, memo?: string[]): Promise<void>;
|
|
23
|
+
createPaymentHint(storeId: Buffer): string;
|
|
23
24
|
}
|
|
24
25
|
//# sourceMappingURL=DigPeer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DigPeer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/DigPeer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAcpD,qBAAa,OAAO;IAClB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,kBAAkB,CAAoB;IAC9C,OAAO,CAAC,gBAAgB,CAAkB;gBAE9B,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAS9C,IAAW,aAAa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MAAM,EACnB,IAAI,EAAE,MAAM,EAAE,GACb,OAAO,CAAC,IAAI,CAAC;WAyBI,gBAAgB,CAClC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,GAChD,OAAO,CAAC,IAAI,CAAC;IAwCH,WAAW,CACtB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,IAAI,GAAE,MAAM,EAAO,GAClB,OAAO,CAAC,IAAI,CAAC;IAYT,iBAAiB,CAAC,OAAO,EAAE,MAAM;CAoBzC"}
|
|
@@ -137,7 +137,7 @@ class DigPeer {
|
|
|
137
137
|
return false;
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
-
static sendEqualBulkPayments(walletName, addresses, totalAmount) {
|
|
140
|
+
static sendEqualBulkPayments(walletName, addresses, totalAmount, memo) {
|
|
141
141
|
// Use a Set to ensure unique addresses
|
|
142
142
|
const uniqueAddresses = Array.from(new Set(addresses));
|
|
143
143
|
// Convert unique addresses to puzzle hashes
|
|
@@ -148,6 +148,7 @@ class DigPeer {
|
|
|
148
148
|
const outputs = puzzleHashes.map((puzzleHash) => ({
|
|
149
149
|
puzzleHash,
|
|
150
150
|
amount: amountPerPuzzleHash,
|
|
151
|
+
memo,
|
|
151
152
|
}));
|
|
152
153
|
// Call the sendBulkPayments function with the generated outputs
|
|
153
154
|
return DigPeer.sendBulkPayments(walletName, outputs);
|
|
@@ -168,12 +169,31 @@ class DigPeer {
|
|
|
168
169
|
}
|
|
169
170
|
await blockchain_2.FullNodePeer.waitForConfirmation((0, datalayer_driver_1.getCoinId)(coins[0]));
|
|
170
171
|
}
|
|
171
|
-
async sendPayment(walletName, amount) {
|
|
172
|
+
async sendPayment(walletName, amount, memo = []) {
|
|
172
173
|
const paymentAddress = await this.contentServer.getPaymentAddress();
|
|
173
174
|
const paymentAddressPuzzleHash = (0, datalayer_driver_1.addressToPuzzleHash)(paymentAddress);
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
175
|
+
const output = {
|
|
176
|
+
puzzleHash: paymentAddressPuzzleHash,
|
|
177
|
+
amount,
|
|
178
|
+
memo,
|
|
179
|
+
};
|
|
180
|
+
return DigPeer.sendBulkPayments(walletName, [output]);
|
|
181
|
+
}
|
|
182
|
+
createPaymentHint(storeId) {
|
|
183
|
+
// Ensure the input is a 32-byte buffer
|
|
184
|
+
if (!Buffer.isBuffer(storeId) || storeId.length !== 32) {
|
|
185
|
+
throw new Error("Invalid input. Must be a 32-byte buffer.");
|
|
186
|
+
}
|
|
187
|
+
// Define the seed
|
|
188
|
+
const seed = "dig";
|
|
189
|
+
// Combine the seed and the original buffer
|
|
190
|
+
const combinedBuffer = Buffer.concat([Buffer.from(seed), storeId]);
|
|
191
|
+
// Apply SHA-256 hash to the combined buffer
|
|
192
|
+
const hash = crypto_1.default.createHash("sha256");
|
|
193
|
+
hash.update(combinedBuffer);
|
|
194
|
+
const transformedBuffer = hash.digest();
|
|
195
|
+
// Return the 32-byte hash as a hex string
|
|
196
|
+
return transformedBuffer.toString("hex");
|
|
177
197
|
}
|
|
178
198
|
}
|
|
179
199
|
exports.DigPeer = DigPeer;
|
|
@@ -12,12 +12,18 @@ export declare class ServerCoin {
|
|
|
12
12
|
getActiveEpochPeers(blacklist?: string[]): Promise<string[]>;
|
|
13
13
|
sampleCurrentEpoch(sampleSize?: number, blacklist?: string[]): Promise<string[]>;
|
|
14
14
|
sampleServerCoinsByEpoch(epoch: number, sampleSize?: number, blacklist?: string[]): Promise<string[]>;
|
|
15
|
-
static getCurrentEpoch():
|
|
15
|
+
static getCurrentEpoch(): {
|
|
16
|
+
epoch: number;
|
|
17
|
+
round: number;
|
|
18
|
+
};
|
|
16
19
|
ensureServerCoinExists(peerIp: string): Promise<void>;
|
|
17
20
|
meltOutdatedEpochs(peerIp: string): Promise<void>;
|
|
18
21
|
static meltUntrackedStoreCoins(): Promise<void>;
|
|
19
22
|
private getServerCoinsForStore;
|
|
20
23
|
hasEpochCoinBeenCreated(currentEpoch: number, peerIp: string): Promise<boolean>;
|
|
21
|
-
static
|
|
24
|
+
static calculateEpochAndRound(currentTimestampUTC: Date): {
|
|
25
|
+
epoch: number;
|
|
26
|
+
round: number;
|
|
27
|
+
};
|
|
22
28
|
}
|
|
23
29
|
//# sourceMappingURL=ServerCoin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServerCoin.d.ts","sourceRoot":"","sources":["../../src/blockchain/ServerCoin.ts"],"names":[],"mappings":"AACA,OAAO,EAML,UAAU,IAAI,gBAAgB,EAE/B,MAAM,kBAAkB,CAAC;AAI1B,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAMrD,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAAS;IACxB,gBAAuB,iBAAiB,eAEtC;gBAEU,OAAO,EAAE,MAAM;IAKd,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA2DzD,kBAAkB,CAC7B,UAAU,EAAE,gBAAgB,EAC5B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC;IAqBH,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAoDjD,oBAAoB;IAerB,gBAAgB,CAC3B,KAAK,EAAE,MAAM,EACb,SAAS,GAAE,MAAM,EAAO,GACvB,OAAO,CAAC,MAAM,EAAE,CAAC;IAoCP,mBAAmB,CAC9B,SAAS,GAAE,MAAM,EAAO,GACvB,OAAO,CAAC,MAAM,EAAE,CAAC;IAMP,kBAAkB,CAC7B,UAAU,GAAE,MAAU,EACtB,SAAS,GAAE,MAAM,EAAO,GACvB,OAAO,CAAC,MAAM,EAAE,CAAC;IAMP,wBAAwB,CACnC,KAAK,EAAE,MAAM,EACb,UAAU,GAAE,MA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,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiDrD,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;WA+B1C,uBAAuB;YAkE7B,sBAAsB;IAWvB,uBAAuB,CAClC,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC;WAuBL,sBAAsB,CAAC,mBAAmB,EAAE,IAAI,GAAG;QAC/D,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;KACf;CA2BF"}
|
|
@@ -23,7 +23,7 @@ class ServerCoin {
|
|
|
23
23
|
const wallet = await Wallet_1.Wallet.load("default");
|
|
24
24
|
const publicSyntheticKey = await wallet.getPublicSyntheticKey();
|
|
25
25
|
const serverCoinCreationCoins = await (0, coins_1.selectUnspentCoins)(peer, BigInt(serverCoinCollateral), BigInt(1000000));
|
|
26
|
-
const currentEpoch = ServerCoin.getCurrentEpoch();
|
|
26
|
+
const { epoch: currentEpoch } = ServerCoin.getCurrentEpoch();
|
|
27
27
|
const epochBasedHint = (0, datalayer_driver_1.morphLauncherId)(Buffer.from(this.storeId, "hex"), BigInt(currentEpoch));
|
|
28
28
|
const newServerCoin = (0, datalayer_driver_1.createServerCoin)(publicSyntheticKey, serverCoinCreationCoins, epochBasedHint, [peerIp], BigInt(serverCoinCollateral), BigInt(1000000));
|
|
29
29
|
const combinedCoinSpends = [...newServerCoin.coinSpends];
|
|
@@ -115,12 +115,12 @@ class ServerCoin {
|
|
|
115
115
|
return Array.from(serverCoinPeers);
|
|
116
116
|
}
|
|
117
117
|
async getActiveEpochPeers(blacklist = []) {
|
|
118
|
-
const epoch = ServerCoin.getCurrentEpoch();
|
|
118
|
+
const { epoch } = ServerCoin.getCurrentEpoch();
|
|
119
119
|
return this.getAllEpochPeers(epoch, blacklist);
|
|
120
120
|
}
|
|
121
121
|
// Sample server coins for the current epoch
|
|
122
122
|
async sampleCurrentEpoch(sampleSize = 5, blacklist = []) {
|
|
123
|
-
const epoch = ServerCoin.getCurrentEpoch();
|
|
123
|
+
const { epoch } = ServerCoin.getCurrentEpoch();
|
|
124
124
|
return this.sampleServerCoinsByEpoch(epoch, sampleSize, blacklist);
|
|
125
125
|
}
|
|
126
126
|
// Sample server coins by epoch
|
|
@@ -130,13 +130,13 @@ class ServerCoin {
|
|
|
130
130
|
}
|
|
131
131
|
// Get the current epoch based on the current timestamp
|
|
132
132
|
static getCurrentEpoch() {
|
|
133
|
-
return ServerCoin.
|
|
133
|
+
return ServerCoin.calculateEpochAndRound(new Date());
|
|
134
134
|
}
|
|
135
135
|
// Ensure server coin exists for the current epoch
|
|
136
136
|
async ensureServerCoinExists(peerIp) {
|
|
137
137
|
try {
|
|
138
138
|
console.log(`Ensuring server coin exists for store ${this.storeId}...`);
|
|
139
|
-
const currentEpoch = ServerCoin.getCurrentEpoch();
|
|
139
|
+
const { epoch: currentEpoch } = ServerCoin.getCurrentEpoch();
|
|
140
140
|
const serverCoins = await this.getServerCoinsForStore(peerIp);
|
|
141
141
|
// Check if a server coin already exists for the current epoch
|
|
142
142
|
const existingCoin = serverCoins.find((coin) => coin.epoch === currentEpoch);
|
|
@@ -167,7 +167,7 @@ class ServerCoin {
|
|
|
167
167
|
// Melt outdated server coins
|
|
168
168
|
async meltOutdatedEpochs(peerIp) {
|
|
169
169
|
try {
|
|
170
|
-
const currentEpoch = ServerCoin.getCurrentEpoch();
|
|
170
|
+
const { epoch: currentEpoch } = ServerCoin.getCurrentEpoch();
|
|
171
171
|
let serverCoins = await this.getServerCoinsForStore(peerIp);
|
|
172
172
|
// Filter out coins that are not in the current epoch
|
|
173
173
|
const outdatedCoins = serverCoins.filter((coin) => coin.epoch < currentEpoch);
|
|
@@ -251,17 +251,23 @@ class ServerCoin {
|
|
|
251
251
|
}
|
|
252
252
|
}
|
|
253
253
|
// Static method to calculate the current epoch
|
|
254
|
-
static
|
|
254
|
+
static calculateEpochAndRound(currentTimestampUTC) {
|
|
255
255
|
const firstEpochStart = new Date(Date.UTC(2024, 8, 3, 0, 0)); // Sept 3, 2024, 00:00 UTC
|
|
256
256
|
// Convert the current timestamp to milliseconds
|
|
257
257
|
const currentTimestampMillis = currentTimestampUTC.getTime();
|
|
258
258
|
// Calculate the number of milliseconds in one epoch (7 days)
|
|
259
|
-
const millisecondsInEpoch = 7 * 24 * 60 * 60 * 1000;
|
|
259
|
+
const millisecondsInEpoch = 7 * 24 * 60 * 60 * 1000; // 7 days in milliseconds
|
|
260
260
|
// Calculate the difference in milliseconds between the current timestamp and the first epoch start
|
|
261
261
|
const differenceMillis = currentTimestampMillis - firstEpochStart.getTime();
|
|
262
262
|
// Calculate the current epoch number
|
|
263
263
|
const epochNumber = Math.floor(differenceMillis / millisecondsInEpoch) + 1;
|
|
264
|
-
|
|
264
|
+
// Calculate the milliseconds elapsed since the start of the current epoch
|
|
265
|
+
const elapsedMillisInCurrentEpoch = differenceMillis % millisecondsInEpoch;
|
|
266
|
+
// Calculate the number of milliseconds in a round (10 minutes)
|
|
267
|
+
const millisecondsInRound = 10 * 60 * 1000; // 10 minutes in milliseconds
|
|
268
|
+
// Calculate the current round number
|
|
269
|
+
const roundNumber = Math.floor(elapsedMillisInCurrentEpoch / millisecondsInRound) + 1;
|
|
270
|
+
return { epoch: epochNumber, round: roundNumber };
|
|
265
271
|
}
|
|
266
272
|
}
|
|
267
273
|
exports.ServerCoin = ServerCoin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dignetwork/dig-sdk",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.26",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"LICENSE"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
+
"@dignetwork/datalayer-driver": "^0.1.24",
|
|
28
29
|
"bip39": "^3.1.0",
|
|
29
30
|
"chia-bls": "^1.0.2",
|
|
30
31
|
"chia-config-loader": "^1.0.1",
|