@alephium/web3 0.3.0-rc.1 → 0.3.0-rc.4
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/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/transaction/index.d.ts +1 -0
- package/dist/src/transaction/index.js +1 -0
- package/dist/src/transaction/sign-verify.d.ts +2 -0
- package/dist/src/transaction/sign-verify.js +62 -0
- package/package.json +1 -1
- package/src/transaction/index.ts +1 -0
- package/src/transaction/sign-verify.ts +38 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright 2018 - 2022 The Alephium Authors
|
|
4
|
+
This file is part of the alephium project.
|
|
5
|
+
|
|
6
|
+
The library is free software: you can redistribute it and/or modify
|
|
7
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
(at your option) any later version.
|
|
10
|
+
|
|
11
|
+
The library is distributed in the hope that it will be useful,
|
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
GNU Lesser General Public License for more details.
|
|
15
|
+
|
|
16
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
17
|
+
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
*/
|
|
19
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k;
|
|
21
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
22
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
23
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
24
|
+
}
|
|
25
|
+
Object.defineProperty(o, k2, desc);
|
|
26
|
+
}) : (function(o, m, k, k2) {
|
|
27
|
+
if (k2 === undefined) k2 = k;
|
|
28
|
+
o[k2] = m[k];
|
|
29
|
+
}));
|
|
30
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
31
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
32
|
+
}) : function(o, v) {
|
|
33
|
+
o["default"] = v;
|
|
34
|
+
});
|
|
35
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
36
|
+
if (mod && mod.__esModule) return mod;
|
|
37
|
+
var result = {};
|
|
38
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
39
|
+
__setModuleDefault(result, mod);
|
|
40
|
+
return result;
|
|
41
|
+
};
|
|
42
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
+
exports.transactionVerifySignature = exports.transactionSign = void 0;
|
|
44
|
+
const utils = __importStar(require("../utils"));
|
|
45
|
+
const elliptic_1 = require("elliptic");
|
|
46
|
+
const ec = new elliptic_1.ec('secp256k1');
|
|
47
|
+
function transactionSign(txHash, privateKey) {
|
|
48
|
+
const keyPair = ec.keyFromPrivate(privateKey);
|
|
49
|
+
const signature = keyPair.sign(txHash);
|
|
50
|
+
return utils.encodeSignature(signature);
|
|
51
|
+
}
|
|
52
|
+
exports.transactionSign = transactionSign;
|
|
53
|
+
function transactionVerifySignature(txHash, publicKey, signature) {
|
|
54
|
+
try {
|
|
55
|
+
const key = ec.keyFromPublic(publicKey, 'hex');
|
|
56
|
+
return key.verify(txHash, utils.signatureDecode(ec, signature));
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.transactionVerifySignature = transactionVerifySignature;
|
package/package.json
CHANGED
package/src/transaction/index.ts
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2018 - 2022 The Alephium Authors
|
|
3
|
+
This file is part of the alephium project.
|
|
4
|
+
|
|
5
|
+
The library is free software: you can redistribute it and/or modify
|
|
6
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
(at your option) any later version.
|
|
9
|
+
|
|
10
|
+
The library is distributed in the hope that it will be useful,
|
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
GNU Lesser General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
16
|
+
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import * as utils from '../utils'
|
|
20
|
+
import { ec as EC } from 'elliptic'
|
|
21
|
+
|
|
22
|
+
const ec = new EC('secp256k1')
|
|
23
|
+
|
|
24
|
+
export function transactionSign(txHash: string, privateKey: string): string {
|
|
25
|
+
const keyPair = ec.keyFromPrivate(privateKey)
|
|
26
|
+
const signature = keyPair.sign(txHash)
|
|
27
|
+
|
|
28
|
+
return utils.encodeSignature(signature)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function transactionVerifySignature(txHash: string, publicKey: string, signature: string): boolean {
|
|
32
|
+
try {
|
|
33
|
+
const key = ec.keyFromPublic(publicKey, 'hex')
|
|
34
|
+
return key.verify(txHash, utils.signatureDecode(ec, signature))
|
|
35
|
+
} catch (error) {
|
|
36
|
+
return false
|
|
37
|
+
}
|
|
38
|
+
}
|