Skip to content

Commit c91366b

Browse files
authored
Merge pull request #1 from tkey/refactor
feat: refactor
2 parents 988edd4 + aa60e91 commit c91366b

File tree

28 files changed

+712
-544
lines changed

28 files changed

+712
-544
lines changed

.github/workflows/ci.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
pull_request:
6+
types:
7+
- opened
8+
- reopened
9+
- synchronize
10+
11+
jobs:
12+
build:
13+
runs-on: macOS-latest
14+
strategy:
15+
matrix:
16+
platform:
17+
- iOS
18+
steps:
19+
- uses: actions/[email protected]
20+
- uses: mxcl/xcodebuild@v1
21+
with:
22+
platform: ${{ matrix.platform }}
23+
action: test
24+
scheme: curvelib.swift
25+
code-coverage: true
26+
upload-logs: always

Package.swift

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,41 @@
1-
// swift-tools-version: 5.9
1+
// swift-tools-version: 5.7
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
55

66
let package = Package(
7-
name: "curvelib",
7+
name: "curvelib.swift",
8+
platforms: [
9+
.iOS(SupportedPlatform.IOSVersion.v13), .macOS(.v10_15)
10+
],
811
products: [
912
// Products define the executables and libraries a package produces, making them visible to other packages.
1013
.library(
11-
name: "curvelib",
12-
targets: ["curvelib"]),
14+
name: "curvelib.swift",
15+
targets: ["curvelib.swift"]),
16+
],
17+
dependencies: [
18+
// Dependencies declare other packages that this package depends on.
19+
// .package(url: /* package url */, from: "1.0.0"),
1320
],
14-
1521
targets: [
16-
.binaryTarget(name: "libcurvelib",
17-
path: "Sources/libcurvelib/libcurvelib.xcframework"
22+
.binaryTarget(name: "curve_secp256k1",
23+
path: "Sources/curve_secp256k1/curve_secp256k1.xcframework"
1824
),
1925

20-
.target(name: "tkeylibcurve",
21-
dependencies: ["libcurvelib"],
22-
path: "Sources/libcurvelib"
26+
.target(name: "curvelib",
27+
dependencies: ["curve_secp256k1"],
28+
path: "Sources/curve_secp256k1"
2329
),
2430
// Targets are the basic building blocks of a package, defining a module or a test suite.
2531
// Targets can depend on other targets in this package and products from dependencies.
2632
.target(
27-
name: "curvelib",
28-
dependencies: ["tkeylibcurve"],
33+
name: "curvelib.swift",
34+
dependencies: ["curvelib"],
2935
path: "Sources/curvelib"
3036
),
3137
.testTarget(
3238
name: "curvelibTests",
33-
dependencies: ["curvelib"]),
39+
dependencies: ["curvelib.swift"]),
3440
]
3541
)

Sources/curve_secp256k1/bridge.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "curve_secp256k1.h"

