@alephium/web3 0.5.0-rc.10 → 0.5.0-rc.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.
@@ -1,6 +1,6 @@
1
1
  import { ExplorerProvider, NodeProvider } from '../api';
2
2
  import { node } from '../api';
3
- import { Account, EnableOptionsBase, Destination, SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScriptTxParams, SignExecuteScriptTxResult, SignMessageParams, SignMessageResult, SignTransferTxParams, SignTransferTxResult, SignUnsignedTxParams, SignUnsignedTxResult, SubmissionResult, SubmitTransactionParams, ExtSignTransferTxParams, ExtSignDeployContractTxParams, ExtSignExecuteScriptTxParams, ExtSignUnsignedTxParams, ExtSignMessageParams, KeyType } from './types';
3
+ import { Account, EnableOptionsBase, Destination, SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScriptTxParams, SignExecuteScriptTxResult, SignMessageParams, SignMessageResult, SignTransferTxParams, SignTransferTxResult, SignUnsignedTxParams, SignUnsignedTxResult, SubmissionResult, SubmitTransactionParams, KeyType } from './types';
4
4
  export declare abstract class SignerProvider {
5
5
  abstract get nodeProvider(): NodeProvider | undefined;
6
6
  abstract get explorerProvider(): ExplorerProvider | undefined;
@@ -18,12 +18,6 @@ export declare abstract class InteractiveSignerProvider<EnableOptions extends En
18
18
  protected abstract unsafeEnable(opt?: EnableOptions): Promise<Account>;
19
19
  enable(opt?: EnableOptions): Promise<Account>;
20
20
  abstract disconnect(): Promise<void>;
21
- abstract signAndSubmitTransferTx(params: ExtSignTransferTxParams): Promise<SignTransferTxResult>;
22
- abstract signAndSubmitDeployContractTx(params: ExtSignDeployContractTxParams): Promise<SignDeployContractTxResult>;
23
- abstract signAndSubmitExecuteScriptTx(params: ExtSignExecuteScriptTxParams): Promise<SignExecuteScriptTxResult>;
24
- abstract signAndSubmitUnsignedTx(params: ExtSignUnsignedTxParams): Promise<SignUnsignedTxResult>;
25
- abstract signUnsignedTx(params: ExtSignUnsignedTxParams): Promise<SignUnsignedTxResult>;
26
- abstract signMessage(params: ExtSignMessageParams): Promise<SignMessageResult>;
27
21
  }
28
22
  export declare abstract class SignerProviderSimple extends SignerProvider {
29
23
  abstract get nodeProvider(): NodeProvider;
@@ -58,7 +52,7 @@ export declare abstract class SignerProviderWithCachedAccounts<T extends Account
58
52
  getAccounts(): Promise<T[]>;
59
53
  getAccount(address: string): Promise<T>;
60
54
  }
61
- export declare function verifySignedMessage(message: string, publicKey: string, signature: string, keyType: KeyType): boolean;
55
+ export declare function verifySignedMessage(message: string, publicKey: string, signature: string, keyType?: KeyType): boolean;
62
56
  export declare function toApiDestination(data: Destination): node.Destination;
63
57
  export declare function toApiDestinations(data: Destination[]): node.Destination[];
64
58
  export declare function fromApiDestination(data: node.Destination): Destination;
@@ -38,7 +38,7 @@ class TransactionBuilder {
38
38
  }
39
39
  }
