algosdk 2.9.0 → 2.11.0
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.
- package/README.md +4 -4
- package/dist/browser/algosdk.min.js +1 -1
- package/dist/browser/algosdk.min.js.map +1 -1
- package/dist/cjs/client/v2/algod/block.js +21 -0
- package/dist/cjs/client/v2/algod/block.js.map +1 -1
- package/dist/cjs/client/v2/indexer/indexer.js +15 -0
- package/dist/cjs/client/v2/indexer/indexer.js.map +1 -1
- package/dist/cjs/client/v2/indexer/models/types.js +168 -3
- package/dist/cjs/client/v2/indexer/models/types.js.map +1 -1
- package/dist/cjs/client/v2/indexer/searchForBlockHeaders.js +209 -0
- package/dist/cjs/client/v2/indexer/searchForBlockHeaders.js.map +1 -0
- package/dist/cjs/transaction.js +102 -0
- package/dist/cjs/transaction.js.map +1 -1
- package/dist/cjs/types/transactions/base.js +6 -1
- package/dist/cjs/types/transactions/base.js.map +1 -1
- package/dist/cjs/types/transactions/heartbeat.js +3 -0
- package/dist/cjs/types/transactions/heartbeat.js.map +1 -0
- package/dist/cjs/types/transactions/index.js.map +1 -1
- package/dist/esm/client/v2/algod/block.js +21 -0
- package/dist/esm/client/v2/algod/block.js.map +1 -1
- package/dist/esm/client/v2/indexer/indexer.js +15 -0
- package/dist/esm/client/v2/indexer/indexer.js.map +1 -1
- package/dist/esm/client/v2/indexer/models/types.js +163 -1
- package/dist/esm/client/v2/indexer/models/types.js.map +1 -1
- package/dist/esm/client/v2/indexer/searchForBlockHeaders.js +203 -0
- package/dist/esm/client/v2/indexer/searchForBlockHeaders.js.map +1 -0
- package/dist/esm/transaction.js +102 -0
- package/dist/esm/transaction.js.map +1 -1
- package/dist/esm/types/transactions/base.js +6 -1
- package/dist/esm/types/transactions/base.js.map +1 -1
- package/dist/esm/types/transactions/heartbeat.js +2 -0
- package/dist/esm/types/transactions/heartbeat.js.map +1 -0
- package/dist/esm/types/transactions/index.js.map +1 -1
- package/dist/types/client/v2/algod/block.d.ts +18 -0
- package/dist/types/client/v2/indexer/indexer.d.ts +13 -0
- package/dist/types/client/v2/indexer/models/types.d.ts +134 -1
- package/dist/types/client/v2/indexer/searchForBlockHeaders.d.ts +172 -0
- package/dist/types/transaction.d.ts +30 -2
- package/dist/types/types/transactions/base.d.ts +17 -1
- package/dist/types/types/transactions/encoded.d.ts +54 -0
- package/dist/types/types/transactions/heartbeat.d.ts +8 -0
- package/dist/types/types/transactions/index.d.ts +3 -1
- package/package.json +1 -1
- package/src/client/v2/algod/block.ts +22 -0
- package/src/client/v2/indexer/indexer.ts +16 -0
- package/src/client/v2/indexer/models/types.ts +294 -0
- package/src/client/v2/indexer/searchForBlockHeaders.ts +212 -0
- package/src/transaction.ts +131 -0
- package/src/types/transactions/base.ts +20 -1
- package/src/types/transactions/encoded.ts +65 -0
- package/src/types/transactions/heartbeat.ts +14 -0
- package/src/types/transactions/index.ts +4 -1
package/src/transaction.ts
CHANGED
|
@@ -19,6 +19,8 @@ import AnyTransaction, {
|
|
|
19
19
|
EncodedSignedTransaction,
|
|
20
20
|
EncodedMultisig,
|
|
21
21
|
EncodedLogicSig,
|
|
22
|
+
EncodedHeartbeatFields,
|
|
23
|
+
EncodedHeartbeatProof,
|
|
22
24
|
} from './types/transactions';
|
|
23
25
|
import { Address } from './types/address';
|
|
24
26
|
|
|
@@ -38,6 +40,100 @@ const KEYREG_STATE_PROOF_KEY_LENGTH = 64;
|
|
|
38
40
|
type AnyTransactionWithParams = MustHaveSuggestedParams<AnyTransaction>;
|
|
39
41
|
type AnyTransactionWithParamsInline = MustHaveSuggestedParamsInline<AnyTransaction>;
|
|
40
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Object representing a heartbeat proof
|
|
45
|
+
*/
|
|
46
|
+
class HeartbeatProof {
|
|
47
|
+
s: Buffer;
|
|
48
|
+
p: Buffer;
|
|
49
|
+
p2: Buffer;
|
|
50
|
+
p1s: Buffer;
|
|
51
|
+
p2s: Buffer;
|
|
52
|
+
|
|
53
|
+
constructor(sig: Buffer, pk: Buffer, pk2: Buffer, p1s: Buffer, p2s: Buffer) {
|
|
54
|
+
this.s = sig;
|
|
55
|
+
this.p = pk;
|
|
56
|
+
this.p2 = pk2;
|
|
57
|
+
this.p1s = p1s;
|
|
58
|
+
this.p2s = p2s;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// eslint-disable-next-line camelcase
|
|
62
|
+
static from_obj_for_encoding(
|
|
63
|
+
encHbFields: EncodedHeartbeatProof
|
|
64
|
+
): HeartbeatProof {
|
|
65
|
+
const proof = Object.create(this.prototype) as HeartbeatProof;
|
|
66
|
+
proof.s = encHbFields.s;
|
|
67
|
+
proof.p = encHbFields.p;
|
|
68
|
+
proof.p2 = encHbFields.p2;
|
|
69
|
+
proof.p1s = encHbFields.p1s;
|
|
70
|
+
proof.p2s = encHbFields.p2s;
|
|
71
|
+
return proof;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// eslint-disable-next-line camelcase
|
|
75
|
+
get_obj_for_encoding() {
|
|
76
|
+
const fields: EncodedHeartbeatProof = {
|
|
77
|
+
s: this.s,
|
|
78
|
+
p: this.p,
|
|
79
|
+
p2: this.p2,
|
|
80
|
+
p1s: this.p1s,
|
|
81
|
+
p2s: this.p2s,
|
|
82
|
+
};
|
|
83
|
+
return fields;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Object representing a heartbeat transaction
|
|
89
|
+
*/
|
|
90
|
+
class HeartbeatFields {
|
|
91
|
+
a: string | Address;
|
|
92
|
+
prf: HeartbeatProof;
|
|
93
|
+
sd: Buffer;
|
|
94
|
+
vid: Buffer;
|
|
95
|
+
kd: number;
|
|
96
|
+
|
|
97
|
+
constructor(
|
|
98
|
+
addr: string | Address,
|
|
99
|
+
proof: EncodedHeartbeatProof,
|
|
100
|
+
seed: Buffer,
|
|
101
|
+
voteID: Buffer,
|
|
102
|
+
kd: number
|
|
103
|
+
) {
|
|
104
|
+
this.a = addr;
|
|
105
|
+
this.prf = HeartbeatProof.from_obj_for_encoding(proof);
|
|
106
|
+
this.sd = seed;
|
|
107
|
+
this.vid = voteID;
|
|
108
|
+
this.kd = kd;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// eslint-disable-next-line camelcase
|
|
112
|
+
static from_obj_for_encoding(
|
|
113
|
+
encHbFields: EncodedHeartbeatFields
|
|
114
|
+
): HeartbeatFields {
|
|
115
|
+
const fields = Object.create(this.prototype) as HeartbeatFields;
|
|
116
|
+
fields.a = address.decodeAddress(address.encodeAddress(encHbFields.a));
|
|
117
|
+
fields.prf = HeartbeatProof.from_obj_for_encoding(encHbFields.prf);
|
|
118
|
+
fields.sd = Buffer.from(encHbFields.sd);
|
|
119
|
+
fields.vid = Buffer.from(encHbFields.vid);
|
|
120
|
+
fields.kd = encHbFields.kd;
|
|
121
|
+
return fields;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// eslint-disable-next-line camelcase
|
|
125
|
+
get_obj_for_encoding() {
|
|
126
|
+
const fields: EncodedHeartbeatFields = {
|
|
127
|
+
a: Buffer.from((this.a as Address).publicKey),
|
|
128
|
+
prf: this.prf.get_obj_for_encoding(),
|
|
129
|
+
sd: this.sd,
|
|
130
|
+
vid: this.vid,
|
|
131
|
+
kd: this.kd,
|
|
132
|
+
};
|
|
133
|
+
return fields;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
41
137
|
/**
|
|
42
138
|
* A modified version of the transaction params. Represents the internal structure that the Transaction class uses
|
|
43
139
|
* to store inputted transaction objects.
|
|
@@ -62,6 +158,7 @@ interface TransactionStorageStructure
|
|
|
62
158
|
| 'appAccounts'
|
|
63
159
|
| 'suggestedParams'
|
|
64
160
|
| 'reKeyTo'
|
|
161
|
+
| 'heartbeatFields' // redefine type to silent TS error about 'string | Address' and 'string' incompatibility
|
|
65
162
|
> {
|
|
66
163
|
from: string | Address;
|
|
67
164
|
to: string | Address;
|
|
@@ -117,6 +214,7 @@ interface TransactionStorageStructure
|
|
|
117
214
|
stateProofType?: number | bigint;
|
|
118
215
|
stateProof?: Uint8Array;
|
|
119
216
|
stateProofMessage?: Uint8Array;
|
|
217
|
+
heartbeatFields?: HeartbeatFields;
|
|
120
218
|
}
|
|
121
219
|
|
|
122
220
|
function getKeyregKey(
|
|
@@ -209,6 +307,7 @@ export class Transaction implements TransactionStorageStructure {
|
|
|
209
307
|
stateProofType?: number | bigint;
|
|
210
308
|
stateProof?: Uint8Array;
|
|
211
309
|
stateProofMessage?: Uint8Array;
|
|
310
|
+
heartbeatFields?: HeartbeatFields;
|
|
212
311
|
|
|
213
312
|
constructor({ ...transaction }: AnyTransaction) {
|
|
214
313
|
// Populate defaults
|
|
@@ -574,6 +673,10 @@ export class Transaction implements TransactionStorageStructure {
|
|
|
574
673
|
} else {
|
|
575
674
|
txn.stateProof = new Uint8Array(0);
|
|
576
675
|
}
|
|
676
|
+
if (txn.heartbeatFields !== undefined) {
|
|
677
|
+
if (txn.heartbeatFields.constructor !== HeartbeatFields)
|
|
678
|
+
throw Error('heartbeatFields must be a HeartbeatFields.');
|
|
679
|
+
}
|
|
577
680
|
}
|
|
578
681
|
|
|
579
682
|
// eslint-disable-next-line camelcase
|
|
@@ -918,6 +1021,28 @@ export class Transaction implements TransactionStorageStructure {
|
|
|
918
1021
|
if (txn.grp === undefined) delete txn.grp;
|
|
919
1022
|
return txn;
|
|
920
1023
|
}
|
|
1024
|
+
if (this.type === 'hb') {
|
|
1025
|
+
// heartbeat txn
|
|
1026
|
+
const txn: EncodedTransaction = {
|
|
1027
|
+
fee: this.fee,
|
|
1028
|
+
fv: this.firstRound,
|
|
1029
|
+
lv: this.lastRound,
|
|
1030
|
+
note: Buffer.from(this.note),
|
|
1031
|
+
snd: Buffer.from(this.from.publicKey),
|
|
1032
|
+
type: this.type,
|
|
1033
|
+
gen: this.genesisID,
|
|
1034
|
+
gh: this.genesisHash,
|
|
1035
|
+
lx: Buffer.from(this.lease),
|
|
1036
|
+
hb: this.heartbeatFields.get_obj_for_encoding(),
|
|
1037
|
+
};
|
|
1038
|
+
// allowed zero values
|
|
1039
|
+
if (!txn.note.length) delete txn.note;
|
|
1040
|
+
if (!txn.lx.length) delete txn.lx;
|
|
1041
|
+
if (!txn.fee) delete txn.fee;
|
|
1042
|
+
if (!txn.gen) delete txn.gen;
|
|
1043
|
+
if (txn.grp === undefined) delete txn.grp;
|
|
1044
|
+
return txn;
|
|
1045
|
+
}
|
|
921
1046
|
|
|
922
1047
|
return undefined;
|
|
923
1048
|
}
|
|
@@ -1105,6 +1230,12 @@ export class Transaction implements TransactionStorageStructure {
|
|
|
1105
1230
|
if (txnForEnc.spmsg !== undefined) {
|
|
1106
1231
|
txn.stateProofMessage = txnForEnc.spmsg;
|
|
1107
1232
|
}
|
|
1233
|
+
} else if (txnForEnc.type === 'hb') {
|
|
1234
|
+
if (txnForEnc.hb !== undefined) {
|
|
1235
|
+
txn.heartbeatFields = HeartbeatFields.from_obj_for_encoding(
|
|
1236
|
+
txnForEnc.hb
|
|
1237
|
+
);
|
|
1238
|
+
}
|
|
1108
1239
|
}
|
|
1109
1240
|
return txn;
|
|
1110
1241
|
}
|
|
@@ -37,6 +37,11 @@ export enum TransactionType {
|
|
|
37
37
|
* State proof transaction
|
|
38
38
|
*/
|
|
39
39
|
stpf = 'stpf',
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Heartbeat transaction
|
|
43
|
+
*/
|
|
44
|
+
hb = 'hb',
|
|
40
45
|
}
|
|
41
46
|
|
|
42
47
|
export function isTransactionType(s: string): s is TransactionType {
|
|
@@ -47,7 +52,8 @@ export function isTransactionType(s: string): s is TransactionType {
|
|
|
47
52
|
s === TransactionType.axfer ||
|
|
48
53
|
s === TransactionType.afrz ||
|
|
49
54
|
s === TransactionType.appl ||
|
|
50
|
-
s === TransactionType.stpf
|
|
55
|
+
s === TransactionType.stpf ||
|
|
56
|
+
s === TransactionType.hb
|
|
51
57
|
);
|
|
52
58
|
}
|
|
53
59
|
|
|
@@ -152,6 +158,14 @@ export interface BoxReference {
|
|
|
152
158
|
name: Uint8Array;
|
|
153
159
|
}
|
|
154
160
|
|
|
161
|
+
interface heartbeatFields {
|
|
162
|
+
a: string;
|
|
163
|
+
prf: Uint8Array;
|
|
164
|
+
sd: Uint8Array;
|
|
165
|
+
vid: Uint8Array;
|
|
166
|
+
kd: number;
|
|
167
|
+
}
|
|
168
|
+
|
|
155
169
|
/**
|
|
156
170
|
* A full list of all available transaction parameters
|
|
157
171
|
*
|
|
@@ -432,4 +446,9 @@ export interface TransactionParams {
|
|
|
432
446
|
* Byte array containing the state proof message.
|
|
433
447
|
*/
|
|
434
448
|
stateProofMessage?: Uint8Array;
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* HeartbeatFields fields
|
|
452
|
+
*/
|
|
453
|
+
heartbeatFields?: heartbeatFields;
|
|
435
454
|
}
|
|
@@ -97,6 +97,66 @@ export interface EncodedBoxReference {
|
|
|
97
97
|
n: Uint8Array;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
/**
|
|
101
|
+
* A structure for an encoded heartbeat proof fields object
|
|
102
|
+
*/
|
|
103
|
+
export interface EncodedHeartbeatProof {
|
|
104
|
+
/**
|
|
105
|
+
* Sig
|
|
106
|
+
*/
|
|
107
|
+
s: Buffer;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* PK
|
|
111
|
+
*/
|
|
112
|
+
p: Buffer;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* PK2
|
|
116
|
+
*/
|
|
117
|
+
p2: Buffer;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* PK1Sig
|
|
121
|
+
*/
|
|
122
|
+
p1s: Buffer;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* PK2Sig
|
|
126
|
+
*/
|
|
127
|
+
p2s: Buffer;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* A structure for an encoded heartbeat fields object
|
|
132
|
+
*/
|
|
133
|
+
export interface EncodedHeartbeatFields {
|
|
134
|
+
/**
|
|
135
|
+
* HbAddress
|
|
136
|
+
*/
|
|
137
|
+
a: Buffer;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* HbProof
|
|
141
|
+
*/
|
|
142
|
+
prf: EncodedHeartbeatProof;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* HbSeed
|
|
146
|
+
*/
|
|
147
|
+
sd: Buffer;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* HbVoteID
|
|
151
|
+
*/
|
|
152
|
+
vid: Buffer;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* HbKeyDilution
|
|
156
|
+
*/
|
|
157
|
+
kd: number;
|
|
158
|
+
}
|
|
159
|
+
|
|
100
160
|
/**
|
|
101
161
|
* A rough structure for the encoded transaction object. Every property is labelled with its associated Transaction type property
|
|
102
162
|
*/
|
|
@@ -330,6 +390,11 @@ export interface EncodedTransaction {
|
|
|
330
390
|
* stateProofMessage
|
|
331
391
|
*/
|
|
332
392
|
spmsg?: Buffer;
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* heartbeat fields
|
|
396
|
+
*/
|
|
397
|
+
hb?: EncodedHeartbeatFields;
|
|
333
398
|
}
|
|
334
399
|
|
|
335
400
|
export interface EncodedSubsig {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TransactionType, TransactionParams } from './base';
|
|
2
|
+
import { ConstructTransaction } from './builder';
|
|
3
|
+
|
|
4
|
+
type SpecificParameters = Pick<TransactionParams, 'heartbeatFields'>;
|
|
5
|
+
|
|
6
|
+
interface Overwrites {
|
|
7
|
+
type?: TransactionType.hb;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type HeartbeatTransaction = ConstructTransaction<
|
|
11
|
+
SpecificParameters,
|
|
12
|
+
Overwrites
|
|
13
|
+
>;
|
|
14
|
+
export default HeartbeatTransaction;
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
ApplicationNoOpTransaction as AppNoOpTxn,
|
|
18
18
|
} from './application';
|
|
19
19
|
import StateProofTxn from './stateproof';
|
|
20
|
+
import HeartbeatTxn from './heartbeat';
|
|
20
21
|
|
|
21
22
|
// Utilities
|
|
22
23
|
export {
|
|
@@ -51,6 +52,7 @@ export {
|
|
|
51
52
|
ApplicationNoOpTransaction as AppNoOpTxn,
|
|
52
53
|
} from './application';
|
|
53
54
|
export { default as StateProofTxn } from './stateproof';
|
|
55
|
+
export { default as HeartbeatTransaction } from './heartbeat';
|
|
54
56
|
|
|
55
57
|
// All possible transaction types
|
|
56
58
|
type AnyTransaction =
|
|
@@ -68,5 +70,6 @@ type AnyTransaction =
|
|
|
68
70
|
| AppCloseOutTxn
|
|
69
71
|
| AppClearStateTxn
|
|
70
72
|
| AppNoOpTxn
|
|
71
|
-
| StateProofTxn
|
|
73
|
+
| StateProofTxn
|
|
74
|
+
| HeartbeatTxn;
|
|
72
75
|
export default AnyTransaction;
|