Sources/libcurvelib/libcurvelib.xcframework/Info.plist renamed to Sources/curve_secp256k1/curve_secp256k1.xcframework/Info.plist

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
<array>
77
<dict>
88
<key>BinaryPath</key>
9-
<string>libcurvelib.a</string>
9+
<string>libsecp256k1_rs.a</string>
1010
<key>LibraryIdentifier</key>
1111
<string>ios-arm64_x86_64-simulator</string>
1212
<key>LibraryPath</key>
13-
<string>libcurvelib.a</string>
13+
<string>libsecp256k1_rs.a</string>
1414
<key>SupportedArchitectures</key>
1515
<array>
1616
<string>arm64</string>
@@ -23,11 +23,11 @@
2323
</dict>
2424
<dict>
2525
<key>BinaryPath</key>
26-
<string>libcurvelib.a</string>
26+
<string>libsecp256k1_rs.a</string>
2727
<key>LibraryIdentifier</key>
2828
<string>macos-arm64_x86_64</string>
2929
<key>LibraryPath</key>
30-
<string>libcurvelib.a</string>
30+
<string>libsecp256k1_rs.a</string>
3131
<key>SupportedArchitectures</key>
3232
<array>
3333
<string>arm64</string>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include <stdbool.h>
2+
#include <stdint.h>
3+
4+
#ifndef __curve_secp256k1_H__
5+
#define __curve_secp256k1_H__ // Include guard
6+
7+
#ifdef __cplusplus // Required for C++ compiler
8+
extern "C" {
9+
#endif
10+
//Forward Declarations
11+
struct PublicKey;
12+
struct SecretKey;
13+
struct Signature;
14+
struct PublicKeyCollection;
15+
struct EncryptedMessage;
16+
17+
// Version
18+
char * curve_secp256k1_get_version(int *error_code);
19+
20+
// String
21+
void curve_secp256k1_string_free(char *ptr);
22+
23+
// PrivateKey
24+
struct SecretKey * curve_secp256k1_private_key_generate();
25+
struct SecretKey * curve_secp256k1_private_key_parse(char *input, int *error_code);
26+
void curve_secp256k1_private_key_tweak_add_assign(struct SecretKey *key, struct SecretKey *tweak, int *error_code);
27+
void curve_secp256k1_private_key_tweak_mul_assign(struct SecretKey *key, struct SecretKey *tweak, int *error_code);
28+
void curve_secp256k1_private_key_inv_assign(struct SecretKey *key, int *error_code);
29+
struct SecretKey * curve_secp256k1_private_key_inv(struct SecretKey *key, int *error_code);
30+
struct PublicKey * curve_secp256k1_private_key_to_public_key(struct SecretKey *key, int *error_code);
31+
char * curve_secp256k1_private_key_serialize(struct SecretKey *key, int *error_code);
32+
void curve_secp256k1_private_key_free(struct SecretKey *key);
33+
34+
// PublicKey
35+
struct PublicKey * curve_secp256k1_public_key_parse(char *input, int *error_code);
36+
char * curve_secp256k1_public_key_serialize(struct PublicKey *key, bool compress, int *error_code);
37+
void curve_secp256k1_public_key_tweak_add_assign(struct PublicKey *key, struct SecretKey *tweak, int *error_code);
38+
void curve_secp256k1_public_key_tweak_mul_assign(struct PublicKey *key, struct SecretKey *tweak, int *error_code);
39+
struct PublicKey * curve_secp256k1_public_key_tweak_mul(struct PublicKey *key, struct SecretKey *tweak, int *error_code);
40+
struct PublicKey * curve_secp256k1_public_key_combine(struct PublicKeyCollection* collection, int *error_code);
41+
void curve_secp256k1_public_key_free(struct PublicKey *key);
42+
43+
// PublicKeyCollection
44+
struct PublicKeyCollection * curve_secp256k1_public_key_collection_new();
45+
void curve_secp256k1_public_key_collection_add(struct PublicKeyCollection *collection, struct PublicKey *key, int *error_code);
46+
void curve_secp256k1_public_key_collection_free(struct PublicKeyCollection *collection);
47+
48+
// Signature
49+
struct Signature * curve_secp256k1_ecdsa_signature_parse(char *input, int *error_code);
50+
char * curve_secp256k1_ecdsa_signature_serialize(struct Signature *sig, int *error_code);
51+
void curve_secp256k1_signature_free(struct Signature *signature);
52+
53+
// ECDH
54+
char *curve_secp256k1_ecdh(struct SecretKey *secret_key, struct PublicKey *public_key, int *error_code); // sha256(pk.mul(sk).compress())
55+
char *curve_secp256k1_standard_ecdh(struct SecretKey *secret_key, struct PublicKey *public_key, int *error_code); // Note: This is the standard ecdh which differs from libsecp256k1
56+
57+
// ECDSA
58+
struct Signature * curve_secp256k1_ecdsa_sign_recoverable(struct SecretKey *key, char *hash, int *error_code);
59+
struct PublicKey * curve_secp256k1_ecdsa_recover(struct Signature *signature, char *hash, int *error_code);
60+
61+
// Encryption
62+
struct EncryptedMessage *curve_secp256k1_encrypted_message_from_components(char *ciphertext, struct PublicKey *ephemeral_public_key, char *iv, char *mac, int* error_code);
63+
char *curve_secp256k1_encrypted_message_get_ciphertext(struct EncryptedMessage *message, int* error_code);
64+
struct PublickKey *curve_secp256k1_encrypted_message_get_ephemeral_public_key(struct EncryptedMessage *message, int* error_code);
65+
char *curve_secp256k1_encrypted_message_get_mac(struct EncryptedMessage *message,int* error_code);
66+
char *curve_secp256k1_encrypted_message_get_iv(struct EncryptedMessage *message,int* error_code);
67+
void curve_secp256k1_encrypted_message_free(struct EncryptedMessage *message);
68+
struct EncryptedMessage *curve_secp256k1_aes_cbc_hmac_encrypt(struct PublicKey *public_key, char *plain_text, int *error_code);
69+
char *curve_secp256k1_aes_cbc_hmac_decrypt(struct SecretKey* secret_key, struct EncryptedMessage* encrypted, int* error_code );
70+
71+
#ifdef __cplusplus
72+
} // extern "C"
73+
#endif
74+
#endif // __curve_secp256k1_H__

Sources/curvelib/curvelib.swift

Lines changed: 0 additions & 28 deletions
This file was deleted.

Sources/curvelib/interface.swift

Lines changed: 0 additions & 24 deletions
This file was deleted.

Sources/curvelib/runtimeError.swift

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)