40
40
  async buildTransferTx(params, publicKey) {
41
- TransactionBuilder.validatePublicKey(params, publicKey, params.signerKeyType ?? 'default');
41
+ TransactionBuilder.validatePublicKey(params, publicKey, params.signerKeyType);
42
42
  const { destinations, gasPrice, ...rest } = params;
43
43
  const data = {
44
44
  fromPublicKey: publicKey,
@@ -51,7 +51,7 @@ class TransactionBuilder {
51
51
  return { ...response, gasPrice: (0, api_1.fromApiNumber256)(response.gasPrice) };
52
52
  }
53
53
  async buildDeployContractTx(params, publicKey) {
54
- TransactionBuilder.validatePublicKey(params, publicKey, params.signerKeyType ?? 'default');
54
+ TransactionBuilder.validatePublicKey(params, publicKey, params.signerKeyType);
55
55
  const { initialAttoAlphAmount, initialTokenAmounts, issueTokenAmount, gasPrice, ...rest } = params;
56
56
  const data = {
57
57
  fromPublicKey: publicKey,
@@ -67,7 +67,7 @@ class TransactionBuilder {
67
67
  return { ...response, groupIndex: response.fromGroup, contractId, gasPrice: (0, api_1.fromApiNumber256)(response.gasPrice) };
68
68
  }
69
69
  async buildExecuteScriptTx(params, publicKey) {
70
- TransactionBuilder.validatePublicKey(params, publicKey, params.signerKeyType ?? 'default');
70
+ TransactionBuilder.validatePublicKey(params, publicKey, params.signerKeyType);
71
71
  const { attoAlphAmount, tokens, gasPrice, ...rest } = params;
72
72
  const data = {
73
73
  fromPublicKey: publicKey,
@@ -110,18 +110,3 @@ export interface EnableOptionsBase {
110
110
  networkId: string;
111
111
  onDisconnected: () => Promise<void>;
112
112
  }
113
- export declare type ExtSignTransferTxParams = SignTransferTxParams & {
114
- networkId: string;
115
- };
116
- export declare type ExtSignDeployContractTxParams = SignDeployContractTxParams & {
117
- networkId: string;
118
- };
119
- export declare type ExtSignExecuteScriptTxParams = SignExecuteScriptTxParams & {
120
- networkId: string;
121
- };
122
- export declare type ExtSignUnsignedTxParams = SignUnsignedTxParams & {
123
- networkId: string;
124
- };
125
- export declare type ExtSignMessageParams = SignMessageParams & {
126
- networkId: string;
127
- };
@@ -1,3 +1,3 @@
1
1
  import { KeyType } from '../signer';
2
- export declare function transactionSign(txId: string, privateKey: string, keyType: KeyType): string;
3
- export declare function transactionVerifySignature(txId: string, publicKey: string, signature: string, keyType: KeyType): boolean;
2
+ export declare function transactionSign(txId: string, privateKey: string, keyType?: KeyType): string;
3
+ export declare function transactionVerifySignature(txId: string, publicKey: string, signature: string, keyType?: KeyType): boolean;
@@ -1,3 +1,3 @@
1
1
  import { KeyType } from '../signer';
2
- export declare function sign(hash: string, privateKey: string, _keyType: KeyType): string;
3
- export declare function verifySignature(hash: string, publicKey: string, signature: string, _keyType: KeyType): boolean;
2
+ export declare function sign(hash: string, privateKey: string, _keyType?: KeyType): string;
3
+ export declare function verifySignature(hash: string, publicKey: string, signature: string, _keyType?: KeyType): boolean;
@@ -14,9 +14,9 @@ export declare function contractIdFromAddress(address: string): Uint8Array;
14
14
  export declare function tokenIdFromAddress(address: string): Uint8Array;
15
15
  export declare function hexToBinUnsafe(hex: string): Uint8Array;
16
16
  export declare function binToHex(bin: Uint8Array): string;
17
- export declare function groupOfPrivateKey(privateKey: string, keyType: KeyType): number;
18
- export declare function publicKeyFromPrivateKey(privateKey: string, _keyType: KeyType): string;
19
- export declare function addressFromPublicKey(publicKey: string, _keyType: KeyType): string;
17
+ export declare function groupOfPrivateKey(privateKey: string, keyType?: KeyType): number;
18
+ export declare function publicKeyFromPrivateKey(privateKey: string, _keyType?: KeyType): string;
19
+ export declare function addressFromPublicKey(publicKey: string, _keyType?: KeyType): string;
20
20
  export declare function addressFromContractId(contractId: string): string;
21
21
  export declare function contractIdFromTx(txId: string, outputIndex: number): string;
22
22
  export declare function subContractId(parentContractId: string, pathInHex: string, group: number): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alephium/web3",
3
- "version": "0.5.0-rc.10",
3
+ "version": "0.5.0-rc.11",
4
4
  "description": "A JS/TS library to interact with the Alephium platform",
5
5
  "license": "GPL",
6
6
  "main": "dist/src/index.js",
@@ -38,11 +38,6 @@ import {
38
38
  SignUnsignedTxResult,
39
39
  SubmissionResult,
40
40
  SubmitTransactionParams,
41
- ExtSignTransferTxParams,
42
- ExtSignDeployContractTxParams,
43
- ExtSignExecuteScriptTxParams,
44
- ExtSignUnsignedTxParams,
45
- ExtSignMessageParams,
46
41
  KeyType
47
42
  } from './types'
48
43
  import { TransactionBuilder } from './tx-builder'
@@ -90,18 +85,6 @@ export abstract class InteractiveSignerProvider<
90
85
  }
91
86
 
92
87
  abstract disconnect(): Promise<void>
93
-
94
- // Methods inherited from SignerProvider, but require networkId in the params
95
- abstract override signAndSubmitTransferTx(params: ExtSignTransferTxParams): Promise<SignTransferTxResult>
96
- abstract override signAndSubmitDeployContractTx(
97
- params: ExtSignDeployContractTxParams
98
- ): Promise<SignDeployContractTxResult>
99
- abstract override signAndSubmitExecuteScriptTx(
100
- params: ExtSignExecuteScriptTxParams
101
- ): Promise<SignExecuteScriptTxResult>
102
- abstract override signAndSubmitUnsignedTx(params: ExtSignUnsignedTxParams): Promise<SignUnsignedTxResult>
103
- abstract override signUnsignedTx(params: ExtSignUnsignedTxParams): Promise<SignUnsignedTxResult>
104
- abstract override signMessage(params: ExtSignMessageParams): Promise<SignMessageResult>
105
88
  }
106
89
 
107
90
  export abstract class SignerProviderSimple extends SignerProvider {
@@ -263,7 +246,7 @@ function extendMessage(message: string): string {
263
246
  return 'Alephium Signed Message: ' + message
264
247
  }
265
248
 
266
- export function verifySignedMessage(message: string, publicKey: string, signature: string, keyType: KeyType): boolean {
249
+ export function verifySignedMessage(message: string, publicKey: string, signature: string, keyType?: KeyType): boolean {
267
250
  const extendedMessage = extendMessage(message)
268
251
  const messageHash = blake.blake2b(extendedMessage, undefined, 32)
269
252
  return utils.verifySignature(utils.binToHex(messageHash), publicKey, signature, keyType)
@@ -47,7 +47,7 @@ export abstract class TransactionBuilder {
47
47
  })()
48
48
  }
49
49
 
50
- private static validatePublicKey(params: SignerAddress, publicKey: string, keyType: KeyType) {
50
+ private static validatePublicKey(params: SignerAddress, publicKey: string, keyType?: KeyType) {
51
51
  const address = addressFromPublicKey(publicKey, keyType)
52
52
  if (address !== params.signerAddress) {
53
53
  throw new Error('Unmatched public key')
@@ -58,7 +58,7 @@ export abstract class TransactionBuilder {
58
58
  params: SignTransferTxParams,
59
59
  publicKey: string
60
60
  ): Promise<Omit<SignTransferTxResult, 'signature'>> {
61
- TransactionBuilder.validatePublicKey(params, publicKey, params.signerKeyType ?? 'default')
61
+ TransactionBuilder.validatePublicKey(params, publicKey, params.signerKeyType)
62
62
 
63
63
  const { destinations, gasPrice, ...rest } = params
64
64
  const data: node.BuildTransaction = {
@@ -76,7 +76,7 @@ export abstract class TransactionBuilder {
76
76
  params: SignDeployContractTxParams,
77
77
  publicKey: string
78
78
  ): Promise<Omit<SignDeployContractTxResult, 'signature'>> {
79
- TransactionBuilder.validatePublicKey(params, publicKey, params.signerKeyType ?? 'default')
79
+ TransactionBuilder.validatePublicKey(params, publicKey, params.signerKeyType)
80
80
 
81
81
  const { initialAttoAlphAmount, initialTokenAmounts, issueTokenAmount, gasPrice, ...rest } = params
82
82
  const data: node.BuildDeployContractTx = {
@@ -97,7 +97,7 @@ export abstract class TransactionBuilder {
97
97
  params: SignExecuteScriptTxParams,
98
98
  publicKey: string
99
99
  ): Promise<Omit<SignExecuteScriptTxResult, 'signature'>> {
100
- TransactionBuilder.validatePublicKey(params, publicKey, params.signerKeyType ?? 'default')
100
+ TransactionBuilder.validatePublicKey(params, publicKey, params.signerKeyType)
101
101
 
102
102
  const { attoAlphAmount, tokens, gasPrice, ...rest } = params
103
103
  const data: node.BuildExecuteScriptTx = {
@@ -162,10 +162,3 @@ export interface EnableOptionsBase {
162
162
  networkId: string
163
163
  onDisconnected: () => Promise<void>
164
164
  }
165
-
166
- // Transaction Params for InteractiveSignerProvider
167
- export type ExtSignTransferTxParams = SignTransferTxParams & { networkId: string }
168
- export type ExtSignDeployContractTxParams = SignDeployContractTxParams & { networkId: string }
169
- export type ExtSignExecuteScriptTxParams = SignExecuteScriptTxParams & { networkId: string }
170
- export type ExtSignUnsignedTxParams = SignUnsignedTxParams & { networkId: string }
171
- export type ExtSignMessageParams = SignMessageParams & { networkId: string }
@@ -19,7 +19,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
19
19
  import * as utils from '../utils'
20
20
  import { KeyType } from '../signer'
21
21
 
22
- export function transactionSign(txId: string, privateKey: string, keyType: KeyType): string {
22
+ export function transactionSign(txId: string, privateKey: string, keyType?: KeyType): string {
23
23
  return utils.sign(txId, privateKey, keyType)
24
24
  }
25
25
 
@@ -27,7 +27,7 @@ export function transactionVerifySignature(
27
27
  txId: string,
28
28
  publicKey: string,
29
29
  signature: string,
30
- keyType: KeyType
30
+ keyType?: KeyType
31
31
  ): boolean {
32
32
  return utils.verifySignature(txId, publicKey, signature, keyType)
33
33
  }
package/src/utils/sign.ts CHANGED
@@ -37,7 +37,7 @@ necc.utils.hmacSha256Sync = (key: Uint8Array, ...messages: Uint8Array[]): Uint8A
37
37
  }
38
38
 
39
39
  // hash has to be 32 bytes
40
- export function sign(hash: string, privateKey: string, _keyType: KeyType): string {
40
+ export function sign(hash: string, privateKey: string, _keyType?: KeyType): string {
41
41
  const keyType = _keyType ?? 'default'
42
42
 
43
43
  if (keyType === 'default') {
@@ -50,7 +50,7 @@ export function sign(hash: string, privateKey: string, _keyType: KeyType): strin
50
50
  }
51
51
  }
52
52
 
53
- export function verifySignature(hash: string, publicKey: string, signature: string, _keyType: KeyType): boolean {
53
+ export function verifySignature(hash: string, publicKey: string, signature: string, _keyType?: KeyType): boolean {
54
54
  const keyType = _keyType ?? 'default'
55
55
 
56
56
  try {
@@ -158,11 +158,11 @@ export function binToHex(bin: Uint8Array): string {
158
158
  return Buffer.from(bin).toString('hex')
159
159
  }
160
160
 
161
- export function groupOfPrivateKey(privateKey: string, keyType: KeyType): number {
161
+ export function groupOfPrivateKey(privateKey: string, keyType?: KeyType): number {
162
162
  return groupOfAddress(addressFromPublicKey(publicKeyFromPrivateKey(privateKey, keyType), keyType))
163
163
  }
164
164
 
165
- export function publicKeyFromPrivateKey(privateKey: string, _keyType: KeyType): string {
165
+ export function publicKeyFromPrivateKey(privateKey: string, _keyType?: KeyType): string {
166
166
  const keyType = _keyType ?? 'default'
167
167
 
168
168
  if (keyType === 'default') {
@@ -173,7 +173,7 @@ export function publicKeyFromPrivateKey(privateKey: string, _keyType: KeyType):
173
173
  }
174
174
  }
175
175
 
176
- export function addressFromPublicKey(publicKey: string, _keyType: KeyType): string {
176
+ export function addressFromPublicKey(publicKey: string, _keyType?: KeyType): string {
177
177
  const keyType = _keyType ?? 'default'
178
178
 
179
179
  if (keyType === 'default') {