mmn-client-js 1.0.10 → 1.0.11
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/index.d.ts +24 -14
- package/dist/index.esm.js +43 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +42 -5
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -7930,12 +7930,19 @@ class MmnClient {
|
|
|
7930
7930
|
* Create and sign a transaction message
|
|
7931
7931
|
*/
|
|
7932
7932
|
createAndSignTx(params) {
|
|
7933
|
-
|
|
7934
|
-
|
|
7933
|
+
if (!this.validateAddress(params.sender)) {
|
|
7934
|
+
throw new Error('Invalid sender address');
|
|
7935
|
+
}
|
|
7936
|
+
if (!this.validateAddress(params.recipient)) {
|
|
7937
|
+
throw new Error('Invalid recipient address');
|
|
7938
|
+
}
|
|
7939
|
+
if (params.sender === params.recipient) {
|
|
7940
|
+
throw new Error('Sender and recipient addresses cannot be the same');
|
|
7941
|
+
}
|
|
7935
7942
|
const txMsg = {
|
|
7936
7943
|
type: params.type,
|
|
7937
|
-
sender:
|
|
7938
|
-
recipient:
|
|
7944
|
+
sender: params.sender,
|
|
7945
|
+
recipient: params.recipient,
|
|
7939
7946
|
amount: params.amount,
|
|
7940
7947
|
timestamp: params.timestamp || Date.now(),
|
|
7941
7948
|
text_data: params.textData || '',
|
|
@@ -8023,6 +8030,17 @@ class MmnClient {
|
|
|
8023
8030
|
* Send a transaction (create, sign, and submit)
|
|
8024
8031
|
*/
|
|
8025
8032
|
async sendTransaction(params) {
|
|
8033
|
+
const fromAddress = this.getAddressFromUserId(params.sender);
|
|
8034
|
+
const toAddress = this.getAddressFromUserId(params.recipient);
|
|
8035
|
+
const signedTx = this.createAndSignTx({
|
|
8036
|
+
...params,
|
|
8037
|
+
type: TX_TYPE.TRANSFER,
|
|
8038
|
+
sender: fromAddress,
|
|
8039
|
+
recipient: toAddress,
|
|
8040
|
+
});
|
|
8041
|
+
return this.addTx(signedTx);
|
|
8042
|
+
}
|
|
8043
|
+
async sendTransactionByAddress(params) {
|
|
8026
8044
|
const signedTx = this.createAndSignTx({
|
|
8027
8045
|
...params,
|
|
8028
8046
|
type: TX_TYPE.TRANSFER,
|
|
@@ -8049,6 +8067,19 @@ class MmnClient {
|
|
|
8049
8067
|
}
|
|
8050
8068
|
return scaledAmount.toString();
|
|
8051
8069
|
}
|
|
8070
|
+
validateAddress(addr) {
|
|
8071
|
+
const decoded = bs58.decode(addr);
|
|
8072
|
+
if (!decoded ||
|
|
8073
|
+
decoded.length !== CRYPTO_CONSTANTS.ED25519_PUBLIC_KEY_LENGTH) {
|
|
8074
|
+
return false;
|
|
8075
|
+
}
|
|
8076
|
+
return true;
|
|
8077
|
+
}
|
|
8078
|
+
validateAmount(balance, amount) {
|
|
8079
|
+
const bigBalance = BigInt(balance);
|
|
8080
|
+
const bigAmount = BigInt(typeof amount === 'number' ? this.scaleAmountToDecimals(amount) : amount);
|
|
8081
|
+
return bigAmount <= bigBalance;
|
|
8082
|
+
}
|
|
8052
8083
|
}
|
|
8053
8084
|
function createMmnClient(config) {
|
|
8054
8085
|
return new MmnClient(config);
|
|
@@ -8061,6 +8092,11 @@ exports.ETransferType = void 0;
|
|
|
8061
8092
|
ETransferType["TransferToken"] = "transfer_token";
|
|
8062
8093
|
ETransferType["UnlockItem"] = "unlock_item";
|
|
8063
8094
|
})(exports.ETransferType || (exports.ETransferType = {}));
|
|
8095
|
+
exports.EZkClientType = void 0;
|
|
8096
|
+
(function (EZkClientType) {
|
|
8097
|
+
EZkClientType["MEZON"] = "mezon";
|
|
8098
|
+
EZkClientType["OAUTH"] = "oauth";
|
|
8099
|
+
})(exports.EZkClientType || (exports.EZkClientType = {}));
|
|
8064
8100
|
|
|
8065
8101
|
class ZkClient {
|
|
8066
8102
|
constructor(config) {
|
|
@@ -8116,13 +8152,14 @@ class ZkClient {
|
|
|
8116
8152
|
throw new Error('Request failed');
|
|
8117
8153
|
}
|
|
8118
8154
|
}
|
|
8119
|
-
async getZkProofs({ userId, ephemeralPublicKey, jwt, address, }) {
|
|
8155
|
+
async getZkProofs({ userId, ephemeralPublicKey, jwt, address, clientType = exports.EZkClientType.MEZON, }) {
|
|
8120
8156
|
const path = `prove`;
|
|
8121
8157
|
const res = await this.makeRequest('POST', path, undefined, {
|
|
8122
8158
|
user_id: userId,
|
|
8123
8159
|
ephemeral_pk: ephemeralPublicKey,
|
|
8124
8160
|
jwt,
|
|
8125
8161
|
address,
|
|
8162
|
+
client_type: clientType,
|
|
8126
8163
|
});
|
|
8127
8164
|
return res.data;
|
|
8128
8165
|
}
|