42 lines
1.2 KiB
Dart
42 lines
1.2 KiB
Dart
|
|
import 'package:swarm/swarm.dart';
|
||
|
|
import 'package:test/test.dart';
|
||
|
|
|
||
|
|
void main() {
|
||
|
|
group('NIP-19 encoding', () {
|
||
|
|
// Canonical test vectors from the NIP-19 specification.
|
||
|
|
test('encodeNpub matches the spec vector', () {
|
||
|
|
expect(
|
||
|
|
encodeNpub(
|
||
|
|
'7e7e9c42a91bfef19fa929e5fda1b72e0ebc1a4c1141673e2794234d86addf4e',
|
||
|
|
),
|
||
|
|
equals(
|
||
|
|
'npub10elfcs4fr0l0r8af98jlmgdh9c8tcxjvz9qkw038js35mp4dma8qzvjptg',
|
||
|
|
),
|
||
|
|
);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('encodeNsec matches the spec vector', () {
|
||
|
|
expect(
|
||
|
|
encodeNsec(
|
||
|
|
'67dea2ed018072d675f5415ecfaed7d2597555e202d85b3d65ea4e58d2d92ffa',
|
||
|
|
),
|
||
|
|
equals(
|
||
|
|
'nsec1vl029mgpspedva04g90vltkh6fvh240zqtv9k0t9af8935ke9laqsnlfe5',
|
||
|
|
),
|
||
|
|
);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('npub/nsec carry the right human-readable prefix', () {
|
||
|
|
const hex =
|
||
|
|
'0000000000000000000000000000000000000000000000000000000000000001';
|
||
|
|
expect(encodeNpub(hex), startsWith('npub1'));
|
||
|
|
expect(encodeNsec(hex), startsWith('nsec1'));
|
||
|
|
});
|
||
|
|
|
||
|
|
test('rejects wrong-length hex', () {
|
||
|
|
expect(() => encodeNpub('abcd'), throwsArgumentError);
|
||
|
|
expect(() => encodeNsec(''), throwsArgumentError);
|
||
|
|
});
|
||
|
|
});
|
||
|
|
}
|