-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement getting permit with OfflineSignerOnlyAminoWalletWrapper
- Loading branch information
Showing
17 changed files
with
815 additions
and
42 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...ain/kotlin/io/eqoty/secretk/extensions/accesscontrol/newPermitWithTargetSpecificWallet.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.eqoty.secretk.extensions.accesscontrol | ||
|
||
import io.eqoty.secretk.types.StdSignature | ||
import io.eqoty.secretk.types.extensions.Permission | ||
import io.eqoty.secretk.wallet.AminoSignResponse | ||
import io.eqoty.secretk.wallet.Wallet | ||
import io.eqoty.wallet.OfflineSignerOnlyAminoWalletWrapper | ||
import jslibs.keplrwallet.types.Keplr | ||
import jslibs.keplrwallet.types.KeplrSignOptionsImpl | ||
import kotlinx.browser.window | ||
import kotlinx.coroutines.await | ||
import kotlinx.serialization.decodeFromString | ||
import kotlinx.serialization.encodeToString | ||
import kotlinx.serialization.json.Json | ||
import org.w3c.dom.get | ||
|
||
internal actual suspend fun PermitFactory.newPermitWithTargetSpecificWallet( | ||
wallet: Wallet, | ||
owner: String, | ||
chainId: String, | ||
permitName: String, | ||
allowedTokens: List<String>, | ||
permissions: List<Permission> | ||
): StdSignature? { | ||
return if (wallet is OfflineSignerOnlyAminoWalletWrapper) { | ||
val jsAminoSignResponse = (window["keplr"] as Keplr).signAmino( | ||
chainId, | ||
owner, | ||
JSON.parse(Json.encodeToString(newSignDoc(chainId, permitName, allowedTokens, permissions))), | ||
// not sure why I can't just directly use KeplrSignOptionsImpl here 🙃 | ||
signOptions = JSON.parse( | ||
Json.encodeToString( | ||
KeplrSignOptionsImpl( | ||
preferNoSetFee = true, // Fee must be 0, so hide it from the user | ||
preferNoSetMemo = true, // Memo must be empty, so hide it from the user | ||
disableBalanceCheck = true | ||
) | ||
) | ||
) | ||
).await() | ||
val aminoSignResponse: AminoSignResponse = Json.decodeFromString(JSON.stringify(jsAminoSignResponse)) | ||
aminoSignResponse.signature | ||
} else { | ||
null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
secretk/src/jsMain/kotlin/jslibs/cosmjs/amino/coins.module_@cosmjs_amino.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
@file:Suppress( | ||
"INTERFACE_WITH_SUPERCLASS", | ||
"OVERRIDING_FINAL_MEMBER", | ||
"RETURN_TYPE_MISMATCH_ON_OVERRIDE", | ||
"CONFLICTING_OVERLOADS" | ||
) | ||
|
||
package jslibs.cosmjs.amino | ||
|
||
external interface Coin { | ||
var denom: String | ||
var amount: String | ||
} | ||
|
||
external fun coin(amount: Number, denom: String): Coin | ||
|
||
external fun coin(amount: String, denom: String): Coin | ||
|
||
external fun coins(amount: Number, denom: String): Array<Coin> | ||
|
||
external fun coins(amount: String, denom: String): Array<Coin> | ||
|
||
external fun parseCoins(input: String): Array<Coin> | ||
|
||
external fun addCoins(lhs: Coin, rhs: Coin): Coin |
46 changes: 46 additions & 0 deletions
46
secretk/src/jsMain/kotlin/jslibs/cosmjs/amino/pubkeys.module_@cosmjs_amino.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
@file:Suppress( | ||
"INTERFACE_WITH_SUPERCLASS", | ||
"OVERRIDING_FINAL_MEMBER", | ||
"RETURN_TYPE_MISMATCH_ON_OVERRIDE", | ||
"CONFLICTING_OVERLOADS" | ||
) | ||
|
||
package jslibs.cosmjs.amino | ||
|
||
external interface Pubkey { | ||
var type: String | ||
var value: dynamic | ||
} | ||
|
||
external interface Ed25519Pubkey : SinglePubkey { | ||
override var type: String /* "tendermint/PubKeyEd25519" */ | ||
override var value: String | ||
} | ||
|
||
external fun isEd25519Pubkey(pubkey: Pubkey): Boolean | ||
|
||
external interface Secp256k1Pubkey : SinglePubkey { | ||
override var type: String /* "tendermint/PubKeySecp256k1" */ | ||
override var value: String | ||
} | ||
|
||
external fun isSecp256k1Pubkey(pubkey: Pubkey): Boolean | ||
|
||
external interface SinglePubkey : Pubkey { | ||
override var type: String | ||
override var value: String | ||
} | ||
|
||
external fun isSinglePubkey(pubkey: Pubkey): Boolean | ||
|
||
external interface MultisigThresholdPubkeyValue { | ||
var threshold: String | ||
var pubkeys: Array<SinglePubkey> | ||
} | ||
|
||
external interface MultisigThresholdPubkey : Pubkey { | ||
override var type: String /* "tendermint/PubKeyMultisigThreshold" */ | ||
override var value: MultisigThresholdPubkeyValue | ||
} | ||
|
||
external fun isMultisigThresholdPubkey(pubkey: Pubkey): Boolean |
24 changes: 24 additions & 0 deletions
24
secretk/src/jsMain/kotlin/jslibs/cosmjs/amino/signature.module_@cosmjs_amino.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
@file:Suppress( | ||
"INTERFACE_WITH_SUPERCLASS", | ||
"OVERRIDING_FINAL_MEMBER", | ||
"RETURN_TYPE_MISMATCH_ON_OVERRIDE", | ||
"CONFLICTING_OVERLOADS" | ||
) | ||
|
||
package jslibs.cosmjs.amino | ||
|
||
import org.khronos.webgl.Uint8Array | ||
|
||
external interface StdSignature { | ||
var pub_key: Pubkey | ||
var signature: String | ||
} | ||
|
||
external fun encodeSecp256k1Signature(pubkey: Uint8Array, signature: Uint8Array): StdSignature | ||
|
||
external interface `T$1` { | ||
var pubkey: Uint8Array | ||
var signature: Uint8Array | ||
} | ||
|
||
external fun decodeSignature(signature: StdSignature): `T$1` |
Oops, something went wrong.