Skip to content
Permalink
Browse files

feat: add identities (#9)

* feat: add identities

* feat: add devices & profile orbitdb integration

Refactor identities.

* chore: add onChange to profile and fix identities onChange

* chore: identityDescriptor -> descriptor

* chore: revert parameters being prefixed with masterXXX

* chore: minor fixes to last commits

* chore: get schema from orbitdb when peeking or importing

* chore: change import schema to profile

* chore: implement getAsync to secret

* chore: fix ipfs not being able to connect to others

* chore: refactor

* chore: update tests

* fix: fix minor issues with the blob store
  • Loading branch information...
paulobmarcos committed May 28, 2019
1 parent aacfd10 commit 4bde10577800b4b9cf82313ed438f06abf03ae3d
Showing with 4,419 additions and 1,596 deletions.
  1. +1 −1 demo/src/shared/components/setup-locker/steps/SetupIdleTimer.js
  2. +1 −1 demo/src/shared/components/timer/Timer.js
  3. +155 −2 demo/src/shared/components/wallet/wallet-content/WalletContent.js
  4. +1,706 −1,052 package-lock.json
  5. +9 −1 package.json
  6. +6 −8 src/__tests__/index.test.js
  7. +0 −159 src/did/methods/__tests__/ipid.test.js
  8. +0 −20 src/did/methods/__tests__/mocks/index.js
  9. +0 −57 src/did/methods/ipid.js
  10. 0 src/{did → didm}/__tests__/__snapshots__/index.test.js.snap
  11. +26 −1 src/{did → didm}/__tests__/index.test.js
  12. +4 −1 src/{did → didm}/__tests__/mocks/index.js
  13. +25 −18 src/{did → didm}/index.js
  14. +234 −0 src/didm/methods/__tests__/ipid.test.js
  15. +44 −0 src/didm/methods/__tests__/mocks/index.js
  16. +104 −0 src/didm/methods/ipid.js
  17. +58 −0 src/identities/identity/backup.js
  18. +230 −0 src/identities/identity/devices.js
  19. +166 −0 src/identities/identity/index.js
  20. +254 −0 src/identities/identity/profile.js
  21. +156 −0 src/identities/identity/utils/blob-store.js
  22. +119 −0 src/identities/identity/utils/orbitdb.js
  23. +9 −0 src/identities/identity/utils/storage-keys.js
  24. +192 −0 src/identities/index.js
  25. +29 −9 src/index.js
  26. +19 −28 src/locker/__tests__/index.test.js
  27. +2 −4 src/locker/index.js
  28. +15 −3 src/locker/locks/__tests__/passphrase.test.js
  29. +1 −1 src/locker/locks/passphrase.js
  30. +14 −1 src/{locker/__tests__/secret.test.js → secret/__tests__/index.test.js}
  31. +12 −2 src/{locker/secret.js → secret/index.js}
  32. +239 −15 src/storage/__tests__/index.test.js
  33. +0 −152 src/storage/__tests__/local-storage.test.js
  34. +126 −0 src/storage/__tests__/mocks/index.js
  35. +175 −6 src/storage/index.js
  36. +0 −49 src/storage/local-storage.js
  37. +46 −0 src/utils/__tests__/aes-gcm.test.js
  38. +53 −0 src/utils/__tests__/mocks/index.js
  39. +18 −0 src/utils/__tests__/shat.test.js
  40. +28 −0 src/utils/aes-gcm.js
  41. +25 −0 src/utils/did.js
  42. +101 −5 src/utils/errors.js
  43. +17 −0 src/utils/sha.js
@@ -41,7 +41,7 @@ class SetupIdleTimer extends Component {
setMaxTime = (value) => {
const { locker, onComplete } = this.props;

locker.getIdleTimer().setMaxTime(value)
locker.idleTimer.setMaxTime(value)
.then(onComplete)
.catch((error) => this.setState({ loading: false, error }));
}
@@ -36,7 +36,7 @@ class Timer extends Component {

this.idleTimeout = setTimeout(this.getRemainingTime, 250);

this.setState({ time: locker.getIdleTimer().getRemainingTime() });
this.setState({ time: locker.idleTimer.getRemainingTime() });
}
}

@@ -6,6 +6,12 @@ import Timer from '../../timer/Timer';
import './WalletContent.css';

class WalletContent extends Component {
componentDidMount() {
const { wallet } = this.props;

wallet.identities.load();
}

render() {
const { wallet: { locker } } = this.props;

@@ -43,6 +49,47 @@ class WalletContent extends Component {
</div>
</div>
</div>
<div className="section">
<h4>Identities</h4>
<div className="content">
<div className="option">
<span>List</span>
<button onClick={ this.handleList }>List</button>
</div>
<div className="option">
<span>Create</span>
<button onClick={ this.handleCreate }>Create</button>
</div>
<div className="option">
<span>Peek</span>
<input
type="text"
placeholder="mnemonic"
onChange={ this.handlePeekInputChange } />
<button onClick={ this.handlePeekSubmit }>Submit</button>
</div>
<div className="option">
<span>Import</span>
<input
type="text"
placeholder="mnemonic"
onChange={ this.handleImportInputChange } />
<button onClick={ this.handleImportSubmit }>Submit</button>
</div>
<div className="option">
<span>Remove</span>
<input
type="text"
placeholder="id"
onChange={ this.handleRemoveIdChange } />
<input
type="text"
placeholder="mnemonic"
onChange={ this.handleRemoveMnemonicChange } />
<button onClick={ this.handleRemoveSubmit }>Remove</button>
</div>
</div>
</div>
</div>
</div>
</div>
@@ -58,7 +105,7 @@ class WalletContent extends Component {
handleRestartTimer = () => {
const { wallet: { locker } } = this.props;

locker.getIdleTimer().restart();
locker.idleTimer.restart();
};

handleMaxTimeInputChange = (event) => {
@@ -69,9 +116,115 @@ class WalletContent extends Component {
const { wallet: { locker } } = this.props;

if (this.maxInputTime > 0) {
locker.getIdleTimer().setMaxTime(this.maxInputTime * 60 * 1000);
locker.idleTimer.setMaxTime(this.maxInputTime * 60 * 1000);
}
};

// IDENTITIES ------------------------------------

handleList = () => {
const { wallet } = this.props;

try {
const identities = wallet.identities.list();

console.log('List Identities:');
identities.forEach((identity) => {
console.log('Identity:', identity);
console.log('Serialized:', {
addedAt: identity.getAddedAt(),
id: identity.getId(),
did: identity.getDid(),
devices: identity.devices.list(),
backup: identity.backup.getData(),
profile: identity.profile.getDetails(),
});
console.log(' ');
});
console.log('Final List Identities.');
} catch (err) {
console.error(err);
}
};

handleCreate = () => {
const { wallet } = this.props;

wallet.identities.create('ipid', {
profileDetails: {
'@context': 'https://schema.org',
'@type': 'Person',
name: 'John Doe',
},
deviceInfo: {
type: 'laptop',
name: 'MacBook Pro'
},
})
.then((identity) => {
console.log('Created Identity:')
console.log('Identity:', identity);
console.log('Serialized:', {
addedAt: identity.getAddedAt(),
id: identity.getId(),
did: identity.getDid(),
devices: identity.devices.list(),
backup: identity.backup.getData(),
profile: identity.profile.getDetails(),
});
console.log(' ');
console.log('End of Created Identity.')
});
};

handleImportInputChange = (event) => {
this.importValue = event.target.value;
};

handleImportSubmit = () => {
const { wallet } = this.props;

wallet.identities.import('ipid', {
mnemonic: this.importValue,
deviceInfo: {
type: 'laptop',
name: 'MacBook Pro'
},
})
.then((result) => console.log('Imported Identity:', result))
};

handlePeekInputChange = (event) => {
this.peekValue = event.target.value;
};

handlePeekSubmit = () => {
const { wallet } = this.props;

wallet.identities.peek('ipid', {
mnemonic: this.peekValue,
})
.then((result) => console.log('Peek Resolved:', result));
};

handleRemoveIdChange = (event) => {
this.removeIdValue = event.target.value;
};

handleRemoveMnemonicChange = (event) => {
this.removeMnemonicValue = event.target.value;
};

handleRemoveSubmit = () => {
const { wallet } = this.props;

wallet.identities.remove(this.removeIdValue, {
mnemonic: this.removeMnemonicValue,
})
.then(() => console.log('Removed Successfully!'));
};

// -----------------------------------------------
}

WalletContent.propTypes = {

0 comments on commit 4bde105

Please sign in to comment.
You can’t perform that action at this time.