diff --git a/package.json b/package.json index 4661566..87a9f9a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ecentrics/eth-identity-provider", - "version": "0.1.3", + "version": "0.2.0", "description": "An Ethereum orbit-db-identity-provider.", "license": "MIT", "author": "Ezerous ", diff --git a/src/ΕthereumContractIdentityProvider.js b/src/ΕthereumContractIdentityProvider.js index 3afd3d7..424af43 100644 --- a/src/ΕthereumContractIdentityProvider.js +++ b/src/ΕthereumContractIdentityProvider.js @@ -51,7 +51,7 @@ class EthereumContractIdentityProvider extends IdentityProvider { } async signIdentity(data) { - if (process.env.NODE_ENV === 'development') { // Don't sign repeatedly while in development + if (EthereumContractIdentityProvider.storeAuthDataLocally) { console.debug(`${LOGGING_PREFIX}Attempting to find stored Orbit identity data...`); const signaturePubKey = await getIdentitySignaturePubKey(data); if (signaturePubKey) { @@ -74,7 +74,7 @@ class EthereumContractIdentityProvider extends IdentityProvider { async doSignIdentity(data) { try { const signaturePubKey = await EthereumContractIdentityProvider.web3.eth.personal.sign(data, this.userAddress, ''); - if (process.env.NODE_ENV === 'development') { + if (EthereumContractIdentityProvider.storeAuthDataLocally) { storeIdentitySignaturePubKey(data, signaturePubKey) .then(() => { console.debug(`${LOGGING_PREFIX}Successfully stored current Orbit identity data.`); @@ -116,6 +116,11 @@ class EthereumContractIdentityProvider extends IdentityProvider { EthereumContractIdentityProvider.contractAddress = contractAddress; } + // Opt to store auth data locally to avoid repeating MetaMask signing prompts + static setStoreAuthDataLocally(storeAuthDataLocally) { + EthereumContractIdentityProvider.storeAuthDataLocally = storeAuthDataLocally; + } + static splitId(id) { const regex = /(0x.*)(0x.*)/g; const match = regex.exec(id); diff --git a/src/ΕthereumIdentityProvider.js b/src/ΕthereumIdentityProvider.js index e8bd321..36c2f70 100644 --- a/src/ΕthereumIdentityProvider.js +++ b/src/ΕthereumIdentityProvider.js @@ -43,7 +43,7 @@ class EthereumIdentityProvider extends IdentityProvider { // Data to be signed is identity.publicKey + identity.signatures.id async signIdentity(data) { - if (process.env.NODE_ENV === 'development') { // Don't sign repeatedly while in development + if (EthereumIdentityProvider.storeAuthDataLocally) { console.debug(`${LOGGING_PREFIX}Attempting to find stored Orbit identity data...`); const signaturePubKey = await getIdentitySignaturePubKey(data); if (signaturePubKey) { @@ -66,7 +66,7 @@ class EthereumIdentityProvider extends IdentityProvider { async doSignIdentity(data) { try { const signaturePubKey = await EthereumIdentityProvider.web3.eth.personal.sign(data, this.id, ''); - if (process.env.NODE_ENV === 'development') { + if (EthereumIdentityProvider.storeAuthDataLocally) { storeIdentitySignaturePubKey(data, signaturePubKey) .then(() => { console.debug(`${LOGGING_PREFIX}Successfully stored current Orbit identity data.`); @@ -100,6 +100,11 @@ class EthereumIdentityProvider extends IdentityProvider { static setWeb3(web3) { EthereumIdentityProvider.web3 = web3; } + + // Opt to store auth data locally to avoid repeating MetaMask signing prompts + static setStoreAuthDataLocally(storeAuthDataLocally) { + EthereumIdentityProvider.storeAuthDataLocally = storeAuthDataLocally; + } } EthereumIdentityProvider.web3 = {};