@bsv/sdk 1.3.9 → 1.3.11

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.
Files changed (72) hide show
  1. package/dist/cjs/package.json +1 -1
  2. package/dist/cjs/src/auth/Peer.js.map +1 -1
  3. package/dist/cjs/src/auth/certificates/Certificate.js +1 -1
  4. package/dist/cjs/src/auth/certificates/Certificate.js.map +1 -1
  5. package/dist/cjs/src/auth/certificates/MasterCertificate.js +93 -63
  6. package/dist/cjs/src/auth/certificates/MasterCertificate.js.map +1 -1
  7. package/dist/cjs/src/auth/certificates/VerifiableCertificate.js +2 -2
  8. package/dist/cjs/src/auth/certificates/VerifiableCertificate.js.map +1 -1
  9. package/dist/cjs/src/auth/utils/createNonce.js +9 -3
  10. package/dist/cjs/src/auth/utils/createNonce.js.map +1 -1
  11. package/dist/cjs/src/auth/utils/getVerifiableCertificates.js +1 -1
  12. package/dist/cjs/src/auth/utils/getVerifiableCertificates.js.map +1 -1
  13. package/dist/cjs/src/auth/utils/validateCertificates.js +1 -1
  14. package/dist/cjs/src/auth/utils/validateCertificates.js.map +1 -1
  15. package/dist/cjs/src/auth/utils/verifyNonce.js +3 -2
  16. package/dist/cjs/src/auth/utils/verifyNonce.js.map +1 -1
  17. package/dist/cjs/src/overlay-tools/OverlayAdminTokenTemplate.js.map +1 -1
  18. package/dist/cjs/src/wallet/ProtoWallet.js.map +1 -1
  19. package/dist/cjs/src/wallet/WalletClient.js.map +1 -1
  20. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  21. package/dist/esm/src/auth/Peer.js.map +1 -1
  22. package/dist/esm/src/auth/certificates/Certificate.js +2 -2
  23. package/dist/esm/src/auth/certificates/Certificate.js.map +1 -1
  24. package/dist/esm/src/auth/certificates/MasterCertificate.js +93 -63
  25. package/dist/esm/src/auth/certificates/MasterCertificate.js.map +1 -1
  26. package/dist/esm/src/auth/certificates/VerifiableCertificate.js +2 -2
  27. package/dist/esm/src/auth/certificates/VerifiableCertificate.js.map +1 -1
  28. package/dist/esm/src/auth/utils/createNonce.js +9 -3
  29. package/dist/esm/src/auth/utils/createNonce.js.map +1 -1
  30. package/dist/esm/src/auth/utils/getVerifiableCertificates.js +1 -1
  31. package/dist/esm/src/auth/utils/getVerifiableCertificates.js.map +1 -1
  32. package/dist/esm/src/auth/utils/validateCertificates.js +1 -1
  33. package/dist/esm/src/auth/utils/validateCertificates.js.map +1 -1
  34. package/dist/esm/src/auth/utils/verifyNonce.js +3 -2
  35. package/dist/esm/src/auth/utils/verifyNonce.js.map +1 -1
  36. package/dist/esm/src/overlay-tools/OverlayAdminTokenTemplate.js.map +1 -1
  37. package/dist/esm/src/wallet/ProtoWallet.js.map +1 -1
  38. package/dist/esm/src/wallet/WalletClient.js.map +1 -1
  39. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  40. package/dist/types/src/auth/Peer.d.ts.map +1 -1
  41. package/dist/types/src/auth/certificates/Certificate.d.ts +3 -3
  42. package/dist/types/src/auth/certificates/Certificate.d.ts.map +1 -1
  43. package/dist/types/src/auth/certificates/MasterCertificate.d.ts +41 -11
  44. package/dist/types/src/auth/certificates/MasterCertificate.d.ts.map +1 -1
  45. package/dist/types/src/auth/certificates/VerifiableCertificate.d.ts +1 -1
  46. package/dist/types/src/auth/certificates/VerifiableCertificate.d.ts.map +1 -1
  47. package/dist/types/src/auth/utils/createNonce.d.ts +4 -3
  48. package/dist/types/src/auth/utils/createNonce.d.ts.map +1 -1
  49. package/dist/types/src/auth/utils/verifyNonce.d.ts +3 -2
  50. package/dist/types/src/auth/utils/verifyNonce.d.ts.map +1 -1
  51. package/dist/types/src/overlay-tools/OverlayAdminTokenTemplate.d.ts.map +1 -1
  52. package/dist/types/src/wallet/ProtoWallet.d.ts.map +1 -1
  53. package/dist/types/src/wallet/WalletClient.d.ts.map +1 -1
  54. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  55. package/dist/umd/bundle.js +1 -1
  56. package/docs/auth.md +71 -26
  57. package/package.json +1 -1
  58. package/src/auth/Peer.ts +21 -21
  59. package/src/auth/__tests/Peer.test.ts +19 -47
  60. package/src/auth/certificates/Certificate.ts +3 -3
  61. package/src/auth/certificates/MasterCertificate.ts +131 -67
  62. package/src/auth/certificates/VerifiableCertificate.ts +3 -4
  63. package/src/auth/certificates/__tests/MasterCertificate.test.ts +142 -51
  64. package/src/auth/certificates/__tests/VerifiableCertificate.test.ts +25 -30
  65. package/src/auth/utils/__tests/cryptononce.test.ts +42 -7
  66. package/src/auth/utils/createNonce.ts +10 -4
  67. package/src/auth/utils/getVerifiableCertificates.ts +2 -2
  68. package/src/auth/utils/validateCertificates.ts +2 -2
  69. package/src/auth/utils/verifyNonce.ts +4 -3
  70. package/src/overlay-tools/OverlayAdminTokenTemplate.ts +4 -4
  71. package/src/wallet/ProtoWallet.ts +10 -10
  72. package/src/wallet/WalletClient.ts +30 -30
