Skip to content

Commit 66d14a8

Browse files
Initial commit
0 parents  commit 66d14a8

File tree

221 files changed

+94636
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

221 files changed

+94636
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
/*.xcodeproj
5+
xcuserdata/
6+
DerivedData/
7+
.swiftpm
8+
.netrc

.gitmodules

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[submodule "Sources/cxxopts"]
2+
path = Sources/cxxopts
3+
url = https://github.com/jarro2783/cxxopts.git
4+
[submodule "Sources/filesystem"]
5+
path = Sources/filesystem
6+
url = https://github.com/gulrak/filesystem.git
7+
[submodule "Sources/chiapos"]
8+
path = Sources/chiapos
9+
url = git@github.com:keyspacewallet/chiapos.git

Package.swift

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// swift-tools-version: 5.7
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "swift-pos",
7+
products: [
8+
.library(
9+
name: "POS",
10+
targets: ["POS"]),
11+
],
12+
targets: [
13+
.target(
14+
name: "blake3",
15+
path: "Sources/chiapos/src/b3",
16+
exclude: [
17+
"blake3_avx2_x86-64_unix.S",
18+
"blake3_avx2.c",
19+
"blake3_avx512_x86-64_unix.S",
20+
"blake3_avx512.c",
21+
"blake3_sse41_x86-64_unix.S",
22+
"blake3_sse41.c",
23+
],
24+
publicHeadersPath: "./",
25+
cSettings: [
26+
.define("BLAKE3_NO_AVX2", to: "1"),
27+
.define("BLAKE3_NO_AVX512", to: "1"),
28+
.define("BLAKE3_NO_SSE41", to: "1")
29+
]),
30+
.target(
31+
name: "chiapos",
32+
path: "Sources/chiapos/src",
33+
exclude: [
34+
"b3",
35+
"cli.cpp",
36+
"../lib/FiniteStateEntropy/lib/huf_compress.c"
37+
],
38+
publicHeadersPath: "./",
39+
cxxSettings: [
40+
.headerSearchPath("b3"),
41+
.headerSearchPath("../lib/include")
42+
]),
43+
.target(
44+
name: "ObjCPOS",
45+
dependencies: ["chiapos", "blake3"],
46+
path: "Sources/ObjCPOS",
47+
cxxSettings: [
48+
.headerSearchPath("../chiapos/src"),
49+
.headerSearchPath("../chiapos/src/b3"),
50+
.headerSearchPath("../chiapos/lib/include")
51+
]),
52+
.target(
53+
name: "POS",
54+
dependencies: ["ObjCPOS"]),
55+
.testTarget(
56+
name: "POSTests",
57+
dependencies: ["POS"]),
58+
],
59+
cxxLanguageStandard: .cxx17
60+
)

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Swift Proof of Space
2+
3+
Swift package of [Chia-Network/chiapos](https://github.com/Chia-Network/chiapos).

Sources/ObjCPOS/Include/POS.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#import <Foundation/Foundation.h>
2+
3+
NS_ASSUME_NONNULL_BEGIN
4+
5+
@interface POS : NSObject
6+
7+
+ (NSData *)validate_proof:(NSData *)proof_id
8+
k:(UInt8)k
9+
challenge:(NSData *)challenge
10+
proof:(NSData *)proof_bytes;
11+
12+
@end
13+
14+
NS_ASSUME_NONNULL_END

Sources/ObjCPOS/POS.mm

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#import "POS.h"
2+
#import "verifier.hpp"
3+
4+
@implementation POS
5+
6+
+ (NSData *)validate_proof:(NSData *)proof_id k:(UInt8)k challenge:(NSData *)challenge proof:(NSData *)proof_bytes {
7+
const uint8_t *seed_ptr = (uint8_t *)proof_id.bytes;
8+
const uint8_t *challenge_ptr = (uint8_t *)challenge.bytes;
9+
const uint8_t *proof_ptr = (uint8_t *)proof_bytes.bytes;
10+
LargeBits quality = Verifier().ValidateProof(seed_ptr, k, challenge_ptr, proof_ptr, proof_bytes.length);
11+
12+
if (quality.GetSize() == 0) {
13+
return [[NSData alloc] init];
14+
}
15+
16+
uint8_t *quality_buf = new uint8_t[32];
17+
quality.ToBytes(quality_buf);
18+
return [NSData dataWithBytes:quality_buf length:32];
19+
}
20+
21+
@end

Sources/POS/POS.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@_exported import ObjCPOS

Sources/chiapos/.clang-format

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
BasedOnStyle: Google
2+
UseTab: Never
3+
ColumnLimit: 100
4+
IndentWidth: 4
5+
TabWidth: 4
6+
AllowShortIfStatementsOnASingleLine: false
7+
IndentCaseLabels: false
8+
AccessModifierOffset: -4
9+
BinPackArguments: false
10+
BinPackParameters: false
11+
AlignAfterOpenBracket: AlwaysBreak
12+
IndentCaseLabels: true
13+
AllowAllParametersOfDeclarationOnNextLine: false
14+
BreakBeforeBraces: Custom
15+
BraceWrapping:
16+
AfterFunction: true
17+
PenaltyReturnTypeOnItsOwnLine: 1000

Sources/chiapos/.dockerignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
*
2+
!lib/
3+
!python-bindings/
4+
!src/
5+
!tests/
6+
!tools/
7+
!uint128_t/
8+
!CMakeLists.txt
9+
!LICENSE
10+
!README.md
11+

Sources/chiapos/.flake8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
max-line-length = 120
3+
exclude = ./lib/pybind11

0 commit comments

Comments
 (0)