@txnlab/use-wallet 0.1.21 → 0.1.22
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/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +1281 -41
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/providers/index.d.ts +7 -7
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +1258 -15
- package/dist/esm/providers/index.d.ts +7 -7
- package/dist/index.d.ts +63 -1
- package/package.json +8 -8
- package/dist/cjs/base-9794b627.js +0 -174
- package/dist/cjs/base-9794b627.js.map +0 -1
- package/dist/cjs/clients/algosigner.js +0 -144
- package/dist/cjs/clients/algosigner.js.map +0 -1
- package/dist/cjs/clients/defly.js +0 -159
- package/dist/cjs/clients/defly.js.map +0 -1
- package/dist/cjs/clients/exodus.js +0 -118
- package/dist/cjs/clients/exodus.js.map +0 -1
- package/dist/cjs/clients/kmd.js +0 -140
- package/dist/cjs/clients/kmd.js.map +0 -1
- package/dist/cjs/clients/myalgowallet.js +0 -128
- package/dist/cjs/clients/myalgowallet.js.map +0 -1
- package/dist/cjs/clients/perawallet.js +0 -169
- package/dist/cjs/clients/perawallet.js.map +0 -1
- package/dist/cjs/clients/walletconnect.js +0 -199
- package/dist/cjs/clients/walletconnect.js.map +0 -1
- package/dist/cjs/constants-e76d1f05.js +0 -63
- package/dist/cjs/constants-e76d1f05.js.map +0 -1
- package/dist/cjs/constants.js +0 -22
- package/dist/cjs/constants.js.map +0 -1
- package/dist/cjs/providers.js +0 -81
- package/dist/cjs/providers.js.map +0 -1
- package/dist/cjs/utils.js +0 -74
- package/dist/cjs/utils.js.map +0 -1
- package/dist/esm/base-71089716.js +0 -152
- package/dist/esm/base-71089716.js.map +0 -1
- package/dist/esm/clients/algosigner.js +0 -142
- package/dist/esm/clients/algosigner.js.map +0 -1
- package/dist/esm/clients/defly.js +0 -139
- package/dist/esm/clients/defly.js.map +0 -1
- package/dist/esm/clients/exodus.js +0 -116
- package/dist/esm/clients/exodus.js.map +0 -1
- package/dist/esm/clients/kmd.js +0 -138
- package/dist/esm/clients/kmd.js.map +0 -1
- package/dist/esm/clients/myalgowallet.js +0 -108
- package/dist/esm/clients/myalgowallet.js.map +0 -1
- package/dist/esm/clients/perawallet.js +0 -149
- package/dist/esm/clients/perawallet.js.map +0 -1
- package/dist/esm/clients/walletconnect.js +0 -179
- package/dist/esm/clients/walletconnect.js.map +0 -1
- package/dist/esm/constants-49b44514.js +0 -53
- package/dist/esm/constants-49b44514.js.map +0 -1
- package/dist/esm/constants.js +0 -2
- package/dist/esm/constants.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/providers.js +0 -77
- package/dist/esm/providers.js.map +0 -1
- package/dist/esm/utils.js +0 -70
- package/dist/esm/utils.js.map +0 -1
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { B as BaseWallet, A as Algod } from '../base-71089716.js';
|
|
2
|
-
import { P as PROVIDER_ID, c as NODE_NETWORK } from '../constants-49b44514.js';
|
|
3
|
-
import { providers } from '../providers.js';
|
|
4
|
-
|
|
5
|
-
class AlgoSignerClient extends BaseWallet {
|
|
6
|
-
#client;
|
|
7
|
-
id;
|
|
8
|
-
provider;
|
|
9
|
-
constructor({ client, id, provider, algosdk, algodClient }) {
|
|
10
|
-
super(algosdk, algodClient);
|
|
11
|
-
this.#client = client;
|
|
12
|
-
this.id = id;
|
|
13
|
-
this.provider = provider;
|
|
14
|
-
}
|
|
15
|
-
static async init() {
|
|
16
|
-
if (typeof window == "undefined" ||
|
|
17
|
-
window.AlgoSigner === undefined) {
|
|
18
|
-
throw new Error("AlgoSigner is not available.");
|
|
19
|
-
}
|
|
20
|
-
const { algosdk, algodClient } = await Algod.init();
|
|
21
|
-
const algoSigner = window.AlgoSigner;
|
|
22
|
-
return new AlgoSignerClient({
|
|
23
|
-
id: PROVIDER_ID.ALGO_SIGNER,
|
|
24
|
-
client: algoSigner,
|
|
25
|
-
provider: providers[PROVIDER_ID.ALGO_SIGNER],
|
|
26
|
-
algosdk: algosdk,
|
|
27
|
-
algodClient: algodClient,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
async connect() {
|
|
31
|
-
await this.#client.connect();
|
|
32
|
-
let ledger = "MainNet";
|
|
33
|
-
if (NODE_NETWORK === "mainnet") {
|
|
34
|
-
ledger = "MainNet";
|
|
35
|
-
}
|
|
36
|
-
else if (NODE_NETWORK === "betanet") {
|
|
37
|
-
ledger = "BetaNet";
|
|
38
|
-
}
|
|
39
|
-
else if (NODE_NETWORK === "testnet") {
|
|
40
|
-
ledger = "TestNet";
|
|
41
|
-
}
|
|
42
|
-
else if (!!NODE_NETWORK) {
|
|
43
|
-
ledger = NODE_NETWORK;
|
|
44
|
-
}
|
|
45
|
-
const accounts = await this.#client.accounts({
|
|
46
|
-
ledger,
|
|
47
|
-
});
|
|
48
|
-
if (accounts.length === 0) {
|
|
49
|
-
throw new Error(`No accounts found for ${this.provider}`);
|
|
50
|
-
}
|
|
51
|
-
const mappedAccounts = accounts.map(({ address }, index) => ({
|
|
52
|
-
name: `AlgoSigner ${index + 1}`,
|
|
53
|
-
address,
|
|
54
|
-
providerId: this.provider.id,
|
|
55
|
-
}));
|
|
56
|
-
return {
|
|
57
|
-
...this.provider,
|
|
58
|
-
accounts: mappedAccounts,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
async reconnect(onDisconnect) {
|
|
62
|
-
if (window === undefined ||
|
|
63
|
-
window.AlgoSigner === undefined) {
|
|
64
|
-
onDisconnect();
|
|
65
|
-
}
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
async disconnect() {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
formatTransactionsArray(transactions) {
|
|
72
|
-
const formattedTransactions = transactions.map(([type, txn]) => {
|
|
73
|
-
const formattedTxn = {
|
|
74
|
-
txn: txn[1],
|
|
75
|
-
};
|
|
76
|
-
if (type === "s") {
|
|
77
|
-
formattedTxn.signers = [];
|
|
78
|
-
const decoded = this.algosdk.decodeSignedTransaction(new Uint8Array(Buffer.from(txn, "base64")));
|
|
79
|
-
formattedTxn.txn = this.#client.encoding.msgpackToBase64(decoded.txn.toByte());
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
const decoded = this.algosdk.decodeUnsignedTransaction(Buffer.from(txn, "base64"));
|
|
83
|
-
formattedTxn.txn = this.#client.encoding.msgpackToBase64(decoded.toByte());
|
|
84
|
-
}
|
|
85
|
-
return formattedTxn;
|
|
86
|
-
});
|
|
87
|
-
return formattedTransactions;
|
|
88
|
-
}
|
|
89
|
-
async signTransactions(activeAdress, transactions) {
|
|
90
|
-
// Decode the transactions to access their properties.
|
|
91
|
-
const decodedTxns = transactions.map((txn) => {
|
|
92
|
-
return this.algosdk.decodeObj(txn);
|
|
93
|
-
});
|
|
94
|
-
// Marshal the transactions,
|
|
95
|
-
// and add the signers property if they shouldn't be signed.
|
|
96
|
-
const txnsToSign = decodedTxns.reduce((acc, txn, i) => {
|
|
97
|
-
const txnObj = {
|
|
98
|
-
txn: this.#client.encoding.msgpackToBase64(transactions[i]),
|
|
99
|
-
};
|
|
100
|
-
if ("txn" in txn ||
|
|
101
|
-
this.algosdk.encodeAddress(txn["snd"]) !== activeAdress) {
|
|
102
|
-
txnObj.txn = this.#client.encoding.msgpackToBase64(this.algosdk.decodeSignedTransaction(transactions[i]).txn.toByte());
|
|
103
|
-
txnObj.signers = [];
|
|
104
|
-
}
|
|
105
|
-
acc.push(txnObj);
|
|
106
|
-
return acc;
|
|
107
|
-
}, []);
|
|
108
|
-
// Sign them with the client.
|
|
109
|
-
const result = await this.#client.signTxn(txnsToSign);
|
|
110
|
-
// Join the newly signed transactions with the original group of transactions.
|
|
111
|
-
const signedTxns = result.reduce((acc, txn, i) => {
|
|
112
|
-
if (txn) {
|
|
113
|
-
acc.push(new Uint8Array(Buffer.from(txn.blob, "base64")));
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
acc.push(transactions[i]);
|
|
117
|
-
}
|
|
118
|
-
return acc;
|
|
119
|
-
}, []);
|
|
120
|
-
return signedTxns;
|
|
121
|
-
}
|
|
122
|
-
async signEncodedTransactions(transactions) {
|
|
123
|
-
const transactionsToSign = this.formatTransactionsArray(transactions);
|
|
124
|
-
const result = await this.#client.signTxn(transactionsToSign);
|
|
125
|
-
if (!result) {
|
|
126
|
-
throw new Error("Signing failed.");
|
|
127
|
-
}
|
|
128
|
-
const signedRawTransactions = result.reduce((signedTxns, txn, currentIndex) => {
|
|
129
|
-
if (txn) {
|
|
130
|
-
signedTxns.push(new Uint8Array(Buffer.from(txn.blob, "base64")));
|
|
131
|
-
}
|
|
132
|
-
if (txn === null) {
|
|
133
|
-
signedTxns.push(new Uint8Array(Buffer.from(transactions[currentIndex][1], "base64")));
|
|
134
|
-
}
|
|
135
|
-
return signedTxns;
|
|
136
|
-
}, []);
|
|
137
|
-
return signedRawTransactions;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export { AlgoSignerClient as default };
|
|
142
|
-
//# sourceMappingURL=algosigner.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"algosigner.js","sources":["../../../src/clients/algosigner.ts"],"sourcesContent":["/**\n * Helpful resources:\n * https://github.com/PureStake/algosigner/blob/develop/docs/dApp-integration.md\n */\nimport type _algosdk from \"algosdk\";\nimport BaseWallet from \"./base\";\nimport Algod from \"../algod\";\nimport { PROVIDER_ID, NODE_NETWORK } from \"../constants\";\nimport { providers } from \"../providers\";\nimport type { WalletProvider } from \"../types\";\nimport { TransactionsArray } from \"../types\";\nimport type { DecodedTransaction, DecodedSignedTransaction } from \"../types\";\n\ntype WindowExtended = { AlgoSigner: AlgoSigner } & Window & typeof globalThis;\n\ntype AlgoSignerTransaction = {\n txn: string;\n // array of addresses to sign with (defaults to the sender),\n // setting this to an empty array tells AlgoSigner\n // that this transaction is not meant to be signed\n signers?: [];\n multisig?: string; // address of a multisig wallet to sign with\n};\n\ntype SupportedLedgers = \"MainNet\" | \"TestNet\" | \"BetaNet\" | string;\n\ntype AlgoSigner = {\n connect: () => Promise<Record<string, never>>;\n accounts: (ledger: {\n ledger: SupportedLedgers;\n }) => Promise<{ address: string }[]>;\n signTxn: (transactions: AlgoSignerTransaction[]) => Promise<\n {\n txID: string;\n blob: string;\n }[]\n >;\n encoding: {\n msgpackToBase64(transaction: Uint8Array): string;\n byteArrayToString(transaction: Uint8Array): string;\n };\n};\n\ntype InitWallet = {\n client: AlgoSigner;\n id: PROVIDER_ID;\n provider: WalletProvider;\n algosdk: typeof _algosdk;\n algodClient: _algosdk.Algodv2;\n};\n\nclass AlgoSignerClient extends BaseWallet {\n #client: AlgoSigner;\n id: PROVIDER_ID;\n provider: WalletProvider;\n\n constructor({ client, id, provider, algosdk, algodClient }: InitWallet) {\n super(algosdk, algodClient);\n\n this.#client = client;\n this.id = id;\n this.provider = provider;\n }\n\n static async init() {\n if (\n typeof window == \"undefined\" ||\n (window as WindowExtended).AlgoSigner === undefined\n ) {\n throw new Error(\"AlgoSigner is not available.\");\n }\n\n const { algosdk, algodClient } = await Algod.init();\n const algoSigner = (window as WindowExtended).AlgoSigner as AlgoSigner;\n\n return new AlgoSignerClient({\n id: PROVIDER_ID.ALGO_SIGNER,\n client: algoSigner,\n provider: providers[PROVIDER_ID.ALGO_SIGNER],\n algosdk: algosdk,\n algodClient: algodClient,\n });\n }\n\n async connect() {\n await this.#client.connect();\n\n let ledger: SupportedLedgers = \"MainNet\";\n\n if (NODE_NETWORK === \"mainnet\") {\n ledger = \"MainNet\";\n } else if (NODE_NETWORK === \"betanet\") {\n ledger = \"BetaNet\";\n } else if (NODE_NETWORK === \"testnet\") {\n ledger = \"TestNet\";\n } else if (!!NODE_NETWORK) {\n ledger = NODE_NETWORK;\n }\n\n const accounts = await this.#client.accounts({\n ledger,\n });\n\n if (accounts.length === 0) {\n throw new Error(`No accounts found for ${this.provider}`);\n }\n\n const mappedAccounts = accounts.map(({ address }, index) => ({\n name: `AlgoSigner ${index + 1}`,\n address,\n providerId: this.provider.id,\n }));\n\n return {\n ...this.provider,\n accounts: mappedAccounts,\n };\n }\n\n async reconnect(onDisconnect: () => void) {\n if (\n window === undefined ||\n (window as WindowExtended).AlgoSigner === undefined\n ) {\n onDisconnect();\n }\n\n return null;\n }\n\n async disconnect() {\n return;\n }\n\n formatTransactionsArray(\n transactions: TransactionsArray\n ): AlgoSignerTransaction[] {\n const formattedTransactions = transactions.map(([type, txn]) => {\n const formattedTxn: AlgoSignerTransaction = {\n txn: txn[1],\n };\n\n if (type === \"s\") {\n formattedTxn.signers = [];\n const decoded = this.algosdk.decodeSignedTransaction(\n new Uint8Array(Buffer.from(txn, \"base64\"))\n );\n formattedTxn.txn = this.#client.encoding.msgpackToBase64(\n decoded.txn.toByte()\n );\n } else {\n const decoded = this.algosdk.decodeUnsignedTransaction(\n Buffer.from(txn, \"base64\")\n );\n formattedTxn.txn = this.#client.encoding.msgpackToBase64(\n decoded.toByte()\n );\n }\n\n return formattedTxn;\n });\n\n return formattedTransactions;\n }\n\n async signTransactions(activeAdress: string, transactions: Uint8Array[]) {\n // Decode the transactions to access their properties.\n const decodedTxns = transactions.map((txn) => {\n return this.algosdk.decodeObj(txn);\n }) as Array<DecodedTransaction | DecodedSignedTransaction>;\n\n // Marshal the transactions,\n // and add the signers property if they shouldn't be signed.\n const txnsToSign = decodedTxns.reduce<AlgoSignerTransaction[]>(\n (acc, txn, i) => {\n const txnObj: AlgoSignerTransaction = {\n txn: this.#client.encoding.msgpackToBase64(transactions[i]),\n };\n\n if (\n \"txn\" in txn ||\n this.algosdk.encodeAddress(txn[\"snd\"]) !== activeAdress\n ) {\n txnObj.txn = this.#client.encoding.msgpackToBase64(\n this.algosdk.decodeSignedTransaction(transactions[i]).txn.toByte()\n );\n txnObj.signers = [];\n }\n\n acc.push(txnObj);\n\n return acc;\n },\n []\n );\n\n // Sign them with the client.\n const result = await this.#client.signTxn(txnsToSign);\n\n // Join the newly signed transactions with the original group of transactions.\n const signedTxns = result.reduce<Uint8Array[]>((acc, txn, i) => {\n if (txn) {\n acc.push(new Uint8Array(Buffer.from(txn.blob, \"base64\")));\n } else {\n acc.push(transactions[i]);\n }\n\n return acc;\n }, []);\n\n return signedTxns;\n }\n\n async signEncodedTransactions(transactions: TransactionsArray) {\n const transactionsToSign = this.formatTransactionsArray(transactions);\n const result = await this.#client.signTxn(transactionsToSign);\n\n if (!result) {\n throw new Error(\"Signing failed.\");\n }\n\n const signedRawTransactions = result.reduce(\n (signedTxns: Uint8Array[], txn, currentIndex) => {\n if (txn) {\n signedTxns.push(new Uint8Array(Buffer.from(txn.blob, \"base64\")));\n }\n\n if (txn === null) {\n signedTxns.push(\n new Uint8Array(Buffer.from(transactions[currentIndex][1], \"base64\"))\n );\n }\n\n return signedTxns;\n },\n []\n );\n\n return signedRawTransactions;\n }\n}\n\nexport default AlgoSignerClient;\n"],"names":[],"mappings":";;;;AAmDA,MAAM,gBAAiB,SAAQ,UAAU,CAAA;AACvC,IAAA,OAAO,CAAa;AACpB,IAAA,EAAE,CAAc;AAChB,IAAA,QAAQ,CAAiB;IAEzB,WAAY,CAAA,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,EAAc,EAAA;AACpE,QAAA,KAAK,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;AAE5B,QAAA,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;AACtB,QAAA,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;AACb,QAAA,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;KAC1B;IAED,aAAa,IAAI,GAAA;QACf,IACE,OAAO,MAAM,IAAI,WAAW;AAC3B,YAAA,MAAyB,CAAC,UAAU,KAAK,SAAS,EACnD;AACA,YAAA,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;AACjD,SAAA;QAED,MAAM,EAAE,OAAO,EAAE,WAA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ED,YAAA,OAAO,UAAU,CAAC;SACnB,EACD,EAAE,CACH,CAAC;AAEF,QAAA,OAAO,qBAAqB,CAAC;KAC9B;AACF;;;;"}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { providers } from '../providers.js';
|
|
2
|
-
import { B as BaseWallet, A as Algod } from '../base-71089716.js';
|
|
3
|
-
import { P as PROVIDER_ID } from '../constants-49b44514.js';
|
|
4
|
-
|
|
5
|
-
class DeflyWalletClient extends BaseWallet {
|
|
6
|
-
#client;
|
|
7
|
-
id;
|
|
8
|
-
provider;
|
|
9
|
-
constructor({ client, id, provider, algosdk, algodClient }) {
|
|
10
|
-
super(algosdk, algodClient);
|
|
11
|
-
this.#client = client;
|
|
12
|
-
this.id = id;
|
|
13
|
-
this.provider = provider;
|
|
14
|
-
}
|
|
15
|
-
static async init() {
|
|
16
|
-
const { algosdk, algodClient } = await Algod.init();
|
|
17
|
-
const DeflyWalletConnect = (await import('@blockshake/defly-connect'))
|
|
18
|
-
.DeflyWalletConnect;
|
|
19
|
-
const deflyWallet = new DeflyWalletConnect({
|
|
20
|
-
shouldShowSignTxnToast: false,
|
|
21
|
-
});
|
|
22
|
-
return new DeflyWalletClient({
|
|
23
|
-
id: PROVIDER_ID.DEFLY,
|
|
24
|
-
client: deflyWallet,
|
|
25
|
-
provider: providers[PROVIDER_ID.DEFLY],
|
|
26
|
-
algosdk,
|
|
27
|
-
algodClient,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
async connect(onDisconnect) {
|
|
31
|
-
const accounts = await this.#client.connect();
|
|
32
|
-
this.#client.connector?.on("disconnect", onDisconnect);
|
|
33
|
-
if (accounts.length === 0) {
|
|
34
|
-
throw new Error(`No accounts found for ${this.provider}`);
|
|
35
|
-
}
|
|
36
|
-
const mappedAccounts = accounts.map((address, index) => ({
|
|
37
|
-
name: `Defly Wallet ${index + 1}`,
|
|
38
|
-
address,
|
|
39
|
-
providerId: this.provider.id,
|
|
40
|
-
}));
|
|
41
|
-
return {
|
|
42
|
-
...this.provider,
|
|
43
|
-
accounts: mappedAccounts,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
async reconnect(onDisconnect) {
|
|
47
|
-
const accounts = await this.#client.reconnectSession();
|
|
48
|
-
this.#client.connector?.on("disconnect", onDisconnect);
|
|
49
|
-
if (!accounts) {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
return {
|
|
53
|
-
...this.provider,
|
|
54
|
-
accounts: accounts.map((address, index) => ({
|
|
55
|
-
name: `Defly Wallet ${index + 1}`,
|
|
56
|
-
address,
|
|
57
|
-
providerId: this.provider.id,
|
|
58
|
-
})),
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
async disconnect() {
|
|
62
|
-
await this.#client.disconnect();
|
|
63
|
-
}
|
|
64
|
-
formatTransactionsArray(transactions) {
|
|
65
|
-
const formattedTransactions = [];
|
|
66
|
-
for (const [type, txn] of transactions) {
|
|
67
|
-
if (type === "s") {
|
|
68
|
-
formattedTransactions.push({
|
|
69
|
-
...this.algosdk.decodeSignedTransaction(new Uint8Array(Buffer.from(txn, "base64"))),
|
|
70
|
-
signers: [],
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
formattedTransactions.push({
|
|
75
|
-
txn: this.algosdk.decodeUnsignedTransaction(new Uint8Array(Buffer.from(txn, "base64"))),
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return formattedTransactions;
|
|
80
|
-
}
|
|
81
|
-
async signTransactions(activeAdress, transactions) {
|
|
82
|
-
// Decode the transactions to access their properties.
|
|
83
|
-
const decodedTxns = transactions.map((txn) => {
|
|
84
|
-
return this.algosdk.decodeObj(txn);
|
|
85
|
-
});
|
|
86
|
-
// Marshal the transactions,
|
|
87
|
-
// and add the signers property if they shouldn't be signed.
|
|
88
|
-
const txnsToSign = decodedTxns.reduce((acc, txn, i) => {
|
|
89
|
-
if (!("txn" in txn) &&
|
|
90
|
-
this.algosdk.encodeAddress(txn["snd"]) === activeAdress) {
|
|
91
|
-
acc.push({
|
|
92
|
-
txn: this.algosdk.decodeUnsignedTransaction(transactions[i]),
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
acc.push({
|
|
97
|
-
txn: this.algosdk.decodeSignedTransaction(transactions[i]).txn,
|
|
98
|
-
signers: [],
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
return acc;
|
|
102
|
-
}, []);
|
|
103
|
-
// Sign them with the client.
|
|
104
|
-
const result = await this.#client.signTransaction([txnsToSign]);
|
|
105
|
-
// Join the newly signed transactions with the original group of transactions.
|
|
106
|
-
const signedTxns = decodedTxns.reduce((acc, txn, i) => {
|
|
107
|
-
if (!("txn" in txn)) {
|
|
108
|
-
const signedByUser = result.shift();
|
|
109
|
-
signedByUser && acc.push(signedByUser);
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
acc.push(transactions[i]);
|
|
113
|
-
}
|
|
114
|
-
return acc;
|
|
115
|
-
}, []);
|
|
116
|
-
return signedTxns;
|
|
117
|
-
}
|
|
118
|
-
async signEncodedTransactions(transactions) {
|
|
119
|
-
const transactionsToSign = this.formatTransactionsArray(transactions);
|
|
120
|
-
const result = await this.#client.signTransaction([
|
|
121
|
-
transactionsToSign,
|
|
122
|
-
]);
|
|
123
|
-
const signedTransactions = [];
|
|
124
|
-
let resultIndex = 0;
|
|
125
|
-
for (const [type, txn] of transactions) {
|
|
126
|
-
if (type === "u") {
|
|
127
|
-
signedTransactions.push(result[resultIndex]);
|
|
128
|
-
resultIndex++;
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
signedTransactions.push(new Uint8Array(Buffer.from(txn, "base64")));
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return signedTransactions;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export { DeflyWalletClient as default };
|
|
139
|
-
//# sourceMappingURL=defly.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defly.js","sources":["../../../src/clients/defly.ts"],"sourcesContent":["/**\n * Helpful resources:\n * https://github.com/blockshake-io/defly-connect\n */\nimport type _algosdk from \"algosdk\";\nimport { providers } from \"../providers\";\nimport Algod from \"../algod\";\nimport type { WalletProvider, Wallet } from \"../types\";\nimport { PROVIDER_ID } from \"../constants\";\nimport type { Transaction } from \"algosdk\";\nimport BaseWallet from \"./base\";\nimport { TransactionsArray } from \"../types\";\nimport type { DeflyWalletConnect } from \"@blockshake/defly-connect\";\nimport type { DecodedTransaction, DecodedSignedTransaction } from \"../types\";\n\nexport interface DeflyTransaction {\n txn: Transaction;\n /**\n * Optional list of addresses that must sign the transactions.\n * Wallet skips to sign this txn if signers is empty array.\n * If undefined, wallet tries to sign it.\n */\n signers?: string[];\n}\n\ntype InitWallet = {\n id: PROVIDER_ID;\n client: DeflyWalletConnect;\n provider: WalletProvider;\n algosdk: typeof _algosdk;\n algodClient: _algosdk.Algodv2;\n};\n\nclass DeflyWalletClient extends BaseWallet {\n #client: DeflyWalletConnect;\n id: PROVIDER_ID;\n provider: WalletProvider;\n\n constructor({ client, id, provider, algosdk, algodClient }: InitWallet) {\n super(algosdk, algodClient);\n\n this.#client = client;\n this.id = id;\n this.provider = provider;\n }\n\n static async init() {\n const { algosdk, algodClient } = await Algod.init();\n\n const DeflyWalletConnect = (await import(\"@blockshake/defly-connect\"))\n .DeflyWalletConnect;\n\n const deflyWallet = new DeflyWalletConnect({\n shouldShowSignTxnToast: false,\n });\n\n return new DeflyWalletClient({\n id: PROVIDER_ID.DEFLY,\n client: deflyWallet,\n provider: providers[PROVIDER_ID.DEFLY],\n algosdk,\n algodClient,\n });\n }\n\n async connect(onDisconnect: () => void): Promise<Wallet> {\n const accounts = await this.#client.connect();\n this.#client.connector?.on(\"disconnect\", onDisconnect);\n\n if (accounts.length === 0) {\n throw new Error(`No accounts found for ${this.provider}`);\n }\n\n const mappedAccounts = accounts.map((address: string, index: number) => ({\n name: `Defly Wallet ${index + 1}`,\n address,\n providerId: this.provider.id,\n }));\n\n return {\n ...this.provider,\n accounts: mappedAccounts,\n };\n }\n\n async reconnect(onDisconnect: () => void) {\n const accounts = await this.#client.reconnectSession();\n this.#client.connector?.on(\"disconnect\", onDisconnect);\n\n if (!accounts) {\n return null;\n }\n\n return {\n ...this.provider,\n accounts: accounts.map((address: string, index: number) => ({\n name: `Defly Wallet ${index + 1}`,\n address,\n providerId: this.provider.id,\n })),\n };\n }\n\n async disconnect() {\n await this.#client.disconnect();\n }\n\n formatTransactionsArray(transactions: TransactionsArray) {\n const formattedTransactions: DeflyTransaction[] = [];\n\n for (const [type, txn] of transactions) {\n if (type === \"s\") {\n formattedTransactions.push({\n ...this.algosdk.decodeSignedTransaction(\n new Uint8Array(Buffer.from(txn, \"base64\"))\n ),\n signers: [],\n });\n } else {\n formattedTransactions.push({\n txn: this.algosdk.decodeUnsignedTransaction(\n new Uint8Array(Buffer.from(txn, \"base64\"))\n ),\n });\n }\n }\n\n return formattedTransactions;\n }\n\n async signTransactions(activeAdress: string, transactions: Uint8Array[]) {\n // Decode the transactions to access their properties.\n const decodedTxns = transactions.map((txn) => {\n return this.algosdk.decodeObj(txn);\n }) as Array<DecodedTransaction | DecodedSignedTransaction>;\n\n // Marshal the transactions,\n // and add the signers property if they shouldn't be signed.\n const txnsToSign = decodedTxns.reduce<DeflyTransaction[]>((acc, txn, i) => {\n if (\n !(\"txn\" in txn) &&\n this.algosdk.encodeAddress(txn[\"snd\"]) === activeAdress\n ) {\n acc.push({\n txn: this.algosdk.decodeUnsignedTransaction(transactions[i]),\n });\n } else {\n acc.push({\n txn: this.algosdk.decodeSignedTransaction(transactions[i]).txn,\n signers: [],\n });\n }\n\n return acc;\n }, []);\n\n // Sign them with the client.\n const result = await this.#client.signTransaction([txnsToSign]);\n\n // Join the newly signed transactions with the original group of transactions.\n const signedTxns = decodedTxns.reduce<Uint8Array[]>((acc, txn, i) => {\n if (!(\"txn\" in txn)) {\n const signedByUser = result.shift();\n signedByUser && acc.push(signedByUser);\n } else {\n acc.push(transactions[i]);\n }\n\n return acc;\n }, []);\n\n return signedTxns;\n }\n\n async signEncodedTransactions(transactions: TransactionsArray) {\n const transactionsToSign = this.formatTransactionsArray(transactions);\n const result: Uint8Array[] = await this.#client.signTransaction([\n transactionsToSign,\n ]);\n\n const signedTransactions: Uint8Array[] = [];\n\n let resultIndex = 0;\n\n for (const [type, txn] of transactions) {\n if (type === \"u\") {\n signedTransactions.push(result[resultIndex]);\n resultIndex++;\n } else {\n signedTransactions.push(new Uint8Array(Buffer.from(txn, \"base64\")));\n }\n }\n\n return signedTransactions;\n }\n}\n\nexport default DeflyWalletClient;\n"],"names":[],"mappings":";;;;AAiCA,MAAM,iBAAkB,SAAQ,UAAU,CAAA;AACxC,IAAA,OAAO,CAAqB;AAC5B,IAAA,EAAE,CAAc;AAChB,IAAA,QAAQ,CAAiB;IAEzB,WAAY,CAAA,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,EAAc,EAAA;AACpE,QAAA,KAAK,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;AAE5B,QAAA,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;AACtB,QAAA,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;AACb,QAAA,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;KAC1B;IAED,aAAa,IAAI,GAAA;QACf,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;QAEpD,MAAM,kBAAkB,GAAG,CAAC,MAAM,OAAO,2BAA2B,CAAC;AAClE,aAAA,kBAAkB,CAAC;AAEtB,QAAA,MAAM,WAAW,GAAG,IAAI,kBAAkB,CAAC;AACzC,YAAA,sBAAsB,EAAE,KAAK;AAC9B,SAAA,CAAC,CAAC;QAEH,OAAO,IAAI,iBAAiB,CAAC;Y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EP,QAAA,OAAO,UAAU,CAAC;KACnB;IAED,MAAM,uBAAuB,CAAC,YAA+B,EAAA;QAC3D,MAAM,kBAAkB,GAAG,IAAI,CAAC,uBAAuB,CAAC,YAAY,CAAC,CAAC;QACtE,MAAM,MAAM,GAAiB,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC;YAC9D,kBAAkB;AACnB,SAAA,CAAC,CAAC;QAEH,MAAM,kBAAkB,GAAiB,EAAE,CAAC;QAE5C,IAAI,WAAW,GAAG,CAAC,CAAC;QAEpB,KAAK,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,YAAY,EAAE;YACtC,IAAI,IAAI,KAAK,GAAG,EAAE;gBAChB,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC;AAC7C,gBAAA,WAAW,EAAE,CAAC;AACf,aAAA;AAAM,iBAAA;AACL,gBAAA,kBAAkB,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;AACrE,aAAA;AACF,SAAA;AAED,QAAA,OAAO,kBAAkB,CAAC;KAC3B;AACF;;;;"}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { B as BaseWallet, A as Algod } from '../base-71089716.js';
|
|
2
|
-
import { P as PROVIDER_ID } from '../constants-49b44514.js';
|
|
3
|
-
import { providers } from '../providers.js';
|
|
4
|
-
|
|
5
|
-
class ExodusClient extends BaseWallet {
|
|
6
|
-
#client;
|
|
7
|
-
id;
|
|
8
|
-
provider;
|
|
9
|
-
constructor({ client, id, provider, algosdk, algodClient }) {
|
|
10
|
-
super(algosdk, algodClient);
|
|
11
|
-
this.#client = client;
|
|
12
|
-
this.id = id;
|
|
13
|
-
this.provider = provider;
|
|
14
|
-
}
|
|
15
|
-
static async init() {
|
|
16
|
-
if (typeof window == "undefined" ||
|
|
17
|
-
window.exodus === undefined) {
|
|
18
|
-
throw new Error("Exodus is not available.");
|
|
19
|
-
}
|
|
20
|
-
const { algosdk, algodClient } = await Algod.init();
|
|
21
|
-
const exodus = window.exodus.algorand;
|
|
22
|
-
return new ExodusClient({
|
|
23
|
-
id: PROVIDER_ID.EXODUS,
|
|
24
|
-
client: exodus,
|
|
25
|
-
provider: providers[PROVIDER_ID.EXODUS],
|
|
26
|
-
algosdk: algosdk,
|
|
27
|
-
algodClient: algodClient,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
async connect() {
|
|
31
|
-
const { address } = await this.#client.connect();
|
|
32
|
-
if (!address) {
|
|
33
|
-
throw new Error(`No accounts found for ${this.provider}`);
|
|
34
|
-
}
|
|
35
|
-
const accounts = [
|
|
36
|
-
{
|
|
37
|
-
name: `Exodus 1`,
|
|
38
|
-
address,
|
|
39
|
-
providerId: this.provider.id,
|
|
40
|
-
},
|
|
41
|
-
];
|
|
42
|
-
return {
|
|
43
|
-
...this.provider,
|
|
44
|
-
accounts,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
async reconnect(onDisconnect) {
|
|
48
|
-
if (window === undefined ||
|
|
49
|
-
window.exodus === undefined ||
|
|
50
|
-
window.exodus.algorand.isConnected !== true) {
|
|
51
|
-
onDisconnect();
|
|
52
|
-
}
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
async disconnect() {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
async signTransactions(activeAdress, transactions) {
|
|
59
|
-
// Decode the transactions to access their properties.
|
|
60
|
-
const decodedTxns = transactions.map((txn) => {
|
|
61
|
-
return this.algosdk.decodeObj(txn);
|
|
62
|
-
});
|
|
63
|
-
// Get the unsigned transactions.
|
|
64
|
-
const txnsToSign = decodedTxns.reduce((acc, txn, i) => {
|
|
65
|
-
// If the transaction isn't already signed and is to be sent from a connected account,
|
|
66
|
-
// add it to the arrays of transactions to be signed.
|
|
67
|
-
if (!("txn" in txn) &&
|
|
68
|
-
this.algosdk.encodeAddress(txn["snd"]) === activeAdress) {
|
|
69
|
-
acc.push(transactions[i]);
|
|
70
|
-
}
|
|
71
|
-
return acc;
|
|
72
|
-
}, []);
|
|
73
|
-
// Sign them with the client.
|
|
74
|
-
const result = await this.#client.signTransaction(txnsToSign);
|
|
75
|
-
// Join the newly signed transactions with the original group of transactions.
|
|
76
|
-
const signedTxns = decodedTxns.reduce((acc, txn, i) => {
|
|
77
|
-
if (!("txn" in txn)) {
|
|
78
|
-
const signedByUser = result.shift();
|
|
79
|
-
signedByUser && acc.push(signedByUser);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
acc.push(transactions[i]);
|
|
83
|
-
}
|
|
84
|
-
return acc;
|
|
85
|
-
}, []);
|
|
86
|
-
return signedTxns;
|
|
87
|
-
}
|
|
88
|
-
async signEncodedTransactions(transactions) {
|
|
89
|
-
const transactionsToSign = [];
|
|
90
|
-
const signedRawTransactions = [];
|
|
91
|
-
for (const [type, txn] of transactions) {
|
|
92
|
-
if (type === "u") {
|
|
93
|
-
const decoded = this.algosdk.decodeUnsignedTransaction(Buffer.from(txn, "base64"));
|
|
94
|
-
transactionsToSign.push(decoded.toByte());
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
const result = await this.#client.signTransaction(transactionsToSign);
|
|
98
|
-
if (!result) {
|
|
99
|
-
throw new Error("Signing failed.");
|
|
100
|
-
}
|
|
101
|
-
let resultIndex = 0;
|
|
102
|
-
for (const [type, txn] of transactions) {
|
|
103
|
-
if (type === "u") {
|
|
104
|
-
signedRawTransactions.push(result[resultIndex]);
|
|
105
|
-
resultIndex++;
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
signedRawTransactions.push(new Uint8Array(Buffer.from(txn, "base64")));
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return signedRawTransactions;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export { ExodusClient as default };
|
|
116
|
-
//# sourceMappingURL=exodus.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"exodus.js","sources":["../../../src/clients/exodus.ts"],"sourcesContent":["/**\n * Helpful resources:\n * https://docs.exodus.com/api-reference/algorand-provider-api/\n */\nimport type _algosdk from \"algosdk\";\nimport BaseWallet from \"./base\";\nimport Algod from \"../algod\";\nimport { PROVIDER_ID } from \"../constants\";\nimport { providers } from \"../providers\";\nimport type { WalletProvider } from \"../types\";\nimport { TransactionsArray } from \"../types\";\nimport type { DecodedTransaction, DecodedSignedTransaction } from \"../types\";\n\ntype WindowExtended = { exodus: { algorand: Exodus } } & Window &\n typeof globalThis;\n\ntype Bytes = Readonly<Uint8Array>;\n\ntype Exodus = {\n isConnected: boolean;\n address: string | null;\n connect: () => Promise<{\n address: string;\n }>;\n disconnect: () => void;\n signAndSendTransaction(transactions: Bytes[]): Promise<{\n txId: string;\n }>;\n signTransaction(transactions: Bytes[]): Promise<Bytes[]>;\n};\n\ntype InitWallet = {\n client: Exodus;\n id: PROVIDER_ID;\n provider: WalletProvider;\n algosdk: typeof _algosdk;\n algodClient: _algosdk.Algodv2;\n};\n\nclass ExodusClient extends BaseWallet {\n #client: Exodus;\n id: PROVIDER_ID;\n provider: WalletProvider;\n\n constructor({ client, id, provider, algosdk, algodClient }: InitWallet) {\n super(algosdk, algodClient);\n\n this.#client = client;\n this.id = id;\n this.provider = provider;\n }\n\n static async init() {\n if (\n typeof window == \"undefined\" ||\n (window as WindowExtended).exodus === undefined\n ) {\n throw new Error(\"Exodus is not available.\");\n }\n\n const { algosdk, algodClient } = await Algod.init();\n const exodus = (window as WindowExtended).exodus.algorand as Exodus;\n\n return new ExodusClient({\n id: PROVIDER_ID.EXODUS,\n client: exodus,\n provider: providers[PROVIDER_ID.EXODUS],\n algosdk: algosdk,\n algodClient: algodClient,\n });\n }\n\n async connect() {\n const { address } = await this.#client.connect();\n\n if (!address) {\n throw new Error(`No accounts found for ${this.provider}`);\n }\n\n const accounts = [\n {\n name: `Exodus 1`,\n address,\n providerId: this.provider.id,\n },\n ];\n\n return {\n ...this.provider,\n accounts,\n };\n }\n\n async reconnect(onDisconnect: () => void) {\n if (\n window === undefined ||\n (window as WindowExtended).exodus === undefined ||\n (window as WindowExtended).exodus.algorand.isConnected !== true\n ) {\n onDisconnect();\n }\n\n return null;\n }\n\n async disconnect() {\n return;\n }\n\n async signTransactions(\n activeAdress: string,\n transactions: Array<Uint8Array>\n ) {\n // Decode the transactions to access their properties.\n const decodedTxns = transactions.map((txn) => {\n return this.algosdk.decodeObj(txn);\n }) as Array<DecodedTransaction | DecodedSignedTransaction>;\n\n // Get the unsigned transactions.\n const txnsToSign = decodedTxns.reduce<Uint8Array[]>((acc, txn, i) => {\n // If the transaction isn't already signed and is to be sent from a connected account,\n // add it to the arrays of transactions to be signed.\n if (\n !(\"txn\" in txn) &&\n this.algosdk.encodeAddress(txn[\"snd\"]) === activeAdress\n ) {\n acc.push(transactions[i]);\n }\n\n return acc;\n }, []);\n\n // Sign them with the client.\n const result = await this.#client.signTransaction(txnsToSign);\n\n // Join the newly signed transactions with the original group of transactions.\n const signedTxns = decodedTxns.reduce<Uint8Array[]>((acc, txn, i) => {\n if (!(\"txn\" in txn)) {\n const signedByUser = result.shift();\n signedByUser && acc.push(signedByUser);\n } else {\n acc.push(transactions[i]);\n }\n\n return acc;\n }, []);\n\n return signedTxns;\n }\n\n async signEncodedTransactions(transactions: TransactionsArray) {\n const transactionsToSign: Uint8Array[] = [];\n const signedRawTransactions: Uint8Array[] = [];\n\n for (const [type, txn] of transactions) {\n if (type === \"u\") {\n const decoded = this.algosdk.decodeUnsignedTransaction(\n Buffer.from(txn, \"base64\")\n );\n transactionsToSign.push(decoded.toByte());\n }\n }\n\n const result = await this.#client.signTransaction(transactionsToSign);\n\n if (!result) {\n throw new Error(\"Signing failed.\");\n }\n\n let resultIndex = 0;\n\n for (const [type, txn] of transactions) {\n if (type === \"u\") {\n signedRawTransactions.push(result[resultIndex]);\n resultIndex++;\n } else {\n signed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,IAAI,WAAW,GAAG,CAAC,CAAC;QAEpB,KAAK,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,YAAY,EAAE;YACtC,IAAI,IAAI,KAAK,GAAG,EAAE;gBAChB,qBAAqB,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC;AAChD,gBAAA,WAAW,EAAE,CAAC;AACf,aAAA;AAAM,iBAAA;AACL,gBAAA,qBAAqB,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;AACxE,aAAA;AACF,SAAA;AAED,QAAA,OAAO,qBAAqB,CAAC;KAC9B;AACF;;;;"}
|
package/dist/esm/clients/kmd.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { B as BaseWallet, A as Algod } from '../base-71089716.js';
|
|
2
|
-
import { P as PROVIDER_ID, f as KMD_WALLET, K as KMD_HOST, d as KMD_TOKEN, e as KMD_PORT } from '../constants-49b44514.js';
|
|
3
|
-
import { providers } from '../providers.js';
|
|
4
|
-
|
|
5
|
-
const DefaultKMDConfig = {
|
|
6
|
-
host: KMD_HOST,
|
|
7
|
-
token: KMD_TOKEN,
|
|
8
|
-
port: KMD_PORT,
|
|
9
|
-
};
|
|
10
|
-
class KMDWallet extends BaseWallet {
|
|
11
|
-
#client;
|
|
12
|
-
walletId;
|
|
13
|
-
id;
|
|
14
|
-
provider;
|
|
15
|
-
constructor({ client, id, provider, algosdk, algodClient }) {
|
|
16
|
-
super(algosdk, algodClient);
|
|
17
|
-
this.#client = client;
|
|
18
|
-
this.id = id;
|
|
19
|
-
this.provider = provider;
|
|
20
|
-
this.walletId = "";
|
|
21
|
-
}
|
|
22
|
-
static async init() {
|
|
23
|
-
// TODO: allow diff config options?
|
|
24
|
-
const kmdConfig = DefaultKMDConfig;
|
|
25
|
-
const { algosdk, algodClient } = await Algod.init();
|
|
26
|
-
const kmdClient = new algosdk.Kmd(kmdConfig.token, kmdConfig.host, kmdConfig.port);
|
|
27
|
-
return new KMDWallet({
|
|
28
|
-
id: PROVIDER_ID.KMD_WALLET,
|
|
29
|
-
client: kmdClient,
|
|
30
|
-
provider: providers[PROVIDER_ID.KMD_WALLET],
|
|
31
|
-
algosdk: algosdk,
|
|
32
|
-
algodClient: algodClient,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
async connect() {
|
|
36
|
-
// TODO: prompt for wallet and password?
|
|
37
|
-
return {
|
|
38
|
-
...this.provider,
|
|
39
|
-
accounts: await this.listAccounts(KMD_WALLET, await this.requestPassword()),
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
async disconnect() {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
async reconnect() {
|
|
46
|
-
return {
|
|
47
|
-
...this.provider,
|
|
48
|
-
accounts: await this.listAccounts(KMD_WALLET, await this.requestPassword()),
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
async requestPassword() {
|
|
52
|
-
// TODO: store it locally?
|
|
53
|
-
const pw = prompt("gib password");
|
|
54
|
-
return pw ? pw : "";
|
|
55
|
-
}
|
|
56
|
-
async getWalletToken(walletId, password) {
|
|
57
|
-
const handleResp = await this.#client.initWalletHandle(walletId, password);
|
|
58
|
-
return handleResp.wallet_handle_token;
|
|
59
|
-
}
|
|
60
|
-
async releaseToken(token) {
|
|
61
|
-
await this.#client.releaseWalletHandle(token);
|
|
62
|
-
}
|
|
63
|
-
async listWallets() {
|
|
64
|
-
const walletResponse = await this.#client.listWallets();
|
|
65
|
-
const walletList = walletResponse["wallets"];
|
|
66
|
-
const walletMap = {};
|
|
67
|
-
for (const w of walletList) {
|
|
68
|
-
walletMap[w.name] = w.id;
|
|
69
|
-
}
|
|
70
|
-
return walletMap;
|
|
71
|
-
}
|
|
72
|
-
async listAccounts(wallet, password) {
|
|
73
|
-
const walletMap = await this.listWallets();
|
|
74
|
-
if (!(wallet in walletMap))
|
|
75
|
-
throw Error("No wallet named: " + wallet);
|
|
76
|
-
this.walletId = walletMap[wallet];
|
|
77
|
-
// Get a handle token
|
|
78
|
-
const token = await this.getWalletToken(this.walletId, password);
|
|
79
|
-
// Fetch accounts and format them as lib expects
|
|
80
|
-
const listResponse = await this.#client.listKeys(token);
|
|
81
|
-
const addresses = listResponse["addresses"];
|
|
82
|
-
const mappedAccounts = addresses.map((address, index) => {
|
|
83
|
-
return {
|
|
84
|
-
name: `KMDWallet ${index + 1}`,
|
|
85
|
-
address,
|
|
86
|
-
providerId: this.provider.id,
|
|
87
|
-
};
|
|
88
|
-
});
|
|
89
|
-
// Release handle token
|
|
90
|
-
this.releaseToken(token);
|
|
91
|
-
return mappedAccounts;
|
|
92
|
-
}
|
|
93
|
-
async signTransactions(activeAddress, transactions) {
|
|
94
|
-
// Decode the transactions to access their properties.
|
|
95
|
-
const decodedTxns = transactions.map((txn) => {
|
|
96
|
-
return this.algosdk.decodeObj(txn);
|
|
97
|
-
});
|
|
98
|
-
// Get a handle token
|
|
99
|
-
const pw = await this.requestPassword();
|
|
100
|
-
const token = await this.getWalletToken(this.walletId, pw);
|
|
101
|
-
const signedTxns = [];
|
|
102
|
-
// Sign them with the client.
|
|
103
|
-
const signingPromises = [];
|
|
104
|
-
for (const idx in decodedTxns) {
|
|
105
|
-
const dtxn = decodedTxns[idx];
|
|
106
|
-
// push the incoming txn into signed, we'll overwrite it later
|
|
107
|
-
signedTxns.push(transactions[idx]);
|
|
108
|
-
// Its already signed, skip it
|
|
109
|
-
if (!("snd" in dtxn))
|
|
110
|
-
continue;
|
|
111
|
-
// Not to be signed by our signer, skip it
|
|
112
|
-
if (!(this.algosdk.encodeAddress(dtxn.snd) === activeAddress))
|
|
113
|
-
continue;
|
|
114
|
-
// overwrite with an empty blob
|
|
115
|
-
signedTxns[idx] = new Uint8Array();
|
|
116
|
-
const txn = this.algosdk.Transaction.from_obj_for_encoding(dtxn);
|
|
117
|
-
signingPromises.push(this.#client.signTransaction(token, pw, txn));
|
|
118
|
-
}
|
|
119
|
-
const signingResults = await Promise.all(signingPromises);
|
|
120
|
-
// Restore the newly signed txns in the correct order
|
|
121
|
-
let signedIdx = 0;
|
|
122
|
-
for (const idx in signedTxns) {
|
|
123
|
-
// If its an empty array, infer that it is one of the
|
|
124
|
-
// ones we wanted to have signed and overwrite the empty buff
|
|
125
|
-
if (signedTxns[idx].length === 0) {
|
|
126
|
-
signedTxns[idx] = signingResults[signedIdx];
|
|
127
|
-
signedIdx += 1;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return signedTxns;
|
|
131
|
-
}
|
|
132
|
-
signEncodedTransactions(transactions) {
|
|
133
|
-
throw new Error("Method not implemented.");
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export { KMDWallet as default };
|
|
138
|
-
//# sourceMappingURL=kmd.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"kmd.js","sources":["../../../src/clients/kmd.ts"],"sourcesContent":["import type _algosdk from \"algosdk\";\nimport Algod from \"../algod\";\nimport BaseWallet from \"./base\";\nimport { PROVIDER_ID } from \"../constants\";\nimport { providers } from \"../providers\";\nimport type { Account, Wallet, WalletProvider } from \"../types\";\nimport { TransactionsArray } from \"../types\";\nimport {\n KMD_HOST,\n KMD_TOKEN,\n KMD_PORT,\n KMD_WALLET,\n KMD_PASSWORD as _KMD_PASSWORD,\n} from \"../constants\";\n\ntype KMDConfig = {\n host: string;\n port: string;\n token: string;\n};\n\nconst DefaultKMDConfig = {\n host: KMD_HOST,\n token: KMD_TOKEN,\n port: KMD_PORT,\n} as KMDConfig;\n\ninterface ListWalletResponse {\n id: string;\n name: string;\n driver_name?: string;\n driver_version?: number;\n mnemonic_ux?: boolean;\n supported_txs?: Array<any>;\n}\n\ninterface InitWalletHandle {\n wallet_handle_token: string;\n message?: string;\n error?: boolean;\n}\n\ntype InitWallet = {\n client: _algosdk.Kmd;\n id: PROVIDER_ID;\n provider: WalletProvider;\n algosdk: typeof _algosdk;\n algodClient: _algosdk.Algodv2;\n};\n\nclass KMDWallet extends BaseWallet {\n #client: _algosdk.Kmd;\n walletId: string;\n id: PROVIDER_ID;\n provider: WalletProvider;\n\n constructor({ client, id, provider, algosdk, algodClient }: InitWallet) {\n super(algosdk, algodClient);\n\n this.#client = client;\n this.id = id;\n this.provider = provider;\n this.walletId = \"\";\n }\n\n static async init() {\n // TODO: allow diff config options?\n const kmdConfig: KMDConfig = DefaultKMDConfig;\n\n const { algosdk, algodClient } = await Algod.init();\n const kmdClient = new algosdk.Kmd(\n kmdConfig.token,\n kmdConfig.host,\n kmdConfig.port\n );\n\n return new KMDWallet({\n id: PROVIDER_ID.KMD_WALLET,\n client: kmdClient,\n provider: providers[PROVIDER_ID.KMD_WALLET],\n algosdk: algosdk,\n algodClient: algodClient,\n });\n }\n\n async connect(): Promise<Wallet> {\n // TODO: prompt for wallet and password?\n return {\n ...this.provider,\n accounts: await this.listAccounts(\n KMD_WALLET,\n await this.requestPassword()\n ),\n };\n }\n\n async disconnect() {\n return;\n }\n\n async reconnect(): Promise<Wallet | null> {\n return {\n ...this.provider,\n accounts: await this.listAccounts(\n KMD_WALLET,\n await this.requestPassword()\n ),\n };\n }\n\n async requestPassword(): Promise<string> {\n // TODO: store it locally?\n const pw = prompt(\"gib password\");\n return pw ? pw : \"\";\n }\n\n async getWalletToken(walletId: string, password: string): Promise<string> {\n const handleResp: InitWalletHandle = await this.#client.initWalletHandle(\n walletId,\n password\n );\n return handleResp.wallet_handle_token;\n }\n\n async releaseToken(token: string): Promise<void> {\n await this.#client.releaseWalletHandle(token);\n }\n\n async listWallets(): Promise<Record<string, string>> {\n const walletResponse = await this.#client.listWallets();\n const walletList: Array<ListWalletResponse> = walletResponse[\"wallets\"];\n const walletMap: Record<string, string> = {};\n for (const w of walletList) {\n walletMap[w.name] = w.id;\n }\n return walletMap;\n }\n\n async listAccounts(\n wallet: string,\n password: string\n ): Promise<Array<Account>> {\n const walletMap = await this.listWallets();\n\n if (!(wallet in walletMap)) throw Error(\"No wallet named: \" + wallet);\n\n this.walletId = walletMap[wallet];\n\n // Get a handle token\n const token = await this.getWalletToken(this.walletId, password);\n\n // Fetch accounts and format them as lib expects\n const listResponse = await this.#client.listKeys(token);\n const addresses: Array<string> = listResponse[\"addresses\"];\n const mappedAccounts = addresses.map((address: string, index: number) => {\n return {\n name: `KMDWallet ${index + 1}`,\n address,\n providerId: this.provider.id,\n };\n });\n\n // Release handle token\n this.releaseToken(token);\n\n return mappedAccounts;\n }\n\n async signTransactions(activeAddress: string, transactions: Uint8Array[]) {\n // Decode the transactions to access their properties.\n const decodedTxns = transactions.map((txn) => {\n return this.algosdk.decodeObj(txn);\n }) as Array<\n _algosdk.EncodedTransaction | _algosdk.EncodedSignedTransaction\n >;\n\n // Get a handle token\n const pw = await this.requestPassword();\n const token = await this.getWalletToken(this.walletId, pw);\n\n const signedTxns: Uint8Array[] = [];\n // Sign them with the client.\n const signingPromises: Promise<Uint8Array>[] = [];\n for (const idx in decodedTxns) {\n const dtxn = decodedTxns[idx];\n\n // push the incoming txn into signed, we'll overwrite it later\n signedTxns.push(transactions[idx]);\n\n // Its already signed, skip it\n if (!(\"snd\" in dtxn)) continue;\n // Not to be signed by our signer, skip it\n if (!(this.algosdk.encodeAddress(dtxn.snd) === activeAddress)) continue;\n\n // overwrite with an empty blob\n signedTxns[idx] = new Uint8Array();\n\n const txn = this.algosdk.Transaction.from_obj_for_encoding(dtxn);\n signingPromises.push(this.#client.signTransaction(token, pw, txn));\n }\n\n const signingResults = await Promise.all(signingPromises);\n\n // Restore the newly signed txns in the correct order\n let signedIdx = 0;\n for (const idx in signedTxns) {\n // If its an empty array, infer that it is one of the\n // ones we wanted to have signed and overwrite the empty buff\n if (signedTxns[idx].length === 0) {\n signedTxns[idx] = signingResults[signedIdx];\n signedIdx += 1;\n }\n }\n\n return signedTxns;\n }\n\n signEncodedTransactions(\n transactions: TransactionsArray\n ): Promise<Uint8Array[]> {\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