@keplr-wallet/cosmos
Advanced tools
Comparing version 0.9.16 to 0.9.18-rc.0
@@ -7,42 +7,51 @@ "use strict"; | ||
// Base account | ||
let account = index_1.BaseAccount.fromAminoJSON({ | ||
height: "8409557", | ||
result: { | ||
type: "cosmos-sdk/BaseAccount", | ||
value: { | ||
address: "cosmos1vv6hruquzpty4xpks9znkw8gys5x4nsnqw9f4k", | ||
public_key: { | ||
type: "tendermint/PubKeySecp256k1", | ||
value: "Avn3xBbmE0+MEyWMuxhmjjiX1GtCUVyv/Mavg8OcRIm4", | ||
}, | ||
account_number: "9736", | ||
sequence: "971", | ||
let account = index_1.BaseAccount.fromProtoJSON({ | ||
account: { | ||
"@type": "/cosmos.auth.v1beta1.BaseAccount", | ||
address: "cosmos1vv6hruquzpty4xpks9znkw8gys5x4nsnqw9f4k", | ||
pub_key: { | ||
"@type": "/cosmos.crypto.secp256k1.PubKey", | ||
key: "Avn3xBbmE0+MEyWMuxhmjjiX1GtCUVyv/Mavg8OcRIm4", | ||
}, | ||
account_number: "9736", | ||
sequence: "1019", | ||
}, | ||
}); | ||
expect(account.getAddress()).toBe("cosmos1vv6hruquzpty4xpks9znkw8gys5x4nsnqw9f4k"); | ||
expect(account.getSequence().toString()).toBe("971"); | ||
expect(account.getSequence().toString()).toBe("1019"); | ||
expect(account.getAccountNumber().toString()).toBe("9736"); | ||
expect(account.getType()).toBe("cosmos-sdk/BaseAccount"); | ||
expect(account.getType()).toBe("/cosmos.auth.v1beta1.BaseAccount"); | ||
// Vesting account | ||
account = index_1.BaseAccount.fromAminoJSON({ | ||
height: "8409738", | ||
result: { | ||
type: "cosmos-sdk/DelayedVestingAccount", | ||
value: { | ||
base_vesting_account: { | ||
base_account: { | ||
address: "cosmos1x3rhderemr703f4lxktk2da99vl5crs28ur3xl", | ||
public_key: { | ||
type: "tendermint/PubKeySecp256k1", | ||
value: "A+Zzm/8QhyL00ISXgiAgeW6zeqZHezVFi2w3iQkJeKyP", | ||
}, | ||
account_number: "367245", | ||
sequence: "7", | ||
account = index_1.BaseAccount.fromProtoJSON({ | ||
account: { | ||
"@type": "/cosmos.vesting.v1beta1.DelayedVestingAccount", | ||
base_vesting_account: { | ||
base_account: { | ||
address: "cosmos1x3rhderemr703f4lxktk2da99vl5crs28ur3xl", | ||
pub_key: { | ||
"@type": "/cosmos.crypto.secp256k1.PubKey", | ||
key: "A+Zzm/8QhyL00ISXgiAgeW6zeqZHezVFi2w3iQkJeKyP", | ||
}, | ||
original_vesting: [{ denom: "uatom", amount: "16666660000" }], | ||
delegated_free: [], | ||
delegated_vesting: [], | ||
end_time: "1719752607", | ||
account_number: "367245", | ||
sequence: "30", | ||
}, | ||
original_vesting: [ | ||
{ | ||
denom: "uatom", | ||
amount: "16666660000", | ||
}, | ||
], | ||
delegated_free: [ | ||
{ | ||
denom: "uatom", | ||
amount: "11620069", | ||
}, | ||
], | ||
delegated_vesting: [ | ||
{ | ||
denom: "uatom", | ||
amount: "16666660000", | ||
}, | ||
], | ||
end_time: "1719752607", | ||
}, | ||
@@ -52,27 +61,36 @@ }, | ||
expect(account.getAddress()).toBe("cosmos1x3rhderemr703f4lxktk2da99vl5crs28ur3xl"); | ||
expect(account.getSequence().toString()).toBe("7"); | ||
expect(account.getSequence().toString()).toBe("30"); | ||
expect(account.getAccountNumber().toString()).toBe("367245"); | ||
expect(account.getType()).toBe("cosmos-sdk/DelayedVestingAccount"); | ||
expect(account.getType()).toBe("/cosmos.vesting.v1beta1.DelayedVestingAccount"); | ||
/* | ||
TODO: Recover test case for ethermint. | ||
// Custom account that embeds the base account (ethermint) | ||
account = index_1.BaseAccount.fromAminoJSON({ | ||
height: "449", | ||
result: { | ||
base_account: { | ||
address: "evmos1w3ygakvq5snf30pca5g8pnyvvfr7x28djnj34m", | ||
public_key: { | ||
type: "tendermint/PubKeySecp256k1", | ||
value: "AulWtcPTIZWd/CnkFkQOMqDOwU7e+U/Iq8Tli1nhBq6j", | ||
}, | ||
account_number: "11", | ||
sequence: "1", | ||
}, | ||
code_hash: "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", | ||
account = BaseAccount.fromAminoJSON({ | ||
height: "449", | ||
result: { | ||
base_account: { | ||
address: "evmos1w3ygakvq5snf30pca5g8pnyvvfr7x28djnj34m", | ||
public_key: { | ||
type: "tendermint/PubKeySecp256k1", | ||
value: "AulWtcPTIZWd/CnkFkQOMqDOwU7e+U/Iq8Tli1nhBq6j", | ||
}, | ||
account_number: "11", | ||
sequence: "1", | ||
}, | ||
}); | ||
expect(account.getAddress()).toBe("evmos1w3ygakvq5snf30pca5g8pnyvvfr7x28djnj34m"); | ||
code_hash: | ||
"0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", | ||
}, | ||
// Above makes the type error. | ||
// But, just test that it can be parsed with ignoring the type error. | ||
} as any); | ||
expect(account.getAddress()).toBe( | ||
"evmos1w3ygakvq5snf30pca5g8pnyvvfr7x28djnj34m" | ||
); | ||
expect(account.getSequence().toString()).toBe("1"); | ||
expect(account.getAccountNumber().toString()).toBe("11"); | ||
expect(account.getType()).toBe(""); | ||
*/ | ||
}); | ||
}); | ||
//# sourceMappingURL=account.spec.js.map |
@@ -15,11 +15,4 @@ import { Int } from "@keplr-wallet/unit"; | ||
static fetchFromRest(instance: AxiosInstance, address: string, defaultBech32Address?: boolean): Promise<BaseAccount>; | ||
static fromAminoJSON(obj: { | ||
height: string; | ||
result: { | ||
type: string; | ||
value: any; | ||
}; | ||
} | { | ||
type: string; | ||
value: any; | ||
static fromProtoJSON(obj: { | ||
account?: any; | ||
}, defaultBech32Address?: string): BaseAccount; | ||
@@ -26,0 +19,0 @@ constructor(type: string, address: string, accountNumber: Int, sequence: Int); |
@@ -26,15 +26,30 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const result = yield instance.get(`auth/accounts/${address}`); | ||
return BaseAccount.fromAminoJSON(result.data, defaultBech32Address ? address : ""); | ||
const result = yield instance.get(`/cosmos/auth/v1beta1/accounts/${address}`, { | ||
validateStatus: function (status) { | ||
// Permit 404 not found to handle the case of account not exists | ||
return (status >= 200 && status < 300) || status === 404; | ||
}, | ||
}); | ||
return BaseAccount.fromProtoJSON(result.data, defaultBech32Address ? address : ""); | ||
}); | ||
} | ||
static fromAminoJSON(obj, | ||
static fromProtoJSON(obj, | ||
// If the account doesn't exist, the result from `auth/accounts` would not have the address. | ||
// In this case, if `defaultBech32Address` param is provided, this will use it instead of the result from rest. | ||
defaultBech32Address = "") { | ||
if ("height" in obj) { | ||
obj = obj.result; | ||
if (!obj.account) { | ||
// Case of not existing account. | ||
// { | ||
// "code": 5, | ||
// "message": "rpc error: code = NotFound desc = account {address} not found: key not found", | ||
// "details": [ | ||
// ] | ||
// } | ||
if (!defaultBech32Address) { | ||
throw new Error(`Account's address is unknown: ${JSON.stringify(obj)}`); | ||
} | ||
return new BaseAccount("", defaultBech32Address, new unit_1.Int(0), new unit_1.Int(0)); | ||
} | ||
const type = obj.type || ""; | ||
let value = "value" in obj ? obj.value : obj; | ||
const type = obj.account["@type"] || ""; | ||
let value = obj.account; | ||
// If the chain modifies the account type, handle the case where the account type embeds the base account. | ||
@@ -54,6 +69,7 @@ // (Actually, the only existent case is ethermint, and this is the line for handling ethermint) | ||
if (baseVestingAccount) { | ||
value = | ||
baseVestingAccount.BaseAccount || | ||
baseVestingAccount.baseAccount || | ||
baseVestingAccount.base_account; | ||
value = baseVestingAccount; | ||
const baseAccount = value.BaseAccount || value.baseAccount || value.base_account; | ||
if (baseAccount) { | ||
value = baseAccount; | ||
} | ||
} | ||
@@ -69,3 +85,3 @@ let address = value.address; | ||
const sequence = value.sequence; | ||
return new BaseAccount(type, address, new unit_1.Int(accountNumber !== null && accountNumber !== void 0 ? accountNumber : "0"), new unit_1.Int(sequence !== null && sequence !== void 0 ? sequence : "0")); | ||
return new BaseAccount(type, address, new unit_1.Int(accountNumber || "0"), new unit_1.Int(sequence || "0")); | ||
} | ||
@@ -72,0 +88,0 @@ getType() { |
{ | ||
"name": "@keplr-wallet/cosmos", | ||
"version": "0.9.16", | ||
"version": "0.9.18-rc.0", | ||
"main": "build/index.js", | ||
@@ -23,4 +23,4 @@ "author": "chainapsis", | ||
"@keplr-wallet/crypto": "^0.9.10", | ||
"@keplr-wallet/types": "^0.9.12", | ||
"@keplr-wallet/unit": "^0.9.12", | ||
"@keplr-wallet/types": "^0.9.18-rc.0", | ||
"@keplr-wallet/unit": "^0.9.18-rc.0", | ||
"axios": "^0.21.4", | ||
@@ -32,3 +32,3 @@ "bech32": "^1.1.4", | ||
}, | ||
"gitHead": "20fe73bd3a330c7e476e18c4c2db12d87083eb77" | ||
"gitHead": "516d9115a614f9b851ed4521b060cbbdad1677d0" | ||
} |
@@ -6,15 +6,12 @@ import { BaseAccount } from "./index"; | ||
// Base account | ||
let account = BaseAccount.fromAminoJSON({ | ||
height: "8409557", | ||
result: { | ||
type: "cosmos-sdk/BaseAccount", | ||
value: { | ||
address: "cosmos1vv6hruquzpty4xpks9znkw8gys5x4nsnqw9f4k", | ||
public_key: { | ||
type: "tendermint/PubKeySecp256k1", | ||
value: "Avn3xBbmE0+MEyWMuxhmjjiX1GtCUVyv/Mavg8OcRIm4", | ||
}, | ||
account_number: "9736", | ||
sequence: "971", | ||
let account = BaseAccount.fromProtoJSON({ | ||
account: { | ||
"@type": "/cosmos.auth.v1beta1.BaseAccount", | ||
address: "cosmos1vv6hruquzpty4xpks9znkw8gys5x4nsnqw9f4k", | ||
pub_key: { | ||
"@type": "/cosmos.crypto.secp256k1.PubKey", | ||
key: "Avn3xBbmE0+MEyWMuxhmjjiX1GtCUVyv/Mavg8OcRIm4", | ||
}, | ||
account_number: "9736", | ||
sequence: "1019", | ||
}, | ||
@@ -26,27 +23,39 @@ }); | ||
); | ||
expect(account.getSequence().toString()).toBe("971"); | ||
expect(account.getSequence().toString()).toBe("1019"); | ||
expect(account.getAccountNumber().toString()).toBe("9736"); | ||
expect(account.getType()).toBe("cosmos-sdk/BaseAccount"); | ||
expect(account.getType()).toBe("/cosmos.auth.v1beta1.BaseAccount"); | ||
// Vesting account | ||
account = BaseAccount.fromAminoJSON({ | ||
height: "8409738", | ||
result: { | ||
type: "cosmos-sdk/DelayedVestingAccount", | ||
value: { | ||
base_vesting_account: { | ||
base_account: { | ||
address: "cosmos1x3rhderemr703f4lxktk2da99vl5crs28ur3xl", | ||
public_key: { | ||
type: "tendermint/PubKeySecp256k1", | ||
value: "A+Zzm/8QhyL00ISXgiAgeW6zeqZHezVFi2w3iQkJeKyP", | ||
}, | ||
account_number: "367245", | ||
sequence: "7", | ||
account = BaseAccount.fromProtoJSON({ | ||
account: { | ||
"@type": "/cosmos.vesting.v1beta1.DelayedVestingAccount", | ||
base_vesting_account: { | ||
base_account: { | ||
address: "cosmos1x3rhderemr703f4lxktk2da99vl5crs28ur3xl", | ||
pub_key: { | ||
"@type": "/cosmos.crypto.secp256k1.PubKey", | ||
key: "A+Zzm/8QhyL00ISXgiAgeW6zeqZHezVFi2w3iQkJeKyP", | ||
}, | ||
original_vesting: [{ denom: "uatom", amount: "16666660000" }], | ||
delegated_free: [], | ||
delegated_vesting: [], | ||
end_time: "1719752607", | ||
account_number: "367245", | ||
sequence: "30", | ||
}, | ||
original_vesting: [ | ||
{ | ||
denom: "uatom", | ||
amount: "16666660000", | ||
}, | ||
], | ||
delegated_free: [ | ||
{ | ||
denom: "uatom", | ||
amount: "11620069", | ||
}, | ||
], | ||
delegated_vesting: [ | ||
{ | ||
denom: "uatom", | ||
amount: "16666660000", | ||
}, | ||
], | ||
end_time: "1719752607", | ||
}, | ||
@@ -59,6 +68,10 @@ }, | ||
); | ||
expect(account.getSequence().toString()).toBe("7"); | ||
expect(account.getSequence().toString()).toBe("30"); | ||
expect(account.getAccountNumber().toString()).toBe("367245"); | ||
expect(account.getType()).toBe("cosmos-sdk/DelayedVestingAccount"); | ||
expect(account.getType()).toBe( | ||
"/cosmos.vesting.v1beta1.DelayedVestingAccount" | ||
); | ||
/* | ||
TODO: Recover test case for ethermint. | ||
// Custom account that embeds the base account (ethermint) | ||
@@ -90,3 +103,4 @@ account = BaseAccount.fromAminoJSON({ | ||
expect(account.getType()).toBe(""); | ||
*/ | ||
}); | ||
}); |
@@ -19,5 +19,13 @@ import { Int } from "@keplr-wallet/unit"; | ||
): Promise<BaseAccount> { | ||
const result = await instance.get(`auth/accounts/${address}`); | ||
const result = await instance.get( | ||
`/cosmos/auth/v1beta1/accounts/${address}`, | ||
{ | ||
validateStatus: function (status) { | ||
// Permit 404 not found to handle the case of account not exists | ||
return (status >= 200 && status < 300) || status === 404; | ||
}, | ||
} | ||
); | ||
return BaseAccount.fromAminoJSON( | ||
return BaseAccount.fromProtoJSON( | ||
result.data, | ||
@@ -28,12 +36,19 @@ defaultBech32Address ? address : "" | ||
public static fromAminoJSON( | ||
obj: | ||
| { | ||
height: string; | ||
result: { | ||
type: string; | ||
value: any; | ||
}; | ||
} | ||
| { type: string; value: any }, | ||
public static fromProtoJSON( | ||
obj: { | ||
account?: any; | ||
/* | ||
Base account format. | ||
{ | ||
"@type": string; | ||
address: string; | ||
pub_key: { | ||
"@type": string; | ||
key: string; | ||
}; | ||
account_number: string; | ||
sequence: string; | ||
}; | ||
*/ | ||
}, | ||
// If the account doesn't exist, the result from `auth/accounts` would not have the address. | ||
@@ -43,9 +58,20 @@ // In this case, if `defaultBech32Address` param is provided, this will use it instead of the result from rest. | ||
): BaseAccount { | ||
if ("height" in obj) { | ||
obj = obj.result; | ||
if (!obj.account) { | ||
// Case of not existing account. | ||
// { | ||
// "code": 5, | ||
// "message": "rpc error: code = NotFound desc = account {address} not found: key not found", | ||
// "details": [ | ||
// ] | ||
// } | ||
if (!defaultBech32Address) { | ||
throw new Error(`Account's address is unknown: ${JSON.stringify(obj)}`); | ||
} | ||
return new BaseAccount("", defaultBech32Address, new Int(0), new Int(0)); | ||
} | ||
const type = obj.type || ""; | ||
const type = obj.account["@type"] || ""; | ||
let value = "value" in obj ? obj.value : obj; | ||
let value = obj.account; | ||
@@ -69,6 +95,9 @@ // If the chain modifies the account type, handle the case where the account type embeds the base account. | ||
if (baseVestingAccount) { | ||
value = | ||
baseVestingAccount.BaseAccount || | ||
baseVestingAccount.baseAccount || | ||
baseVestingAccount.base_account; | ||
value = baseVestingAccount; | ||
const baseAccount = | ||
value.BaseAccount || value.baseAccount || value.base_account; | ||
if (baseAccount) { | ||
value = baseAccount; | ||
} | ||
} | ||
@@ -90,4 +119,4 @@ | ||
address, | ||
new Int(accountNumber ?? "0"), | ||
new Int(sequence ?? "0") | ||
new Int(accountNumber || "0"), | ||
new Int(sequence || "0") | ||
); | ||
@@ -94,0 +123,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
956342
17936
+ Added@keplr-wallet/types@0.9.18-rc.0(transitive)
+ Added@keplr-wallet/unit@0.9.18-rc.0(transitive)
- Removed@keplr-wallet/types@0.9.12(transitive)
- Removed@keplr-wallet/unit@0.9.12(transitive)