Skip to content

Commit

Permalink
PKG -- [fcl] Update verifyAccountProof verifyUserSignatures
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Santos committed May 3, 2022
1 parent 1773fcf commit bb17f1b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
9 changes: 9 additions & 0 deletions .changeset/short-ravens-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@onflow/fcl": major
---

# Removed default contract address for verifyAccountProof, verifyUserSignatures

AppUtils.verifyAccountProof and AppUtils.verifyUserSignatures now requires
setting `fcl.config.flow.network` (testnet or mainnet) or override contract address via
`opts.fclCryptoContract`
4 changes: 2 additions & 2 deletions docs/reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ A method allowing applications to cryptographically verify a message was signed
#### Note
⚠️ `fcl.config.network`, `fcl.config.env` or options override is required to use this api. See [FCL Configuration](#configuration).
⚠️ `fcl.config.flow.network` or options override is required to use this api. See [FCL Configuration](#configuration).
### Arguments
Expand Down Expand Up @@ -846,7 +846,7 @@ const verifySignatures = async (message, compositeSignatures) => {
A method allowing applications to cryptographically prove that a user controls an on-chain account. During user authentication, some FCL compatible wallets will choose to support the FCL `account-proof` service. If a wallet chooses to support this service, and the user approves the signing of message data, they will return `account-proof` data and a signature(s) that can be used to prove a user controls an on-chain account.
See [proving-authentication](https://github.com/onflow/fcl-js/blob/master/docs/reference/proving-authentication.mdx) documentaion for more details.
⚠️ `fcl.config.network`, `fcl.config.env` or options override is required to use this api. See [FCL Configuration](#configuration).
⚠️ `fcl.config.flow.network` or options override is required to use this api. See [FCL Configuration](#configuration).
### Arguments
Expand Down
39 changes: 15 additions & 24 deletions packages/fcl/src/app-utils/verify-signatures.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {config} from "@onflow/config"
import {invariant} from "@onflow/util-invariant"
import {sansPrefix} from "@onflow/util-address"
import {query} from "../exec/query"
import {encodeAccountProof} from "../wallet-utils"
import {sansPrefix} from "@onflow/util-address"
import {isString} from "../exec/utils/is"

const ACCOUNT_PROOF = "ACCOUNT_PROOF"
const USER_SIGNATURE = "USER_SIGNATURE"
Expand All @@ -11,12 +12,12 @@ export const validateArgs = args => {
if (args.appIdentifier) {
const {appIdentifier, address, nonce, signatures} = args
invariant(
typeof appIdentifier === "string",
"appIdentifier must be a string"
isString(appIdentifier),
"verifyAccountProof({ appIdentifier }) -- appIdentifier must be a string"
)
invariant(
typeof address === "string" && sansPrefix(address).length === 16,
"address must be a valid address"
isString(address) && sansPrefix(address).length === 16,
"verifyAccountProof({ address }) -- address must be a valid address"
)
invariant(/^[0-9a-f]+$/i.test(nonce), "nonce must be a hex string")
invariant(
Expand Down Expand Up @@ -54,29 +55,19 @@ const getVerifySignaturesScript = async (sig, opts) => {
? "verifyAccountProofSignatures"
: "verifyUserSignatures"

const network = await config.first(["env", "flow.network"])
let fclCryptoContract
const network = await config.first(["env", "network"])

invariant(
network,
"Network (local, testnet, mainnet) must be provided via fcl.config.env or fcl.config.network"
opts.fclCryptoContract || network === "testnet" || network === "mainnet",
"${verifyFunction}({ fclCryptoContract }) -- config.flow.network must be specified (testnet || mainnet) or contract address provided via opts.fclCryptoContract"
)

switch (network) {
case "local":
invariant(
opts.fclCryptoContract,
`In ${verifyFunction}: opts.fclCryptoContract address required for local network`
)
fclCryptoContract = opts.fclCryptoContract
break
case "testnet":
fclCryptoContract = "0x74daa6f9c7ef24b1"
break
case "mainnet":
fclCryptoContract = "0xb4b82a1c9d21d284"
break
default:
fclCryptoContract = "0x74daa6f9c7ef24b1"
if (opts.fclCryptoContract) {
fclCryptoContract = opts.fclCryptoContract
} else {
fclCryptoContract =
network === "testnet" ? "0x74daa6f9c7ef24b1" : "0xb4b82a1c9d21d284"
}

return `
Expand Down

0 comments on commit bb17f1b

Please sign in to comment.