@etherplay/connect 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { AlchemyMechanism, OriginAccount } from '@etherplay/alchemy';
2
2
  import type { EIP1193WindowWalletProvider } from 'eip-1193';
3
- import { fromEntropyKeyToMnemonic } from '@etherplay/alchemy';
4
- export { fromEntropyKeyToMnemonic };
3
+ import { fromEntropyKeyToMnemonic, originKeyMessage, originPublicKeyPublicationMessage } from '@etherplay/alchemy';
4
+ export { fromEntropyKeyToMnemonic, originPublicKeyPublicationMessage, originKeyMessage };
5
5
  export type { OriginAccount };
6
6
  export type PopupSettings = {
7
7
  walletHost: string;
@@ -81,4 +81,5 @@ export declare function createConnection(settings: {
81
81
  requestSignature: () => Promise<void>;
82
82
  connectOnCurrentWalletAccount: (address: `0x${string}`) => void;
83
83
  disconnect: () => void;
84
+ getSignatureForPublicKeyPublication: () => Promise<`0x${string}`>;
84
85
  };
package/dist/index.js CHANGED
@@ -1,9 +1,8 @@
1
1
  import { writable } from 'svelte/store';
2
2
  import { createPopupLauncher } from './popup.js';
3
- import { fromEntropyKeyToMnemonic, fromMnemonicToFirstAccount, fromSignatureToKey, originKeyMessage } from '@etherplay/alchemy';
4
- import { bytesToHex } from '@noble/hashes/utils';
5
- export { fromEntropyKeyToMnemonic };
6
- const encoder = new TextEncoder();
3
+ import { fromEntropyKeyToMnemonic, fromMnemonicToFirstAccount, fromSignatureToKey, originKeyMessage, originPublicKeyPublicationMessage } from '@etherplay/alchemy';
4
+ import { hashMessage } from './utils.js';
5
+ export { fromEntropyKeyToMnemonic, originPublicKeyPublicationMessage, originKeyMessage };
7
6
  const storageAccountKey = '__origin_account';
8
7
  export function createConnection(settings) {
9
8
  let autoConnect = true;
@@ -146,8 +145,7 @@ export function createConnection(settings) {
146
145
  throw new Error(`no wallet provided initialised`);
147
146
  }
148
147
  const message = originKeyMessage(origin);
149
- const messageAsBytes = encoder.encode(message);
150
- const msg = `0x${bytesToHex(messageAsBytes)}`;
148
+ const msg = hashMessage(message);
151
149
  set({
152
150
  ...$connection,
153
151
  step: 'WaitingForSignature'
@@ -181,11 +179,13 @@ export function createConnection(settings) {
181
179
  signer: {
182
180
  origin,
183
181
  address: originAccount.address,
182
+ publicKey: originAccount.publicKey,
184
183
  privateKey: originAccount.privateKey,
185
184
  mnemonicKey: originKey
186
185
  },
187
186
  metadata: {},
188
- mechanismUsed: $connection.mechanism
187
+ mechanismUsed: $connection.mechanism,
188
+ savedPublicKeyPublicationSignature: undefined
189
189
  };
190
190
  set({
191
191
  ...$connection,
@@ -476,6 +476,29 @@ export function createConnection(settings) {
476
476
  popup?.cancel();
477
477
  set({ step: 'Idle', loading: false, wallets: $connection.wallets });
478
478
  }
479
+ function getSignatureForPublicKeyPublication() {
480
+ if ($connection.step !== 'SignedIn') {
481
+ throw new Error('Not signed in');
482
+ }
483
+ const account = $connection.account;
484
+ if ($connection.mechanism.type === 'wallet') {
485
+ if (!walletProvider) {
486
+ throw new Error(`no provider`);
487
+ }
488
+ const message = originPublicKeyPublicationMessage(origin, account.signer.publicKey);
489
+ const msg = hashMessage(message);
490
+ return walletProvider.request({
491
+ method: 'personal_sign',
492
+ params: [msg, account.address]
493
+ });
494
+ }
495
+ if (account.savedPublicKeyPublicationSignature) {
496
+ return Promise.resolve(account.savedPublicKeyPublicationSignature);
497
+ }
498
+ // TODO offer a way to use iframe + popup to sign the message
499
+ // this would require saving mnemonic or privatekey on etherplay localstorage though
500
+ throw new Error(`no saved public key publication signature for ${account.address}`);
501
+ }
479
502
  return {
480
503
  subscribe: _store.subscribe,
481
504
  connect,
@@ -483,6 +506,7 @@ export function createConnection(settings) {
483
506
  back,
484
507
  requestSignature,
485
508
  connectOnCurrentWalletAccount,
486
- disconnect
509
+ disconnect,
510
+ getSignatureForPublicKeyPublication
487
511
  };
488
512
  }
package/dist/utils.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  import type { Readable } from 'svelte/store';
2
2
  export declare function createStorePromise<U, T, V extends Readable<T>>(store: V, executor: (resolve: (value: U | PromiseLike<U>) => void, reject: (reason?: any) => void) => void): Promise<U> & V;
3
+ export declare function hashMessage(message: string): `0x${string}`;
package/dist/utils.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { bytesToHex } from '@noble/hashes/utils';
1
2
  export function createStorePromise(store, executor) {
2
3
  const storePromise = new Promise(executor);
3
4
  for (const key of Object.keys(store)) {
@@ -11,3 +12,9 @@ export function createStorePromise(store, executor) {
11
12
  }
12
13
  return storePromise;
13
14
  }
15
+ const encoder = new TextEncoder();
16
+ export function hashMessage(message) {
17
+ const messageAsBytes = encoder.encode(message);
18
+ const msg = `0x${bytesToHex(messageAsBytes)}`;
19
+ return msg;
20
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etherplay/connect",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -52,7 +52,7 @@
52
52
  "@scure/bip32": "^1.6.2",
53
53
  "@scure/bip39": "^1.5.4",
54
54
  "zustand": "^5.0.3",
55
- "@etherplay/alchemy": "0.0.3"
55
+ "@etherplay/alchemy": "0.0.5"
56
56
  },
57
57
  "scripts": {
58
58
  "dev": "vite dev --host --port 60002",