@midnight-ntwrk/wallet-sdk-address-format 2.0.0 → 3.0.0-beta.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.
- package/dist/index.d.ts +66 -16
- package/dist/index.js +149 -55
- package/package.json +28 -18
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,35 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DustPublicKey, EncryptionSecretKey, UserAddress } from '@midnight-ntwrk/ledger-v7';
|
|
2
|
+
export declare const mainnet: unique symbol;
|
|
3
|
+
export type NetworkId = string | typeof mainnet;
|
|
2
4
|
export type FormatContext = {
|
|
3
|
-
networkId:
|
|
5
|
+
networkId: NetworkId;
|
|
4
6
|
};
|
|
7
|
+
export type Field = {
|
|
8
|
+
bytes: number;
|
|
9
|
+
modulus: bigint;
|
|
10
|
+
};
|
|
11
|
+
export declare const BLSScalar: Field;
|
|
12
|
+
export declare const ScaleBigInt: {
|
|
13
|
+
encode: (data: bigint) => Buffer;
|
|
14
|
+
decode: (repr: Uint8Array) => bigint;
|
|
15
|
+
};
|
|
16
|
+
export declare const Bech32mSymbol: unique symbol;
|
|
17
|
+
export type HasCodec<T> = {
|
|
18
|
+
[Bech32mSymbol]: Bech32mCodec<T>;
|
|
19
|
+
};
|
|
20
|
+
export type CodecTarget<T> = T extends HasCodec<infer U> ? U : never;
|
|
5
21
|
export declare class MidnightBech32m {
|
|
6
|
-
readonly type: string;
|
|
7
|
-
readonly network: string | null;
|
|
8
|
-
readonly data: Buffer;
|
|
9
22
|
static readonly prefix = "mn";
|
|
23
|
+
static encode<T extends HasCodec<T>>(networkId: NetworkId, item: T): MidnightBech32m;
|
|
10
24
|
static validateSegment(segmentName: string, segment: string): void;
|
|
11
25
|
static parse(bech32string: string): MidnightBech32m;
|
|
12
|
-
|
|
26
|
+
readonly type: string;
|
|
27
|
+
readonly network: NetworkId;
|
|
28
|
+
readonly data: Buffer;
|
|
29
|
+
constructor(type: string, network: NetworkId, data: Buffer);
|
|
30
|
+
decode<TClass extends HasCodec<any>>(tclass: TClass, networkId: NetworkId): CodecTarget<TClass>;
|
|
13
31
|
asString(): string;
|
|
32
|
+
toString(): string;
|
|
14
33
|
}
|
|
15
34
|
export declare class Bech32mCodec<T> {
|
|
16
35
|
readonly type: string;
|
|
@@ -18,33 +37,64 @@ export declare class Bech32mCodec<T> {
|
|
|
18
37
|
readonly dataFromBytes: (bytes: Buffer) => T;
|
|
19
38
|
constructor(type: string, dataToBytes: (data: T) => Buffer, dataFromBytes: (bytes: Buffer) => T);
|
|
20
39
|
encode(networkId: NetworkId, data: T): MidnightBech32m;
|
|
21
|
-
decode(networkId: NetworkId
|
|
22
|
-
static createContext(networkId: NetworkId
|
|
23
|
-
static createContextFromZswap(networkId: NetworkId): FormatContext;
|
|
40
|
+
decode(networkId: NetworkId, repr: MidnightBech32m): T;
|
|
41
|
+
static createContext(networkId: NetworkId): FormatContext;
|
|
24
42
|
}
|
|
25
43
|
export declare class ShieldedAddress {
|
|
44
|
+
static readonly codec: Bech32mCodec<ShieldedAddress>;
|
|
45
|
+
static readonly [Bech32mSymbol]: Bech32mCodec<ShieldedAddress>;
|
|
46
|
+
readonly [Bech32mSymbol]: Bech32mCodec<ShieldedAddress>;
|
|
26
47
|
readonly coinPublicKey: ShieldedCoinPublicKey;
|
|
27
48
|
readonly encryptionPublicKey: ShieldedEncryptionPublicKey;
|
|
28
|
-
static codec: Bech32mCodec<ShieldedAddress>;
|
|
29
49
|
constructor(coinPublicKey: ShieldedCoinPublicKey, encryptionPublicKey: ShieldedEncryptionPublicKey);
|
|
30
50
|
coinPublicKeyString(): string;
|
|
31
51
|
encryptionPublicKeyString(): string;
|
|
52
|
+
equals(other: ShieldedAddress): boolean;
|
|
32
53
|
}
|
|
33
54
|
export declare class ShieldedEncryptionSecretKey {
|
|
55
|
+
static readonly codec: Bech32mCodec<ShieldedEncryptionSecretKey>;
|
|
34
56
|
readonly zswap: EncryptionSecretKey;
|
|
35
|
-
static codec: Bech32mCodec<ShieldedEncryptionSecretKey>;
|
|
36
57
|
constructor(zswap: EncryptionSecretKey);
|
|
37
58
|
}
|
|
38
59
|
export declare class ShieldedCoinPublicKey {
|
|
60
|
+
static readonly keyLength = 32;
|
|
61
|
+
static readonly codec: Bech32mCodec<ShieldedCoinPublicKey>;
|
|
62
|
+
static fromHexString(hexString: string): ShieldedCoinPublicKey;
|
|
39
63
|
readonly data: Buffer;
|
|
40
|
-
static readonly key_length = 32;
|
|
41
|
-
static codec: Bech32mCodec<ShieldedCoinPublicKey>;
|
|
42
64
|
constructor(data: Buffer);
|
|
65
|
+
toHexString(): string;
|
|
66
|
+
equals(other: string): boolean;
|
|
67
|
+
equals(other: ShieldedCoinPublicKey): boolean;
|
|
43
68
|
}
|
|
44
69
|
export declare class ShieldedEncryptionPublicKey {
|
|
70
|
+
static readonly keyLength = 32;
|
|
71
|
+
static readonly codec: Bech32mCodec<ShieldedEncryptionPublicKey>;
|
|
72
|
+
static fromHexString(hexString: string): ShieldedEncryptionPublicKey;
|
|
45
73
|
readonly data: Buffer;
|
|
46
|
-
static readonly key_length = 32;
|
|
47
|
-
static codec: Bech32mCodec<ShieldedEncryptionPublicKey>;
|
|
48
74
|
constructor(data: Buffer);
|
|
75
|
+
toHexString(): string;
|
|
76
|
+
equals(other: string): boolean;
|
|
77
|
+
equals(other: ShieldedEncryptionPublicKey): boolean;
|
|
78
|
+
}
|
|
79
|
+
export declare class UnshieldedAddress {
|
|
80
|
+
readonly data: Buffer;
|
|
81
|
+
static readonly keyLength = 32;
|
|
82
|
+
static readonly codec: Bech32mCodec<UnshieldedAddress>;
|
|
83
|
+
static readonly [Bech32mSymbol]: Bech32mCodec<UnshieldedAddress>;
|
|
84
|
+
readonly [Bech32mSymbol]: Bech32mCodec<UnshieldedAddress>;
|
|
85
|
+
constructor(data: Buffer);
|
|
86
|
+
get hexString(): UserAddress;
|
|
87
|
+
equals(other: string): boolean;
|
|
88
|
+
equals(other: UnshieldedAddress): boolean;
|
|
89
|
+
}
|
|
90
|
+
export declare class DustAddress {
|
|
91
|
+
readonly data: bigint;
|
|
92
|
+
static readonly codec: Bech32mCodec<DustAddress>;
|
|
93
|
+
static readonly [Bech32mSymbol]: Bech32mCodec<DustAddress>;
|
|
94
|
+
readonly [Bech32mSymbol]: Bech32mCodec<DustAddress>;
|
|
95
|
+
static readonly encodePublicKey: (networkId: string, publicKey: DustPublicKey) => string;
|
|
96
|
+
constructor(data: bigint);
|
|
97
|
+
serialize(): Buffer;
|
|
98
|
+
equals(other: bigint): boolean;
|
|
99
|
+
equals(other: DustAddress): boolean;
|
|
49
100
|
}
|
|
50
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,47 @@
|
|
|
1
|
-
|
|
1
|
+
// This file is part of MIDNIGHT-WALLET-SDK.
|
|
2
|
+
// Copyright (C) 2025 Midnight Foundation
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// You may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { EncryptionSecretKey } from '@midnight-ntwrk/ledger-v7';
|
|
2
14
|
import { bech32m } from '@scure/base';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
15
|
+
import * as subsquidScale from '@subsquid/scale-codec';
|
|
16
|
+
export const mainnet = Symbol('Mainnet');
|
|
17
|
+
const NetworkId = {
|
|
18
|
+
toString: (networkId) => {
|
|
19
|
+
return networkId === mainnet ? 'mainnet' : networkId;
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
export const BLSScalar = {
|
|
23
|
+
bytes: 32,
|
|
24
|
+
modulus: BigInt('0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001'),
|
|
25
|
+
};
|
|
26
|
+
export const ScaleBigInt = {
|
|
27
|
+
encode: (data) => {
|
|
28
|
+
const sink = new subsquidScale.ByteSink();
|
|
29
|
+
sink.compact(data);
|
|
30
|
+
return Buffer.from(sink.toBytes());
|
|
31
|
+
},
|
|
32
|
+
decode: (repr) => {
|
|
33
|
+
const src = new subsquidScale.Src(repr);
|
|
34
|
+
const res = src.compact();
|
|
35
|
+
src.assertEOF();
|
|
36
|
+
return BigInt(res);
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
export const Bech32mSymbol = Symbol('MidnightBech32m');
|
|
40
|
+
export class MidnightBech32m {
|
|
8
41
|
static prefix = 'mn';
|
|
42
|
+
static encode(networkId, item) {
|
|
43
|
+
return item[Bech32mSymbol].encode(networkId, item);
|
|
44
|
+
}
|
|
9
45
|
static validateSegment(segmentName, segment) {
|
|
10
46
|
const result = /^[A-Za-z1-9-]+$/.test(segment);
|
|
11
47
|
if (!result) {
|
|
@@ -14,38 +50,49 @@ class MidnightBech32m {
|
|
|
14
50
|
}
|
|
15
51
|
static parse(bech32string) {
|
|
16
52
|
const bech32parsed = bech32m.decodeToBytes(bech32string);
|
|
17
|
-
const [prefix, type, network =
|
|
53
|
+
const [prefix, type, network = mainnet] = bech32parsed.prefix.split('_');
|
|
18
54
|
if (prefix != MidnightBech32m.prefix) {
|
|
19
55
|
throw new Error(`Expected prefix ${MidnightBech32m.prefix}`);
|
|
20
56
|
}
|
|
21
57
|
MidnightBech32m.validateSegment('type', type);
|
|
22
|
-
if (network !=
|
|
58
|
+
if (network != mainnet) {
|
|
23
59
|
MidnightBech32m.validateSegment('network', network);
|
|
24
60
|
}
|
|
25
61
|
return new MidnightBech32m(type, network, Buffer.from(bech32parsed.bytes));
|
|
26
62
|
}
|
|
63
|
+
type;
|
|
64
|
+
network;
|
|
65
|
+
data;
|
|
27
66
|
constructor(type, network, data) {
|
|
28
|
-
this.type = type;
|
|
29
|
-
this.network = network;
|
|
30
67
|
this.data = data;
|
|
68
|
+
this.network = network;
|
|
69
|
+
this.type = type;
|
|
31
70
|
MidnightBech32m.validateSegment('type', type);
|
|
32
|
-
if (network !=
|
|
71
|
+
if (network != mainnet) {
|
|
33
72
|
MidnightBech32m.validateSegment('network', network);
|
|
34
73
|
}
|
|
35
74
|
}
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
76
|
+
decode(tclass, networkId) {
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
78
|
+
return tclass[Bech32mSymbol].decode(networkId, this);
|
|
79
|
+
}
|
|
36
80
|
asString() {
|
|
37
|
-
const networkSegment = this.network ==
|
|
81
|
+
const networkSegment = this.network == mainnet ? '' : `_${this.network}`;
|
|
38
82
|
return bech32m.encode(`${MidnightBech32m.prefix}_${this.type}${networkSegment}`, bech32m.toWords(this.data), false);
|
|
39
83
|
}
|
|
84
|
+
toString() {
|
|
85
|
+
return this.asString();
|
|
86
|
+
}
|
|
40
87
|
}
|
|
41
|
-
class Bech32mCodec {
|
|
88
|
+
export class Bech32mCodec {
|
|
42
89
|
type;
|
|
43
90
|
dataToBytes;
|
|
44
91
|
dataFromBytes;
|
|
45
92
|
constructor(type, dataToBytes, dataFromBytes) {
|
|
46
|
-
this.type = type;
|
|
47
|
-
this.dataToBytes = dataToBytes;
|
|
48
93
|
this.dataFromBytes = dataFromBytes;
|
|
94
|
+
this.dataToBytes = dataToBytes;
|
|
95
|
+
this.type = type;
|
|
49
96
|
}
|
|
50
97
|
encode(networkId, data) {
|
|
51
98
|
const context = Bech32mCodec.createContext(networkId);
|
|
@@ -57,47 +104,32 @@ class Bech32mCodec {
|
|
|
57
104
|
throw new Error(`Expected type ${this.type}, got ${repr.type}`);
|
|
58
105
|
}
|
|
59
106
|
if (context.networkId != repr.network) {
|
|
60
|
-
throw new Error(`Expected ${context.networkId
|
|
107
|
+
throw new Error(`Expected ${NetworkId.toString(context.networkId)} address, got ${NetworkId.toString(repr.network)} one`);
|
|
61
108
|
}
|
|
62
109
|
return this.dataFromBytes(repr.data);
|
|
63
110
|
}
|
|
64
111
|
static createContext(networkId) {
|
|
65
|
-
if (networkId ===
|
|
66
|
-
return { networkId:
|
|
67
|
-
}
|
|
68
|
-
else if (typeof networkId === 'string') {
|
|
69
|
-
return { networkId };
|
|
112
|
+
if (networkId === 'mainnet') {
|
|
113
|
+
return { networkId: mainnet };
|
|
70
114
|
}
|
|
71
115
|
else {
|
|
72
|
-
return
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
static createContextFromZswap(networkId) {
|
|
76
|
-
switch (networkId) {
|
|
77
|
-
case NetworkId.DevNet:
|
|
78
|
-
return { networkId: 'dev' };
|
|
79
|
-
case NetworkId.MainNet:
|
|
80
|
-
return { networkId: null };
|
|
81
|
-
case NetworkId.TestNet:
|
|
82
|
-
return { networkId: 'test' };
|
|
83
|
-
case NetworkId.Undeployed:
|
|
84
|
-
return { networkId: 'undeployed' };
|
|
85
|
-
default:
|
|
86
|
-
return { networkId: null };
|
|
116
|
+
return { networkId };
|
|
87
117
|
}
|
|
88
118
|
}
|
|
89
119
|
}
|
|
90
|
-
class ShieldedAddress {
|
|
91
|
-
coinPublicKey;
|
|
92
|
-
encryptionPublicKey;
|
|
120
|
+
export class ShieldedAddress {
|
|
93
121
|
static codec = new Bech32mCodec('shield-addr', (addr) => Buffer.concat([addr.coinPublicKey.data, addr.encryptionPublicKey.data]), (bytes) => {
|
|
94
|
-
const coinPublicKey = new ShieldedCoinPublicKey(bytes.subarray(0, ShieldedCoinPublicKey.
|
|
95
|
-
const encryptionPublicKey = new ShieldedEncryptionPublicKey(bytes.subarray(ShieldedCoinPublicKey.
|
|
122
|
+
const coinPublicKey = new ShieldedCoinPublicKey(bytes.subarray(0, ShieldedCoinPublicKey.keyLength));
|
|
123
|
+
const encryptionPublicKey = new ShieldedEncryptionPublicKey(bytes.subarray(ShieldedCoinPublicKey.keyLength));
|
|
96
124
|
return new ShieldedAddress(coinPublicKey, encryptionPublicKey);
|
|
97
125
|
});
|
|
126
|
+
static [Bech32mSymbol] = ShieldedAddress.codec;
|
|
127
|
+
[Bech32mSymbol] = ShieldedAddress.codec;
|
|
128
|
+
coinPublicKey;
|
|
129
|
+
encryptionPublicKey;
|
|
98
130
|
constructor(coinPublicKey, encryptionPublicKey) {
|
|
99
|
-
this.coinPublicKey = coinPublicKey;
|
|
100
131
|
this.encryptionPublicKey = encryptionPublicKey;
|
|
132
|
+
this.coinPublicKey = coinPublicKey;
|
|
101
133
|
}
|
|
102
134
|
coinPublicKeyString() {
|
|
103
135
|
return this.coinPublicKey.data.toString('hex');
|
|
@@ -105,35 +137,97 @@ class ShieldedAddress {
|
|
|
105
137
|
encryptionPublicKeyString() {
|
|
106
138
|
return this.encryptionPublicKey.data.toString('hex');
|
|
107
139
|
}
|
|
140
|
+
equals(other) {
|
|
141
|
+
return this.coinPublicKey.equals(other.coinPublicKey) && this.encryptionPublicKey.equals(other.encryptionPublicKey);
|
|
142
|
+
}
|
|
108
143
|
}
|
|
109
|
-
class ShieldedEncryptionSecretKey {
|
|
110
|
-
zswap;
|
|
111
|
-
static codec = new Bech32mCodec('shield-esk', (esk) => Buffer.from(esk.zswap.yesIKnowTheSecurityImplicationsOfThis_serialize(NetworkId.Undeployed).subarray(1)), (repr) => new ShieldedEncryptionSecretKey(EncryptionSecretKey.deserialize(Buffer.concat([Buffer.of(0), repr]), NetworkId.Undeployed)));
|
|
144
|
+
export class ShieldedEncryptionSecretKey {
|
|
145
|
+
static codec = new Bech32mCodec('shield-esk', (esk) => Buffer.from(esk.zswap.yesIKnowTheSecurityImplicationsOfThis_serialize()), (repr) => new ShieldedEncryptionSecretKey(EncryptionSecretKey.deserialize(repr)));
|
|
112
146
|
// There are some bits in serialization of field elements and elliptic curve points, that are hard to replicate
|
|
113
147
|
// Thus using zswap implementation directly for serialization purposes
|
|
148
|
+
zswap;
|
|
114
149
|
constructor(zswap) {
|
|
115
150
|
this.zswap = zswap;
|
|
116
151
|
}
|
|
117
152
|
}
|
|
118
|
-
class ShieldedCoinPublicKey {
|
|
119
|
-
|
|
120
|
-
static key_length = 32;
|
|
153
|
+
export class ShieldedCoinPublicKey {
|
|
154
|
+
static keyLength = 32;
|
|
121
155
|
static codec = new Bech32mCodec('shield-cpk', (cpk) => cpk.data, (repr) => new ShieldedCoinPublicKey(repr));
|
|
156
|
+
static fromHexString(hexString) {
|
|
157
|
+
return new ShieldedCoinPublicKey(Buffer.from(hexString, 'hex'));
|
|
158
|
+
}
|
|
159
|
+
data;
|
|
122
160
|
constructor(data) {
|
|
123
161
|
this.data = data;
|
|
124
|
-
if (data.length != ShieldedCoinPublicKey.
|
|
162
|
+
if (data.length != ShieldedCoinPublicKey.keyLength) {
|
|
125
163
|
throw new Error('Coin public key needs to be 32 bytes long');
|
|
126
164
|
}
|
|
127
165
|
}
|
|
166
|
+
toHexString() {
|
|
167
|
+
return this.data.toString('hex');
|
|
168
|
+
}
|
|
169
|
+
equals(other) {
|
|
170
|
+
const otherKey = typeof other === 'string' ? ShieldedCoinPublicKey.fromHexString(other) : other;
|
|
171
|
+
return otherKey.data.equals(this.data);
|
|
172
|
+
}
|
|
128
173
|
}
|
|
129
|
-
class ShieldedEncryptionPublicKey {
|
|
130
|
-
|
|
131
|
-
static key_length = 32;
|
|
174
|
+
export class ShieldedEncryptionPublicKey {
|
|
175
|
+
static keyLength = 32;
|
|
132
176
|
static codec = new Bech32mCodec('shield-epk', (cpk) => cpk.data, (repr) => new ShieldedEncryptionPublicKey(repr));
|
|
177
|
+
static fromHexString(hexString) {
|
|
178
|
+
return new ShieldedEncryptionPublicKey(Buffer.from(hexString, 'hex'));
|
|
179
|
+
}
|
|
180
|
+
data;
|
|
181
|
+
constructor(data) {
|
|
182
|
+
this.data = data;
|
|
183
|
+
}
|
|
184
|
+
toHexString() {
|
|
185
|
+
return this.data.toString('hex');
|
|
186
|
+
}
|
|
187
|
+
equals(other) {
|
|
188
|
+
const otherKey = typeof other === 'string' ? ShieldedEncryptionPublicKey.fromHexString(other) : other;
|
|
189
|
+
return otherKey.data.equals(this.data);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
export class UnshieldedAddress {
|
|
193
|
+
data;
|
|
194
|
+
static keyLength = 32;
|
|
195
|
+
static codec = new Bech32mCodec('addr', (addr) => addr.data, (repr) => new UnshieldedAddress(repr));
|
|
196
|
+
static [Bech32mSymbol] = UnshieldedAddress.codec;
|
|
197
|
+
[Bech32mSymbol] = UnshieldedAddress.codec;
|
|
198
|
+
constructor(data) {
|
|
199
|
+
if (data.length != UnshieldedAddress.keyLength) {
|
|
200
|
+
throw new Error('Unshielded address needs to be 32 bytes long');
|
|
201
|
+
}
|
|
202
|
+
this.data = data;
|
|
203
|
+
}
|
|
204
|
+
get hexString() {
|
|
205
|
+
return this.data.toString('hex');
|
|
206
|
+
}
|
|
207
|
+
equals(other) {
|
|
208
|
+
const otherAddress = typeof other === 'string' ? new UnshieldedAddress(Buffer.from(other, 'hex')) : other;
|
|
209
|
+
return otherAddress.data.equals(this.data);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
export class DustAddress {
|
|
213
|
+
data;
|
|
214
|
+
static codec = new Bech32mCodec('dust', (daddr) => daddr.serialize(), (repr) => new DustAddress(ScaleBigInt.decode(repr)));
|
|
215
|
+
static [Bech32mSymbol] = DustAddress.codec;
|
|
216
|
+
[Bech32mSymbol] = DustAddress.codec;
|
|
217
|
+
static encodePublicKey = (networkId, publicKey) => {
|
|
218
|
+
return DustAddress.codec.encode(networkId, new DustAddress(publicKey)).asString();
|
|
219
|
+
};
|
|
133
220
|
constructor(data) {
|
|
221
|
+
if (data >= BLSScalar.modulus) {
|
|
222
|
+
throw new Error('Dust address is too large');
|
|
223
|
+
}
|
|
134
224
|
this.data = data;
|
|
135
225
|
}
|
|
226
|
+
serialize() {
|
|
227
|
+
return ScaleBigInt.encode(this.data);
|
|
228
|
+
}
|
|
229
|
+
equals(other) {
|
|
230
|
+
const otherAddress = typeof other === 'bigint' ? other : other.data;
|
|
231
|
+
return otherAddress === this.data;
|
|
232
|
+
}
|
|
136
233
|
}
|
|
137
|
-
|
|
138
|
-
export { Bech32mCodec, MidnightBech32m, ShieldedAddress, ShieldedCoinPublicKey, ShieldedEncryptionPublicKey, ShieldedEncryptionSecretKey };
|
|
139
|
-
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,41 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midnight-ntwrk/wallet-sdk-address-format",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-beta.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
6
7
|
"types": "./dist/index.d.ts",
|
|
7
|
-
"author": "
|
|
8
|
+
"author": "Midnight Foundation",
|
|
8
9
|
"license": "Apache-2.0",
|
|
9
10
|
"publishConfig": {
|
|
10
11
|
"registry": "https://npm.pkg.github.com/"
|
|
11
12
|
},
|
|
12
|
-
"repository": {
|
|
13
|
-
"type": "git",
|
|
14
|
-
"url": "https://github.com/midnight-ntwrk/artifacts.git"
|
|
15
|
-
},
|
|
16
13
|
"files": [
|
|
17
14
|
"dist/"
|
|
18
15
|
],
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/midnight-ntwrk/artifacts.git"
|
|
19
|
+
},
|
|
19
20
|
"exports": {
|
|
20
21
|
".": {
|
|
21
|
-
"
|
|
22
|
-
"
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js"
|
|
23
24
|
}
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
|
-
"@
|
|
27
|
+
"@midnight-ntwrk/ledger-v7": "7.0.0-rc.1",
|
|
28
|
+
"@scure/base": "^1.2.6",
|
|
29
|
+
"@subsquid/scale-codec": "^4.0.1"
|
|
27
30
|
},
|
|
28
31
|
"devDependencies": {
|
|
29
|
-
"@
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
32
|
+
"@types/node": "22.17.0",
|
|
33
|
+
"eslint": "^9.37.0",
|
|
34
|
+
"prettier": "^3.7.0",
|
|
35
|
+
"publint": "~0.3.14",
|
|
36
|
+
"rimraf": "^6.0.1",
|
|
37
|
+
"typescript": "^5.9.3",
|
|
38
|
+
"vitest": "^4.0.16"
|
|
34
39
|
},
|
|
35
40
|
"scripts": {
|
|
36
41
|
"typecheck": "tsc -b ./tsconfig.json --noEmit",
|
|
37
|
-
"test": "
|
|
38
|
-
"lint": "eslint",
|
|
39
|
-
"
|
|
42
|
+
"test": "vitest run",
|
|
43
|
+
"lint": "eslint --max-warnings 0",
|
|
44
|
+
"format": "prettier --write \"**/*.{ts,js,json,yaml,yml,md}\"",
|
|
45
|
+
"format:check": "prettier --check \"**/*.{ts,js,json,yaml,yml,md}\"",
|
|
46
|
+
"dist": "tsc -b ./tsconfig.build.json",
|
|
47
|
+
"dist:publish": "tsc -b ./tsconfig.publish.json",
|
|
48
|
+
"clean": "rimraf --glob dist 'tsconfig.*.tsbuildinfo' && date +%s > .clean-timestamp",
|
|
49
|
+
"publint": "publint --strict"
|
|
40
50
|
}
|
|
41
|
-
}
|
|
51
|
+
}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAGvE,MAAM,MAAM,aAAa,GAAG;IAC1B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