Browse Source

feat: store auth data optionally

develop
Ezerous 3 years ago
parent
commit
1fd5f791d7
  1. 2
      package.json
  2. 9
      src/ΕthereumContractIdentityProvider.js
  3. 9
      src/ΕthereumIdentityProvider.js

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "@ecentrics/eth-identity-provider", "name": "@ecentrics/eth-identity-provider",
"version": "0.1.3", "version": "0.2.0",
"description": "An Ethereum orbit-db-identity-provider.", "description": "An Ethereum orbit-db-identity-provider.",
"license": "MIT", "license": "MIT",
"author": "Ezerous <ezerous@gmail.com>", "author": "Ezerous <ezerous@gmail.com>",

9
src/ΕthereumContractIdentityProvider.js

@ -51,7 +51,7 @@ class EthereumContractIdentityProvider extends IdentityProvider {
} }
async signIdentity(data) { 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...`); console.debug(`${LOGGING_PREFIX}Attempting to find stored Orbit identity data...`);
const signaturePubKey = await getIdentitySignaturePubKey(data); const signaturePubKey = await getIdentitySignaturePubKey(data);
if (signaturePubKey) { if (signaturePubKey) {
@ -74,7 +74,7 @@ class EthereumContractIdentityProvider extends IdentityProvider {
async doSignIdentity(data) { async doSignIdentity(data) {
try { try {
const signaturePubKey = await EthereumContractIdentityProvider.web3.eth.personal.sign(data, this.userAddress, ''); const signaturePubKey = await EthereumContractIdentityProvider.web3.eth.personal.sign(data, this.userAddress, '');
if (process.env.NODE_ENV === 'development') { if (EthereumContractIdentityProvider.storeAuthDataLocally) {
storeIdentitySignaturePubKey(data, signaturePubKey) storeIdentitySignaturePubKey(data, signaturePubKey)
.then(() => { .then(() => {
console.debug(`${LOGGING_PREFIX}Successfully stored current Orbit identity data.`); console.debug(`${LOGGING_PREFIX}Successfully stored current Orbit identity data.`);
@ -116,6 +116,11 @@ class EthereumContractIdentityProvider extends IdentityProvider {
EthereumContractIdentityProvider.contractAddress = contractAddress; EthereumContractIdentityProvider.contractAddress = contractAddress;
} }
// Opt to store auth data locally to avoid repeating MetaMask signing prompts
static setStoreAuthDataLocally(storeAuthDataLocally) {
EthereumContractIdentityProvider.storeAuthDataLocally = storeAuthDataLocally;
}
static splitId(id) { static splitId(id) {
const regex = /(0x.*)(0x.*)/g; const regex = /(0x.*)(0x.*)/g;
const match = regex.exec(id); const match = regex.exec(id);

9
src/ΕthereumIdentityProvider.js

@ -43,7 +43,7 @@ class EthereumIdentityProvider extends IdentityProvider {
// Data to be signed is identity.publicKey + identity.signatures.id // Data to be signed is identity.publicKey + identity.signatures.id
async signIdentity(data) { 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...`); console.debug(`${LOGGING_PREFIX}Attempting to find stored Orbit identity data...`);
const signaturePubKey = await getIdentitySignaturePubKey(data); const signaturePubKey = await getIdentitySignaturePubKey(data);
if (signaturePubKey) { if (signaturePubKey) {
@ -66,7 +66,7 @@ class EthereumIdentityProvider extends IdentityProvider {
async doSignIdentity(data) { async doSignIdentity(data) {
try { try {
const signaturePubKey = await EthereumIdentityProvider.web3.eth.personal.sign(data, this.id, ''); const signaturePubKey = await EthereumIdentityProvider.web3.eth.personal.sign(data, this.id, '');
if (process.env.NODE_ENV === 'development') { if (EthereumIdentityProvider.storeAuthDataLocally) {
storeIdentitySignaturePubKey(data, signaturePubKey) storeIdentitySignaturePubKey(data, signaturePubKey)
.then(() => { .then(() => {
console.debug(`${LOGGING_PREFIX}Successfully stored current Orbit identity data.`); console.debug(`${LOGGING_PREFIX}Successfully stored current Orbit identity data.`);
@ -100,6 +100,11 @@ class EthereumIdentityProvider extends IdentityProvider {
static setWeb3(web3) { static setWeb3(web3) {
EthereumIdentityProvider.web3 = web3; EthereumIdentityProvider.web3 = web3;
} }
// Opt to store auth data locally to avoid repeating MetaMask signing prompts
static setStoreAuthDataLocally(storeAuthDataLocally) {
EthereumIdentityProvider.storeAuthDataLocally = storeAuthDataLocally;
}
} }
EthereumIdentityProvider.web3 = {}; EthereumIdentityProvider.web3 = {};

Loading…
Cancel
Save