@@ -2,14 +2,15 @@ import { VerifiableCertificate } from '../../../../dist/cjs/src/auth/certificate
2
2
  import { PrivateKey, SymmetricKey, Utils } from '../../../../dist/cjs/src/primitives/index.js'
3
3
  import { CompletedProtoWallet } from '../../../../dist/cjs/src/auth/certificates/__tests/CompletedProtoWallet.js'
4
4
  import { Certificate } from '../../../../dist/cjs/src/auth/certificates/index.js'
5
+ import { MasterCertificate } from '../../../../dist/cjs/src/auth/certificates/MasterCertificate.js'
5
6
 
6
7
  describe('VerifiableCertificate', () => {
7
8
  const subjectPrivateKey = PrivateKey.fromRandom()
8
- const subjectPubKey = subjectPrivateKey.toPublicKey().toString()
9
+ const subjectIdentityKey = subjectPrivateKey.toPublicKey().toString()
9
10
  const certifierPrivateKey = PrivateKey.fromRandom()
10
- const certifierPubKey = certifierPrivateKey.toPublicKey().toString()
11
+ const certifierIdentityKey = certifierPrivateKey.toPublicKey().toString()
11
12
  const verifierPrivateKey = PrivateKey.fromRandom()
12
- const verifierPubKey = verifierPrivateKey.toPublicKey().toString()
13
+ const verifierIdentityKey = verifierPrivateKey.toPublicKey().toString()
13
14
 
14
15
  const subjectWallet = new CompletedProtoWallet(subjectPrivateKey)
15
16
  const verifierWallet = new CompletedProtoWallet(verifierPrivateKey)
@@ -28,34 +29,28 @@ describe('VerifiableCertificate', () => {
28
29
 
29
30
  beforeEach(async () => {
30
31
  // For each test, we'll build a fresh VerifiableCertificate with valid encryption
31
- const certificateFields = {}
32
- const keyring = {}
33
-
34
- for (const fieldName in plaintextFields) {
35
- // Generate a random field symmetric key
36
- const fieldSymKey = SymmetricKey.fromRandom()
37
- // Encrypt the field's plaintext
38
- const encryptedFieldValue = fieldSymKey.encrypt(Utils.toArray(plaintextFields[fieldName], 'utf8'))
39
- certificateFields[fieldName] = Utils.toBase64(encryptedFieldValue as number[])
40
-
41
- // Now encrypt the fieldSymKey for the verifier
42
- const { ciphertext: encryptedRevelationKey } = await subjectWallet.encrypt({
43
- plaintext: fieldSymKey.toArray(),
44
- ...Certificate.getCertificateFieldEncryptionDetails(sampleSerialNumber, fieldName),
45
- counterparty: verifierPubKey
46
- })
47
- keyring[fieldName] = Utils.toBase64(encryptedRevelationKey)
48
- }
49
-
32
+ const { certificateFields, masterKeyring } = await MasterCertificate.createCertificateFields(
33
+ subjectWallet,
34
+ certifierIdentityKey,
35
+ plaintextFields
36
+ )
37
+ const keyringForVerifier = await MasterCertificate.createKeyringForVerifier(
38
+ subjectWallet,
39
+ certifierIdentityKey,
40
+ verifierIdentityKey,
41
+ certificateFields,
42
+ Object.keys(certificateFields),
43
+ masterKeyring,
44
+ sampleSerialNumber
45
+ )
50
46
  verifiableCert = new VerifiableCertificate(
51
47
  sampleType,
52
48
  sampleSerialNumber,
53
- subjectPubKey,
54
- certifierPubKey,
49
+ subjectIdentityKey,
50
+ certifierIdentityKey,
55
51
  sampleRevocationOutpoint,
56
52
  certificateFields,
57
- undefined, // signature
58
- keyring
53
+ keyringForVerifier
59
54
  )
60
55
  })
61
56
 
@@ -64,8 +59,8 @@ describe('VerifiableCertificate', () => {
64
59
  expect(verifiableCert).toBeInstanceOf(VerifiableCertificate)
65
60
  expect(verifiableCert.type).toEqual(sampleType)
66
61
  expect(verifiableCert.serialNumber).toEqual(sampleSerialNumber)
67
- expect(verifiableCert.subject).toEqual(subjectPubKey)
68
- expect(verifiableCert.certifier).toEqual(certifierPubKey)
62
+ expect(verifiableCert.subject).toEqual(subjectIdentityKey)
63
+ expect(verifiableCert.certifier).toEqual(certifierIdentityKey)
69
64
  expect(verifiableCert.revocationOutpoint).toEqual(sampleRevocationOutpoint)
70
65
  expect(verifiableCert.fields).toBeDefined()
71
66
  expect(verifiableCert.keyring).toBeDefined()
@@ -97,8 +92,8 @@ describe('VerifiableCertificate', () => {
97
92
  verifiableCert.certifier,
98
93
  verifiableCert.revocationOutpoint,
99
94
  fields,
100
- verifiableCert.signature,
101
- {} // empty
95
+ {}, // empty
96
+ verifiableCert.signature
102
97
  )
103
98
 
104
99
  await expect(emptyKeyringCert.decryptFields(verifierWallet)).rejects.toThrow(
@@ -1,16 +1,17 @@
1
- import { PrivateKey } from '../../../../dist/cjs/src/primitives/index.js'
2
- import { ProtoWallet } from '../../../../dist/cjs/src/wallet/index.js'
3
- import { Wallet } from '../../../../dist/cjs/src/wallet/Wallet.interfaces.js'
1
+ import { PrivateKey, Random, Utils } from '../../../../dist/cjs/src/primitives/index.js'
2
+ import { ProtoWallet } from '../../../../dist/cjs/src/wallet/ProtoWallet.js'
3
+ import { WalletInterface } from '../../../../dist/cjs/src/wallet/Wallet.interfaces.js'
4
4
  import { createNonce } from '../../../../dist/cjs/src/auth/utils/createNonce.js'
5
5
  import { verifyNonce } from '../../../../dist/cjs/src/auth/utils/verifyNonce.js'
6
+ import { hash256 } from '../../../../dist/cjs/src/primitives/Hash.js'
6
7
 
7
8
  describe('createNonce', () => {
8
- let mockWallet: Wallet
9
+ let mockWallet: WalletInterface
9
10
 
10
11
  beforeEach(() => {
11
12
  mockWallet = {
12
13
  createHmac: jest.fn().mockResolvedValue({ hmac: new Uint8Array(16) }),
13
- } as unknown as Wallet
14
+ } as unknown as WalletInterface
14
15
  })
15
16
 
16
17
  afterEach(() => {
@@ -31,13 +32,13 @@ describe('createNonce', () => {
31
32
  })
32
33
 
33
34
  describe('verifyNonce', () => {
34
- let mockWallet: Wallet
35
+ let mockWallet: WalletInterface
35
36
 
36
37
  beforeEach(() => {
37
38
  mockWallet = {
38
39
  createHmac: jest.fn().mockResolvedValue({ hmac: new Uint8Array(16) }),
39
40
  verifyHmac: jest.fn().mockResolvedValue({ valid: true }),
40
- } as unknown as Wallet
41
+ } as unknown as WalletInterface
41
42
  })
42
43
 
43
44
  afterEach(() => {
@@ -81,4 +82,38 @@ describe('verifyNonce', () => {
81
82
 
82
83
  expect(isValid).toEqual(true)
83
84
  })
85
+
86
+ it('SerialNumber use-case', async () => {
87
+ const clientWallet = new ProtoWallet(PrivateKey.fromRandom())
88
+ const serverWallet = new ProtoWallet(PrivateKey.fromRandom())
89
+
90
+ // Client creates a random nonce that the server can verify
91
+ const clientNonce = await createNonce(clientWallet, (await serverWallet.getPublicKey({ identityKey: true })).publicKey)
92
+ // The server verifies the client created the nonce provided
93
+ await verifyNonce(clientNonce, serverWallet, (await clientWallet.getPublicKey({ identityKey: true })).publicKey)
94
+ // Server creates a random nonce that the client can verify
95
+ const serverNonce = await createNonce(serverWallet, (await clientWallet.getPublicKey({ identityKey: true })).publicKey)
96
+ // The server compute a serial number from the client and server nonce
97
+ const { hmac: serialNumber } = await serverWallet.createHmac({
98
+ data: clientNonce + serverNonce,
99
+ protocolID: [2, 'certificate creation'],
100
+ keyID: serverNonce + clientNonce,
101
+ counterparty: (await clientWallet.getPublicKey({ identityKey: true })).publicKey
102
+ })
103
+
104
+ // Client verifies server's nonce
105
+ await verifyNonce(serverNonce, clientWallet, (await serverWallet.getPublicKey({ identityKey: true })).publicKey)
106
+
107
+ // Client verifies the server included their nonce
108
+ const { valid } = await clientWallet.verifyHmac({
109
+ hmac: serialNumber,
110
+ data: clientNonce + serverNonce,
111
+ protocolID: [2, 'certificate creation'],
112
+ keyID: serverNonce + clientNonce,
113
+ counterparty: (await serverWallet.getPublicKey({ identityKey: true })).publicKey,
114
+ })
115
+
116
+ console.log(Utils.toBase64(serialNumber))
117
+ expect(valid).toEqual(true)
118
+ })
84
119
  })
@@ -1,15 +1,21 @@
1
- import { Utils, Random, WalletInterface } from '../../../mod.js'
1
+ import { Utils, Random, WalletInterface, WalletCounterparty } from '../../../mod.js'
2
2
 
3
3
  /**
4
- * Creates a nonce derived from a privateKey
4
+ * Creates a nonce derived from a wallet
5
5
  * @param wallet
6
+ * @param counterparty - The counterparty to the nonce creation. Defaults to 'self'.
6
7
  * @returns A random nonce derived with a wallet
7
8
  */
8
- export async function createNonce(wallet: WalletInterface): Promise<string> {
9
+ export async function createNonce(wallet: WalletInterface, counterparty: WalletCounterparty = 'self'): Promise<string> {
9
10
  // Generate 16 random bytes for the first half of the data
10
11
  const firstHalf = Random(16)
11
12
  // Create an sha256 HMAC
12
- const { hmac } = await wallet.createHmac({ protocolID: [2, 'server hmac'], keyID: Utils.toUTF8(firstHalf), data: firstHalf, counterparty: 'self' })
13
+ const { hmac } = await wallet.createHmac({
14
+ protocolID: [2, 'server hmac'],
15
+ keyID: Utils.toUTF8(firstHalf),
16
+ data: firstHalf,
17
+ counterparty
18
+ })
13
19
  // Concatenate firstHalf and secondHalf as the nonce bytes
14
20
  const nonceBytes = [...firstHalf, ...hmac]
15
21
  return Utils.toBase64(nonceBytes)
@@ -33,8 +33,8 @@ export const getVerifiableCertificates = async (wallet: WalletInterface, request
33
33
  certificate.certifier,
34
34
  certificate.revocationOutpoint,
35
35
  certificate.fields,
36
- certificate.signature,
37
- keyringForVerifier
36
+ keyringForVerifier,
37
+ certificate.signature
38
38
  )
39
39
  }))
40
40
  }
@@ -24,8 +24,8 @@ export const validateCertificates = async (verifierWallet: WalletInterface, mess
24
24
  incomingCert.certifier,
25
25
  incomingCert.revocationOutpoint,
26
26
  incomingCert.fields,
27
- incomingCert.signature,
28
- incomingCert.keyring
27
+ incomingCert.keyring,
28
+ incomingCert.signature
29
29
  )
30
30
  const isValidCert = await certToVerify.verify()
31
31
  if (!isValidCert) {
@@ -1,12 +1,13 @@
1
- import { Utils, WalletInterface } from '../../../mod.js'
1
+ import { Utils, WalletCounterparty, WalletInterface } from '../../../mod.js'
2
2
 
3
3
  /**
4
4
  * Verifies a nonce derived from a wallet
5
5
  * @param nonce - A nonce to verify as a base64 string.
6
6
  * @param wallet
7
+ * @param counterparty - The counterparty to the nonce creation. Defaults to 'self'.
7
8
  * @returns The status of the validation
8
9
  */
9
- export async function verifyNonce(nonce: string, wallet: WalletInterface): Promise<boolean> {
10
+ export async function verifyNonce(nonce: string, wallet: WalletInterface, counterparty: WalletCounterparty = 'self'): Promise<boolean> {
10
11
  // Convert nonce from base64 string to Uint8Array
11
12
  const buffer = Utils.toArray(nonce, 'base64')
12
13
 
@@ -20,7 +21,7 @@ export async function verifyNonce(nonce: string, wallet: WalletInterface): Promi
20
21
  hmac,
21
22
  protocolID: [2, 'server hmac'],
22
23
  keyID: Utils.toUTF8(data),
23
- counterparty: 'self'
24
+ counterparty
24
25
  })
25
26
 
26
27
  return valid
@@ -15,7 +15,7 @@ export default class OverlayAdminTokenTemplate implements ScriptTemplate {
15
15
  * @param script Locking script comprising a SHIP or SLAP token to decode
16
16
  * @returns Decoded SHIP or SLAP advertisement
17
17
  */
18
- static decode(script: LockingScript): { protocol: 'SHIP' | 'SLAP', identityKey: string, domain: string, topicOrService: string } {
18
+ static decode (script: LockingScript): { protocol: 'SHIP' | 'SLAP', identityKey: string, domain: string, topicOrService: string } {
19
19
  const result = PushDrop.decode(script)
20
20
  if (result.fields.length < 4) {
21
21
  throw new Error('Invalid SHIP/SLAP advertisement!')
@@ -39,7 +39,7 @@ export default class OverlayAdminTokenTemplate implements ScriptTemplate {
39
39
  * Constructs a new Overlay Admin template instance
40
40
  * @param wallet Wallet to use for locking and unlocking
41
41
  */
42
- constructor(wallet: WalletInterface) {
42
+ constructor (wallet: WalletInterface) {
43
43
  this.pushDrop = new PushDrop(wallet)
44
44
  }
45
45
 
@@ -50,7 +50,7 @@ export default class OverlayAdminTokenTemplate implements ScriptTemplate {
50
50
  * @param topicOrService Topic or service to advertise
51
51
  * @returns Locking script comprising the advertisement token
52
52
  */
53
- async lock(protocol: 'SHIP' | 'SLAP', domain: string, topicOrService: string): Promise<LockingScript> {
53
+ async lock (protocol: 'SHIP' | 'SLAP', domain: string, topicOrService: string): Promise<LockingScript> {
54
54
  const { publicKey: identityKey } = await this.pushDrop.wallet.getPublicKey({ identityKey: true })
55
55
  return await this.pushDrop.lock(
56
56
  [
@@ -70,7 +70,7 @@ export default class OverlayAdminTokenTemplate implements ScriptTemplate {
70
70
  * @param protocol SHIP or SLAP, depending on the token to unlock
71
71
  * @returns Script unlocker capable of unlocking the advertisement token
72
72
  */
73
- unlock(protocol: 'SHIP' | 'SLAP'): {
73
+ unlock (protocol: 'SHIP' | 'SLAP'): {
74
74
  sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>
75
75
  estimateLength: (tx: Transaction, inputIndex: number) => Promise<number>
76
76
  } {
@@ -35,14 +35,14 @@ import {
35
35
  export class ProtoWallet {
36
36
  keyDeriver: KeyDeriverApi
37
37
 
38
- constructor(rootKeyOrKeyDeriver: PrivateKey | 'anyone' | KeyDeriverApi) {
38
+ constructor (rootKeyOrKeyDeriver: PrivateKey | 'anyone' | KeyDeriverApi) {
39
39
  if (typeof (rootKeyOrKeyDeriver as KeyDeriver).identityKey !== 'string') {
40
40
  rootKeyOrKeyDeriver = new KeyDeriver(rootKeyOrKeyDeriver as PrivateKey | 'anyone')
41
41
  }
42
42
  this.keyDeriver = rootKeyOrKeyDeriver as KeyDeriver
43
43
  }
44
44
 
45
- async getPublicKey(
45
+ async getPublicKey (
46
46
  args: GetPublicKeyArgs
47
47
  ): Promise<{ publicKey: PubKeyHex }> {
48
48
  if (args.identityKey) {
@@ -64,7 +64,7 @@ export class ProtoWallet {
64
64
  }
65
65
  }
66
66
 
67
- async revealCounterpartyKeyLinkage(
67
+ async revealCounterpartyKeyLinkage (
68
68
  args: RevealCounterpartyKeyLinkageArgs
69
69
  ): Promise<RevealCounterpartyKeyLinkageResult> {
70
70
  const { publicKey: identityKey } = await this.getPublicKey({ identityKey: true })
@@ -98,7 +98,7 @@ export class ProtoWallet {
98
98
  }
99
99
  }
100
100
 
101
- async revealSpecificKeyLinkage(
101
+ async revealSpecificKeyLinkage (
102
102
  args: RevealSpecificKeyLinkageArgs
103
103
  ): Promise<RevealSpecificKeyLinkageResult> {
104
104
  const { publicKey: identityKey } = await this.getPublicKey({ identityKey: true })
@@ -131,7 +131,7 @@ export class ProtoWallet {
131
131
  }
132
132
  }
133
133
 
134
- async encrypt(
134
+ async encrypt (
135
135
  args: WalletEncryptArgs
136
136
  ): Promise<WalletEncryptResult> {
137
137
  const key = this.keyDeriver.deriveSymmetricKey(
@@ -142,7 +142,7 @@ export class ProtoWallet {
142
142
  return { ciphertext: key.encrypt(args.plaintext) as number[] }
143
143
  }
144
144
 
145
- async decrypt(
145
+ async decrypt (
146
146
  args: WalletDecryptArgs
147
147
  ): Promise<WalletDecryptResult> {
148
148
  const key = this.keyDeriver.deriveSymmetricKey(
@@ -153,7 +153,7 @@ export class ProtoWallet {
153
153
  return { plaintext: key.decrypt(args.ciphertext) as number[] }
154
154
  }
155
155
 
156
- async createHmac(
156
+ async createHmac (
157
157
  args: CreateHmacArgs
158
158
  ): Promise<CreateHmacResult> {
159
159
  const key = this.keyDeriver.deriveSymmetricKey(
@@ -164,7 +164,7 @@ export class ProtoWallet {
164
164
  return { hmac: Hash.sha256hmac(key.toArray(), args.data) }
165
165
  }
166
166
 
167
- async verifyHmac(
167
+ async verifyHmac (
168
168
  args: VerifyHmacArgs
169
169
  ): Promise<VerifyHmacResult> {
170
170
  const key = this.keyDeriver.deriveSymmetricKey(
@@ -181,7 +181,7 @@ export class ProtoWallet {
181
181
  return { valid }
182
182
  }
183
183
 
184
- async createSignature(
184
+ async createSignature (
185
185
  args: CreateSignatureArgs
186
186
  ): Promise<CreateSignatureResult> {
187
187
  if (!args.hashToDirectlySign && !args.data) {
@@ -196,7 +196,7 @@ export class ProtoWallet {
196
196
  return { signature: ECDSA.sign(new BigNumber(hash), key, true).toDER() as number[] }
197
197
  }
198
198
 
199
- async verifySignature(
199
+ async verifySignature (
200
200
  args: VerifySignatureArgs
201
201
  ): Promise<VerifySignatureResult> {
202
202
  if (!args.hashToDirectlyVerify && !args.data) {
@@ -13,7 +13,7 @@ const MAX_XDM_RESPONSE_WAIT = 200
13
13
  export default class WalletClient implements WalletInterface {
14
14
  public substrate: 'auto' | WalletInterface
15
15
  originator?: OriginatorDomainNameStringUnder250Bytes
16
- constructor(substrate: 'auto' | 'Cicada' | 'XDM' | 'window.CWI' | 'json-api' | WalletInterface = 'auto', originator?: OriginatorDomainNameStringUnder250Bytes) {
16
+ constructor (substrate: 'auto' | 'Cicada' | 'XDM' | 'window.CWI' | 'json-api' | WalletInterface = 'auto', originator?: OriginatorDomainNameStringUnder250Bytes) {
17
17
  if (substrate === 'Cicada') substrate = new WalletWireTransceiver(new HTTPWalletWire(originator))
18
18
  if (substrate === 'window.CWI') substrate = new WindowCWISubstrate()
19
19
  if (substrate === 'XDM') substrate = new XDMSubstrate()
@@ -22,7 +22,7 @@ export default class WalletClient implements WalletInterface {
22
22
  this.originator = originator
23
23
  }
24
24
 
25
- async connectToSubstrate() {
25
+ async connectToSubstrate () {
26
26
  if (typeof this.substrate === 'object') {
27
27
  return // substrate is already connected
28
28
  }
@@ -68,141 +68,141 @@ export default class WalletClient implements WalletInterface {
68
68
  }
69
69
  }
70
70
 
71
- async createAction(args: CreateActionArgs): Promise<CreateActionResult> {
71
+ async createAction (args: CreateActionArgs): Promise<CreateActionResult> {
72
72
  await this.connectToSubstrate()
73
73
  return await (this.substrate as WalletInterface).createAction(args, this.originator)
74
74
  }
75
75
 
76
- async signAction(args: SignActionArgs): Promise<SignActionResult> {
76
+ async signAction (args: SignActionArgs): Promise<SignActionResult> {
77
77
  await this.connectToSubstrate()
78
78
  return await (this.substrate as WalletInterface).signAction(args, this.originator)
79
79
  }
80
80
 
81
- async abortAction(args: { reference: Base64String }): Promise<{ aborted: true }> {
81
+ async abortAction (args: { reference: Base64String }): Promise<{ aborted: true }> {
82
82
  await this.connectToSubstrate()
83
83
  return await (this.substrate as WalletInterface).abortAction(args, this.originator)
84
84
  }
85
85
 
86
- async listActions(args: ListActionsArgs): Promise<ListActionsResult> {
86
+ async listActions (args: ListActionsArgs): Promise<ListActionsResult> {
87
87
  await this.connectToSubstrate()
88
88
  return await (this.substrate as WalletInterface).listActions(args, this.originator)
89
89
  }
90
90
 
91
- async internalizeAction(args: InternalizeActionArgs): Promise<{ accepted: true }> {
91
+ async internalizeAction (args: InternalizeActionArgs): Promise<{ accepted: true }> {
92
92
  await this.connectToSubstrate()
93
93
  return await (this.substrate as WalletInterface).internalizeAction(args, this.originator)
94
94
  }
95
95
 
96
- async listOutputs(args: ListOutputsArgs): Promise<ListOutputsResult> {
96
+ async listOutputs (args: ListOutputsArgs): Promise<ListOutputsResult> {
97
97
  await this.connectToSubstrate()
98
98
  return await (this.substrate as WalletInterface).listOutputs(args, this.originator)
99
99
  }
100
100
 
101
- async relinquishOutput(args: { basket: BasketStringUnder300Bytes, output: OutpointString }): Promise<{ relinquished: true }> {
101
+ async relinquishOutput (args: { basket: BasketStringUnder300Bytes, output: OutpointString }): Promise<{ relinquished: true }> {
102
102
  await this.connectToSubstrate()
103
103
  return await (this.substrate as WalletInterface).relinquishOutput(args, this.originator)
104
104
  }
105
105
 
106
- async getPublicKey(args: { identityKey?: true, protocolID?: [SecurityLevel, ProtocolString5To400Bytes], keyID?: KeyIDStringUnder800Bytes, privileged?: BooleanDefaultFalse, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', forSelf?: BooleanDefaultFalse }): Promise<{ publicKey: PubKeyHex }> {
106
+ async getPublicKey (args: { identityKey?: true, protocolID?: [SecurityLevel, ProtocolString5To400Bytes], keyID?: KeyIDStringUnder800Bytes, privileged?: BooleanDefaultFalse, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', forSelf?: BooleanDefaultFalse }): Promise<{ publicKey: PubKeyHex }> {
107
107
  await this.connectToSubstrate()
108
108
  return await (this.substrate as WalletInterface).getPublicKey(args, this.originator)
109
109
  }
110
110
 
111
- async revealCounterpartyKeyLinkage(args: { counterparty: PubKeyHex, verifier: PubKeyHex, privilegedReason?: DescriptionString5to50Bytes, privileged?: BooleanDefaultFalse }): Promise<{ prover: PubKeyHex, verifier: PubKeyHex, counterparty: PubKeyHex, revelationTime: ISOTimestampString, encryptedLinkage: Byte[], encryptedLinkageProof: Byte[] }> {
111
+ async revealCounterpartyKeyLinkage (args: { counterparty: PubKeyHex, verifier: PubKeyHex, privilegedReason?: DescriptionString5to50Bytes, privileged?: BooleanDefaultFalse }): Promise<{ prover: PubKeyHex, verifier: PubKeyHex, counterparty: PubKeyHex, revelationTime: ISOTimestampString, encryptedLinkage: Byte[], encryptedLinkageProof: Byte[] }> {
112
112
  await this.connectToSubstrate()
113
113
  return await (this.substrate as WalletInterface).revealCounterpartyKeyLinkage(args, this.originator)
114
114
  }
115
115
 
116
- async revealSpecificKeyLinkage(args: { counterparty: PubKeyHex, verifier: PubKeyHex, protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, privileged?: BooleanDefaultFalse }): Promise<{ prover: PubKeyHex, verifier: PubKeyHex, counterparty: PubKeyHex, protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, encryptedLinkage: Byte[], encryptedLinkageProof: Byte[], proofType: Byte }> {
116
+ async revealSpecificKeyLinkage (args: { counterparty: PubKeyHex, verifier: PubKeyHex, protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, privileged?: BooleanDefaultFalse }): Promise<{ prover: PubKeyHex, verifier: PubKeyHex, counterparty: PubKeyHex, protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, encryptedLinkage: Byte[], encryptedLinkageProof: Byte[], proofType: Byte }> {
117
117
  await this.connectToSubstrate()
118
118
  return await (this.substrate as WalletInterface).revealSpecificKeyLinkage(args, this.originator)
119
119
  }
120
120
 
121
- async encrypt(args: { plaintext: Byte[], protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', privileged?: BooleanDefaultFalse }): Promise<{ ciphertext: Byte[] }> {
121
+ async encrypt (args: { plaintext: Byte[], protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', privileged?: BooleanDefaultFalse }): Promise<{ ciphertext: Byte[] }> {
122
122
  await this.connectToSubstrate()
123
123
  return await (this.substrate as WalletInterface).encrypt(args, this.originator)
124
124
  }
125
125
 
126
- async decrypt(args: { ciphertext: Byte[], protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', privileged?: BooleanDefaultFalse }): Promise<{ plaintext: Byte[] }> {
126
+ async decrypt (args: { ciphertext: Byte[], protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', privileged?: BooleanDefaultFalse }): Promise<{ plaintext: Byte[] }> {
127
127
  return await (this.substrate as WalletInterface).decrypt(args, this.originator)
128
128
  }
129
129
 
130
- async createHmac(args: { data: Byte[], protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', privileged?: BooleanDefaultFalse }): Promise<{ hmac: Byte[] }> {
130
+ async createHmac (args: { data: Byte[], protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', privileged?: BooleanDefaultFalse }): Promise<{ hmac: Byte[] }> {
131
131
  await this.connectToSubstrate()
132
132
  return await (this.substrate as WalletInterface).createHmac(args, this.originator)
133
133
  }
134
134
 
135
- async verifyHmac(args: { data: Byte[], hmac: Byte[], protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', privileged?: BooleanDefaultFalse }): Promise<{ valid: true }> {
135
+ async verifyHmac (args: { data: Byte[], hmac: Byte[], protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', privileged?: BooleanDefaultFalse }): Promise<{ valid: true }> {
136
136
  await this.connectToSubstrate()
137
137
  return await (this.substrate as WalletInterface).verifyHmac(args, this.originator)
138
138
  }
139
139
 
140
- async createSignature(args: { data?: Byte[], hashToDirectlySign?: Byte[], protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', privileged?: BooleanDefaultFalse }): Promise<{ signature: Byte[] }> {
140
+ async createSignature (args: { data?: Byte[], hashToDirectlySign?: Byte[], protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', privileged?: BooleanDefaultFalse }): Promise<{ signature: Byte[] }> {
141
141
  await this.connectToSubstrate()
142
142
  return await (this.substrate as WalletInterface).createSignature(args, this.originator)
143
143
  }
144
144
 
145
- async verifySignature(args: { data?: Byte[], hashToDirectlyVerify?: Byte[], signature: Byte[], protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', forSelf?: BooleanDefaultFalse, privileged?: BooleanDefaultFalse }): Promise<{ valid: true }> {
145
+ async verifySignature (args: { data?: Byte[], hashToDirectlyVerify?: Byte[], signature: Byte[], protocolID: [SecurityLevel, ProtocolString5To400Bytes], keyID: KeyIDStringUnder800Bytes, privilegedReason?: DescriptionString5to50Bytes, counterparty?: PubKeyHex | 'self' | 'anyone', forSelf?: BooleanDefaultFalse, privileged?: BooleanDefaultFalse }): Promise<{ valid: true }> {
146
146
  await this.connectToSubstrate()
147
147
  return await (this.substrate as WalletInterface).verifySignature(args, this.originator)
148
148
  }
149
149
 
150
- async acquireCertificate(args: AcquireCertificateArgs): Promise<AcquireCertificateResult> {
150
+ async acquireCertificate (args: AcquireCertificateArgs): Promise<AcquireCertificateResult> {
151
151
  await this.connectToSubstrate()
152
152
  return await (this.substrate as WalletInterface).acquireCertificate(args, this.originator)
153
153
  }
154
154
 
155
- async listCertificates(args: { certifiers: PubKeyHex[], types: Base64String[], limit?: PositiveIntegerDefault10Max10000, offset?: PositiveIntegerOrZero, privileged?: BooleanDefaultFalse, privilegedReason?: DescriptionString5to50Bytes }): Promise<ListCertificatesResult> {
155
+ async listCertificates (args: { certifiers: PubKeyHex[], types: Base64String[], limit?: PositiveIntegerDefault10Max10000, offset?: PositiveIntegerOrZero, privileged?: BooleanDefaultFalse, privilegedReason?: DescriptionString5to50Bytes }): Promise<ListCertificatesResult> {
156
156
  await this.connectToSubstrate()
157
157
  return await (this.substrate as WalletInterface).listCertificates(args, this.originator)
158
158
  }
159
159
 
160
- async proveCertificate(args: ProveCertificateArgs): Promise<ProveCertificateResult> {
160
+ async proveCertificate (args: ProveCertificateArgs): Promise<ProveCertificateResult> {
161
161
  await this.connectToSubstrate()
162
162
  return await (this.substrate as WalletInterface).proveCertificate(args, this.originator)
163
163
  }
164
164
 
165
- async relinquishCertificate(args: { type: Base64String, serialNumber: Base64String, certifier: PubKeyHex }): Promise<{ relinquished: true }> {
165
+ async relinquishCertificate (args: { type: Base64String, serialNumber: Base64String, certifier: PubKeyHex }): Promise<{ relinquished: true }> {
166
166
  await this.connectToSubstrate()
167
167
  return await (this.substrate as WalletInterface).relinquishCertificate(args, this.originator)
168
168
  }
169
169
 
170
- async discoverByIdentityKey(args: { identityKey: PubKeyHex, limit?: PositiveIntegerDefault10Max10000, offset?: PositiveIntegerOrZero }): Promise<DiscoverCertificatesResult> {
170
+ async discoverByIdentityKey (args: { identityKey: PubKeyHex, limit?: PositiveIntegerDefault10Max10000, offset?: PositiveIntegerOrZero }): Promise<DiscoverCertificatesResult> {
171
171
  await this.connectToSubstrate()
172
172
  return await (this.substrate as WalletInterface).discoverByIdentityKey(args, this.originator)
173
173
  }
174
174
 
175
- async discoverByAttributes(args: { attributes: Record<CertificateFieldNameUnder50Bytes, string>, limit?: PositiveIntegerDefault10Max10000, offset?: PositiveIntegerOrZero }): Promise<DiscoverCertificatesResult> {
175
+ async discoverByAttributes (args: { attributes: Record<CertificateFieldNameUnder50Bytes, string>, limit?: PositiveIntegerDefault10Max10000, offset?: PositiveIntegerOrZero }): Promise<DiscoverCertificatesResult> {
176
176
  await this.connectToSubstrate()
177
177
  return await (this.substrate as WalletInterface).discoverByAttributes(args, this.originator)
178
178
  }
179
179
 
180
- async isAuthenticated(args: {} = {}): Promise<AuthenticatedResult> {
180
+ async isAuthenticated (args: {} = {}): Promise<AuthenticatedResult> {
181
181
  await this.connectToSubstrate()
182
182
  return await (this.substrate as WalletInterface).isAuthenticated(args, this.originator)
183
183
  }
184
184
 
185
- async waitForAuthentication(args: {} = {}): Promise<{ authenticated: true }> {
185
+ async waitForAuthentication (args: {} = {}): Promise<{ authenticated: true }> {
186
186
  await this.connectToSubstrate()
187
187
  return await (this.substrate as WalletInterface).waitForAuthentication(args, this.originator)
188
188
  }
189
189
 
190
- async getHeight(args: {} = {}): Promise<{ height: PositiveInteger }> {
190
+ async getHeight (args: {} = {}): Promise<{ height: PositiveInteger }> {
191
191
  await this.connectToSubstrate()
192
192
  return await (this.substrate as WalletInterface).getHeight(args, this.originator)
193
193
  }
194
194
 
195
- async getHeaderForHeight(args: { height: PositiveInteger }): Promise<{ header: HexString }> {
195
+ async getHeaderForHeight (args: { height: PositiveInteger }): Promise<{ header: HexString }> {
196
196
  await this.connectToSubstrate()
197
197
  return await (this.substrate as WalletInterface).getHeaderForHeight(args, this.originator)
198
198
  }
199
199
 
200
- async getNetwork(args: {} = {}): Promise<{ network: 'mainnet' | 'testnet' }> {
200
+ async getNetwork (args: {} = {}): Promise<{ network: 'mainnet' | 'testnet' }> {
201
201
  await this.connectToSubstrate()
202
202
  return await (this.substrate as WalletInterface).getNetwork(args, this.originator)
203
203
  }
204
204
 
205
- async getVersion(args: {} = {}): Promise<{ version: VersionString7To30Bytes }> {
205
+ async getVersion (args: {} = {}): Promise<{ version: VersionString7To30Bytes }> {
206
206
  await this.connectToSubstrate()
207
207
  return await (this.substrate as WalletInterface).getVersion(args, this.originator)
208
208
  }