saito-js 0.0.4 → 0.0.6
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/browser/index.js +3669 -0
- package/configs.d.ts +26 -0
- package/configs.d.ts.map +1 -0
- package/index.node.d.ts +12 -0
- package/index.node.d.ts.map +1 -0
- package/index.web.d.ts +12 -0
- package/index.web.d.ts.map +1 -0
- package/lib/block.d.ts +18 -0
- package/lib/block.d.ts.map +1 -0
- package/lib/blockchain.d.ts +8 -0
- package/lib/blockchain.d.ts.map +1 -0
- package/lib/custom/custom_shared_methods.d.ts +22 -0
- package/lib/custom/custom_shared_methods.d.ts.map +1 -0
- package/lib/custom/shared_methods.web.d.ts +15 -0
- package/lib/custom/shared_methods.web.d.ts.map +1 -0
- package/lib/factory.d.ts +16 -0
- package/lib/factory.d.ts.map +1 -0
- package/lib/peer.d.ts +15 -0
- package/lib/peer.d.ts.map +1 -0
- package/lib/saito_factory.d.ts +1 -0
- package/lib/saito_factory.d.ts.map +1 -0
- package/lib/slip.d.ts +43 -0
- package/lib/slip.d.ts.map +1 -0
- package/lib/transaction.d.ts +70 -0
- package/lib/transaction.d.ts.map +1 -0
- package/lib/wallet.d.ts +18 -0
- package/lib/wallet.d.ts.map +1 -0
- package/package.json +2 -2
- package/saito.d.ts +52 -0
- package/saito.d.ts.map +1 -0
- package/server/index.js +3731 -0
- package/{shared_methods.ts → shared_methods.d.ts} +1 -18
- package/shared_methods.d.ts.map +1 -0
- package/tests/index.test.d.ts +1 -0
- package/tests/index.test.d.ts.map +1 -0
- package/.github/workflows/publish.yml +0 -50
- package/.prettierrc.json +0 -3
- package/babel.config.json +0 -13
- package/configs.ts +0 -26
- package/index.node.ts +0 -51
- package/index.web.ts +0 -47
- package/lib/block.ts +0 -42
- package/lib/blockchain.ts +0 -14
- package/lib/custom/custom_shared_methods.ts +0 -92
- package/lib/custom/shared_methods.web.ts +0 -123
- package/lib/factory.ts +0 -32
- package/lib/peer.ts +0 -50
- package/lib/saito_factory.ts +0 -18
- package/lib/slip.ts +0 -119
- package/lib/transaction.ts +0 -179
- package/lib/wallet.ts +0 -61
- package/saito.ts +0 -404
- package/tests/index.test.ts +0 -35
- package/tsconfig.json +0 -111
- package/tsconfig.testing.json +0 -19
- package/webpack.config.js +0 -136
- package/webpack.prod.config.js +0 -136
package/lib/slip.ts
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import type {WasmSlip} from 'saito-wasm/dist/types/pkg/node/index_bg';
|
|
2
|
-
|
|
3
|
-
export enum SlipType {
|
|
4
|
-
Normal = 0,
|
|
5
|
-
ATR = 1,
|
|
6
|
-
VipInput = 2,
|
|
7
|
-
VipOutput = 3,
|
|
8
|
-
MinerInput = 4,
|
|
9
|
-
MinerOutput = 5,
|
|
10
|
-
RouterInput = 6,
|
|
11
|
-
RouterOutput = 7,
|
|
12
|
-
Other = 8,
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default class Slip {
|
|
16
|
-
private slip: WasmSlip;
|
|
17
|
-
public static Type: any;
|
|
18
|
-
|
|
19
|
-
public constructor(slip?: WasmSlip, json?: any) {
|
|
20
|
-
if (!slip) {
|
|
21
|
-
this.slip = new Slip.Type();
|
|
22
|
-
} else {
|
|
23
|
-
this.slip = slip;
|
|
24
|
-
}
|
|
25
|
-
if (json) {
|
|
26
|
-
this.publicKey = json.publicKey;
|
|
27
|
-
this.type = json.type;
|
|
28
|
-
this.amount = json.amount;
|
|
29
|
-
this.index = json.index;
|
|
30
|
-
this.blockId = json.blockId;
|
|
31
|
-
this.txOrdinal = json.txOrdinal;
|
|
32
|
-
this.utxoKey = json.utxoKey;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
public get wasmSlip(): WasmSlip {
|
|
37
|
-
return this.slip;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public get type(): SlipType {
|
|
41
|
-
return this.slip.slip_type as SlipType;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
public set type(type: SlipType) {
|
|
45
|
-
this.slip.slip_type = type as number;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
public get amount(): bigint {
|
|
49
|
-
return this.slip.amount;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
public set amount(amount: bigint | number) {
|
|
53
|
-
this.slip.amount = BigInt(amount);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
public get publicKey(): string {
|
|
57
|
-
return this.slip.public_key;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
public set publicKey(key: string) {
|
|
61
|
-
this.slip.public_key = key;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public set index(index: number) {
|
|
65
|
-
this.slip.slip_index = index;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
public get index(): number {
|
|
69
|
-
return this.slip.slip_index;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
public set blockId(id: bigint) {
|
|
73
|
-
this.slip.block_id = id;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
public get blockId(): bigint {
|
|
77
|
-
return this.slip.block_id;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public set txOrdinal(ordinal: bigint) {
|
|
81
|
-
this.slip.tx_ordinal = ordinal;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
public get txOrdinal(): bigint {
|
|
85
|
-
return this.slip.tx_ordinal;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
public set utxoKey(key: string) {
|
|
89
|
-
this.slip.utxo_key = key;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
public get utxoKey(): string {
|
|
93
|
-
return this.slip.utxo_key;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
public toJson(): {
|
|
97
|
-
blockId: bigint;
|
|
98
|
-
utxoKey: string;
|
|
99
|
-
amount: bigint;
|
|
100
|
-
index: number;
|
|
101
|
-
publicKey: string;
|
|
102
|
-
txOrdinal: bigint;
|
|
103
|
-
type: any;
|
|
104
|
-
} {
|
|
105
|
-
return {
|
|
106
|
-
publicKey: this.publicKey,
|
|
107
|
-
type: this.type,
|
|
108
|
-
amount: this.amount,
|
|
109
|
-
index: this.index,
|
|
110
|
-
blockId: this.blockId,
|
|
111
|
-
txOrdinal: this.txOrdinal,
|
|
112
|
-
utxoKey: this.utxoKey,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
public clone() {
|
|
117
|
-
return new Slip(undefined, this.toJson());
|
|
118
|
-
}
|
|
119
|
-
}
|
package/lib/transaction.ts
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import type {WasmTransaction} from "saito-wasm/dist/types/pkg/node/index_bg";
|
|
2
|
-
import Slip from "./slip";
|
|
3
|
-
import Saito from "../saito";
|
|
4
|
-
import Factory from "./factory";
|
|
5
|
-
|
|
6
|
-
export enum TransactionType {
|
|
7
|
-
Normal = 0,
|
|
8
|
-
Fee = 1,
|
|
9
|
-
GoldenTicket = 2,
|
|
10
|
-
ATR = 3,
|
|
11
|
-
Vip = 4,
|
|
12
|
-
SPV = 5,
|
|
13
|
-
Issuance = 6,
|
|
14
|
-
Other = 7,
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export default class Transaction {
|
|
18
|
-
protected tx: WasmTransaction;
|
|
19
|
-
public static Type: any;
|
|
20
|
-
public msg: any = {};
|
|
21
|
-
|
|
22
|
-
// TODO : factory pattern might be useful here to remove unnecessary wrappings
|
|
23
|
-
constructor(tx?: WasmTransaction, json?: any) {
|
|
24
|
-
if (tx) {
|
|
25
|
-
this.tx = tx;
|
|
26
|
-
} else {
|
|
27
|
-
this.tx = new Transaction.Type();
|
|
28
|
-
}
|
|
29
|
-
if (json) {
|
|
30
|
-
for (let slip of json.to) {
|
|
31
|
-
let s = new Slip(undefined, slip);
|
|
32
|
-
this.addToSlip(s);
|
|
33
|
-
}
|
|
34
|
-
for (let slip of json.from) {
|
|
35
|
-
let s = new Slip(undefined, slip);
|
|
36
|
-
this.addFromSlip(s);
|
|
37
|
-
}
|
|
38
|
-
this.timestamp = json.timestamp;
|
|
39
|
-
this.type = json.type;
|
|
40
|
-
this.signature = json.signature;
|
|
41
|
-
this.data = new Uint8Array(Buffer.from(json.buffer, "base64"));
|
|
42
|
-
this.txs_replacements = json.txs_replacements;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public get wasmTransaction(): WasmTransaction {
|
|
47
|
-
return this.tx;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public addFromSlip(slip: Slip) {
|
|
51
|
-
this.tx.add_from_slip(slip.wasmSlip);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
public addToSlip(slip: Slip) {
|
|
55
|
-
this.tx.add_to_slip(slip.wasmSlip);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public get to(): Array<Slip> {
|
|
59
|
-
return this.tx.to.map((slip) => {
|
|
60
|
-
return Saito.getInstance().factory.createSlip(slip);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public get from(): Array<Slip> {
|
|
65
|
-
return this.tx.from.map((slip) => {
|
|
66
|
-
return Saito.getInstance().factory.createSlip(slip);
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
public get type(): TransactionType {
|
|
71
|
-
return this.tx.type as TransactionType;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
public set type(type: TransactionType) {
|
|
75
|
-
this.tx.type = type as number;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
public get timestamp(): number {
|
|
79
|
-
return Number(this.tx.timestamp);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
public set timestamp(timestamp: bigint | number) {
|
|
83
|
-
this.tx.timestamp = BigInt(timestamp);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
public set signature(sig: string) {
|
|
87
|
-
this.tx.signature = sig;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
public get signature(): string {
|
|
91
|
-
return this.tx.signature;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
public set data(buffer: Uint8Array) {
|
|
95
|
-
this.tx.data = buffer;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
public get data(): Uint8Array {
|
|
99
|
-
return this.tx.data;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
public set txs_replacements(r: number) {
|
|
103
|
-
this.tx.txs_replacements = r;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
public get txs_replacements(): number {
|
|
107
|
-
return this.tx.txs_replacements;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
public get total_fees(): bigint {
|
|
111
|
-
return this.tx.total_fees;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
public async sign() {
|
|
115
|
-
return this.tx.sign();
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
public async signAndEncrypt() {
|
|
119
|
-
return this.tx.sign_and_encrypt();
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
public isFrom(key: string): boolean {
|
|
123
|
-
return this.tx.is_from(key);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
public isTo(key: string): boolean {
|
|
127
|
-
return this.tx.is_to(key);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
public toJson() {
|
|
131
|
-
this.packData();
|
|
132
|
-
return {
|
|
133
|
-
to: this.to.map((slip) => slip.toJson()),
|
|
134
|
-
from: this.from.map((slip) => slip.toJson()),
|
|
135
|
-
type: this.type,
|
|
136
|
-
timestamp: this.timestamp,
|
|
137
|
-
signature: this.signature,
|
|
138
|
-
buffer: Buffer.from(this.data).toString("base64"),
|
|
139
|
-
txs_replacements: this.txs_replacements,
|
|
140
|
-
total_fees: this.total_fees,
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
public static deserialize(buffer: Uint8Array, factory: Factory): Transaction | null {
|
|
145
|
-
try {
|
|
146
|
-
let wasmTx = Transaction.Type.deserialize(buffer);
|
|
147
|
-
return factory.createTransaction(wasmTx);
|
|
148
|
-
} catch (e) {
|
|
149
|
-
console.debug(e);
|
|
150
|
-
return null;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
public serialize(): Uint8Array {
|
|
155
|
-
return this.tx.serialize();
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
public packData() {
|
|
159
|
-
if (Object.keys(this.msg).length === 0) {
|
|
160
|
-
this.data = new Uint8Array(Buffer.alloc(0));
|
|
161
|
-
} else {
|
|
162
|
-
this.data = new Uint8Array(Buffer.from(JSON.stringify(this.msg), "utf-8"));
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
public unpackData() {
|
|
167
|
-
if (this.data.byteLength === 0) {
|
|
168
|
-
this.msg = {};
|
|
169
|
-
} else {
|
|
170
|
-
try {
|
|
171
|
-
this.msg = JSON.parse(Buffer.from(this.data).toString("utf-8"));
|
|
172
|
-
} catch (error) {
|
|
173
|
-
console.log("failed parsing tx buffer into msg");
|
|
174
|
-
console.error(error);
|
|
175
|
-
this.msg = {};
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
package/lib/wallet.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { WasmWallet } from "saito-wasm/dist/types/pkg/node/index_bg";
|
|
2
|
-
import Saito from "../saito";
|
|
3
|
-
|
|
4
|
-
export const DefaultEmptyPrivateKey =
|
|
5
|
-
"0000000000000000000000000000000000000000000000000000000000000000";
|
|
6
|
-
export const DefaultEmptyPublicKey =
|
|
7
|
-
"000000000000000000000000000000000000000000000000000000000000000000";
|
|
8
|
-
|
|
9
|
-
export default class Wallet {
|
|
10
|
-
protected wallet: WasmWallet;
|
|
11
|
-
public static Type: any;
|
|
12
|
-
|
|
13
|
-
constructor(wallet: WasmWallet) {
|
|
14
|
-
this.wallet = wallet;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public async save() {
|
|
18
|
-
return this.wallet.save();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public async load() {
|
|
22
|
-
return this.wallet.load();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public async reset() {
|
|
26
|
-
return this.wallet.reset();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public async getPublicKey() {
|
|
30
|
-
let key = await this.wallet.get_public_key();
|
|
31
|
-
return key === DefaultEmptyPublicKey ? "" : key;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public async setPublicKey(key: string) {
|
|
35
|
-
if (key === "") {
|
|
36
|
-
key = DefaultEmptyPublicKey;
|
|
37
|
-
}
|
|
38
|
-
return this.wallet.set_public_key(key);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public async getPrivateKey() {
|
|
42
|
-
let key = await this.wallet.get_private_key();
|
|
43
|
-
return key === DefaultEmptyPrivateKey ? "" : key;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public async setPrivateKey(key: string) {
|
|
47
|
-
if (key === "") {
|
|
48
|
-
key = DefaultEmptyPrivateKey;
|
|
49
|
-
}
|
|
50
|
-
return this.wallet.set_private_key(key);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public async getBalance() {
|
|
54
|
-
return this.wallet.get_balance();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
public async getPendingTxs() {
|
|
58
|
-
let txs = await this.wallet.get_pending_txs();
|
|
59
|
-
return txs.map((tx: any) => Saito.getInstance().factory.createTransaction(tx));
|
|
60
|
-
}
|
|
61
|
-
}
|