-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
721 additions
and
433 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { freeDecryptedWallet } from "~wallets/encryption"; | ||
import type { Allowance } from "~applications/allowance"; | ||
import { defaultGateway } from "~applications/gateway"; | ||
import type { ModuleAppData } from "~api/background"; | ||
import type { JWKInterface } from "warp-contracts"; | ||
import { allowanceAuth } from "../sign/allowance"; | ||
import { signAuth } from "../sign/sign_auth"; | ||
import Arweave from "arweave"; | ||
|
||
/** | ||
* Ensure allowance for dispatch | ||
*/ | ||
export async function ensureAllowanceDispatch( | ||
appData: ModuleAppData, | ||
allowance: Allowance, | ||
keyfile: JWKInterface, | ||
price: number | ||
) { | ||
const arweave = new Arweave(defaultGateway); | ||
|
||
// allowance or sign auth | ||
try { | ||
if (allowance.enabled) { | ||
await allowanceAuth(allowance, appData.appURL, price); | ||
} else { | ||
// get address | ||
const address = await arweave.wallets.jwkToAddress(keyfile); | ||
|
||
await signAuth( | ||
appData.appURL, | ||
// @ts-expect-error | ||
dataEntry.toJSON(), | ||
address | ||
); | ||
} | ||
} catch (e) { | ||
freeDecryptedWallet(keyfile); | ||
throw new Error(e?.message || e); | ||
} | ||
} |
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
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
Oops, something went wrong.