### p256k/uint256/'.._(_:) Operator Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Creates a range of uint256 values from a start to an end, inclusive. ```APIDOC ## '.._(_:) Operator ### Description Creates a closed range (inclusive) of uint256 values from a starting value up to a specified end value. ### Method Operator Overloading ### Endpoint N/A (In-code operation) ### Parameters - **_**: The starting uint256 value of the range. ### Request Example ```swift let startValue: uint256 = 1 let range = startValue... // Creates a range from startValue to the maximum possible uint256 value ``` ### Response #### Success Response - **PartialRangeFrom**: A range object representing the sequence of uint256 values starting from the given value. ``` -------------------------------- ### p256k/uint256/'.._(_:_:) Operator Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Creates a range of uint256 values from a start to an end, inclusive. ```APIDOC ## '.._(_:_:) Operator ### Description Creates a closed range (inclusive) of uint256 values between a start and an end value. ### Method Operator Overloading ### Endpoint N/A (In-code operation) ### Parameters - **_**: The starting uint256 value of the range. - **_**: The ending uint256 value of the range. ### Request Example ```swift let range = uint256(1) .. uint256(5) // Represents values 1, 2, 3, 4, 5 ``` ### Response #### Success Response - **Range**: A range object representing the sequence of uint256 values. ``` -------------------------------- ### p256k/p256k/schnorr/nonce/reduce(into:_:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Combines the elements of the sequence into a single value using a combining closure, starting with an in-out initial result. ```APIDOC ## p256k/p256k/schnorr/nonce/reduce(into:_:) ### Description Combines the elements of the sequence into a single value using a combining closure, starting with an in-out initial result. ### Method Not specified (likely a method on a sequence type) ### Endpoint Not applicable (SDK method) ### Parameters - **initialResult** (inout Result) - Required - The initial value to use in the reduction. - **updateResult** ((inout Result, Self.Element) -> Void) - Required - The closure that updates the result. ``` -------------------------------- ### p256k/p256k/keyagreement/privatekey/init(format:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Initializes a new P256k private key with a specified format. ```APIDOC ## p256k/p256k/keyagreement/privatekey/init(format:) ### Description Initializes a new P256k private key with a specified format. ### Initializer `init(format: P256k.KeyFormat)` ### Parameters - `format` (P256k.KeyFormat) - The desired format for the new private key. ### Returns - `P256k.KeyAgreement.PrivateKey` - A newly generated P256k private key. ``` -------------------------------- ### init(dataRepresentation:format:) Source: https://docs.21.dev/data/documentation/p256k/p256k/signing/privatekey Creates a secp256k1 private key for signing from a 32-byte raw scalar. ```APIDOC ## init(dataRepresentation:format:) ### Description Creates a secp256k1 private key for signing from a 32-byte raw scalar. ### Parameters #### Path Parameters - **dataRepresentation** (Data) - Description: The 32-byte raw scalar. - **format** (PublicKey.Format) - Description: Controls whether the public key companion is serialized as compressed (33 bytes, default) or uncompressed (65 bytes). ``` -------------------------------- ### init(format:) Source: https://docs.21.dev/data/documentation/p256k/p256k/signing/privatekey Creates a random secp256k1 private key for signing by generating 32 cryptographically secure random bytes and validating them with secp256k1_ec_seckey_verify. ```APIDOC ## init(format:) ### Description Creates a random secp256k1 private key for signing by generating 32 cryptographically secure random bytes and validating them with `secp256k1_ec_seckey_verify`. ### Parameters #### Path Parameters - **format** (PublicKey.Format) - Description: Controls whether the public key companion is serialized as compressed (33 bytes, default) or uncompressed (65 bytes). ``` -------------------------------- ### p256k/uint256/'...(_:_:) Operator Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Creates a range of uint256 values from a start to an end, exclusive of the end. ```APIDOC ## '...(_:_:) Operator ### Description Creates a half-open range (exclusive of the end) of uint256 values between a start and an end value. ### Method Operator Overloading ### Endpoint N/A (In-code operation) ### Parameters - **_**: The starting uint256 value of the range. - **_**: The ending uint256 value of the range (exclusive). ### Request Example ```swift let range = uint256(1)...uint256(5) // Represents values 1, 2, 3, 4 ``` ### Response #### Success Response - **Range**: A range object representing the sequence of uint256 values. ``` -------------------------------- ### p256k/p256k/keyagreement/publickey/init(x963Representation:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Initializes a P256k public key from its X.963 representation. ```APIDOC ## p256k/p256k/keyagreement/publickey/init(x963Representation:) ### Description Initializes a P256k public key from its X.963 representation. ### Initializer `init(x963Representation: Data)` ### Parameters - `x963Representation` (Data) - The X.963-encoded data of the public key. ### Returns - `P256k.KeyAgreement.PublicKey?` - An optional PublicKey instance, or `nil` if the X.963 data is invalid. ``` -------------------------------- ### p256k/uint256/'...(_:)-89x2e Operator Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Creates a range of uint256 values from a start to an end, exclusive of the end. ```APIDOC ## '...(_:)-89x2e Operator ### Description Creates a half-open range (exclusive of the end) of uint256 values starting from a given value up to the maximum possible uint256 value. ### Method Operator Overloading ### Endpoint N/A (In-code operation) ### Parameters - **_**: The starting uint256 value of the range. ### Request Example ```swift let startValue: uint256 = 1 let range = startValue... // Creates a range from startValue up to, but not including, the maximum uint256 value ``` ### Response #### Success Response - **PartialRangeFrom**: A range object representing the sequence of uint256 values starting from the given value. ``` -------------------------------- ### Key Agreement Initialization Source: https://docs.21.dev/data/documentation/p256k/ellipticcurvediffiehellman Demonstrates how to generate private keys and derive their corresponding public keys for ECDH operations within the P256K framework. ```APIDOC ## Key Agreement Initialization ### Description Initialize private keys and derive public keys for ECDH. ### Method `P256K.KeyAgreement.PrivateKey()` ### Usage ```swift import P256K let alicePrivateKey = try P256K.KeyAgreement.PrivateKey() let bobPrivateKey = try P256K.KeyAgreement.PrivateKey() let alicePublicKey = alicePrivateKey.publicKey let bobPublicKey = bobPrivateKey.publicKey ``` ### Notes `P256K.KeyAgreement.PrivateKey` is byte-compatible with `P256K.Signing.PrivateKey`. ``` -------------------------------- ### p256k/uint256/'...(_:)-4ce89 Operator Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Creates a range of uint256 values from a start to an end, exclusive of the end. ```APIDOC ## '...(_:)-4ce89 Operator ### Description Creates a half-open range (exclusive of the end) of uint256 values starting from a given value up to the maximum possible uint256 value. ### Method Operator Overloading ### Endpoint N/A (In-code operation) ### Parameters - **_**: The starting uint256 value of the range. ### Request Example ```swift let startValue: uint256 = 1 let range = startValue... // Creates a range from startValue up to, but not including, the maximum uint256 value ``` ### Response #### Success Response - **PartialRangeFrom**: A range object representing the sequence of uint256 values starting from the given value. ``` -------------------------------- ### p256k/p256k/format/init(rawValue:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Initializes a P256k format from its raw value. ```APIDOC ## p256k/p256k/format/init(rawValue:) ### Description Initializes a P256k format from its raw value. ### Initializer `init(rawValue: Int)` ### Parameters - `rawValue` (Int) - The raw integer value representing the format. ### Returns - `P256k.Format?` - An optional P256k.Format instance, or `nil` if the raw value is invalid. ``` -------------------------------- ### p256k/p256k/musig/publickey/init(xonlykey:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Initializes a public key from an x-only key. ```APIDOC ## p256k/p256k/musig/publickey/init(xonlykey:) ### Description Initializes a public key from an x-only key. ### Method Not specified (likely a constructor or factory method) ### Parameters - **xonlykey**: The x-only key to initialize the public key from. ``` -------------------------------- ### p256k/uint256/init(from:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Initializes a uint256 from another uint256 value. ```APIDOC ## p256k/uint256/init(from:) ### Description Initializes a uint256 from another uint256 value. ### Parameters #### Path Parameters - **from** (uint256) - Required - The source uint256 value. ``` -------------------------------- ### PrivateKey Initialization Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Covers multiple ways to initialize a PrivateKey, including from raw data, DER, PEM, and specific formats. ```APIDOC ## PrivateKey Initialization ### Description Initializes a PrivateKey instance from various formats. ### Methods - `init(_: PrivateKeyFormat)` - `init(dataRepresentation: Data, format: PrivateKeyFormat)` - `init(derRepresentation: Data)` - `init(format: PrivateKeyFormat)` - `init(pemRepresentation: Data)` ``` -------------------------------- ### XOnlyKey Initialization Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Explains how to initialize an XOnlyKey from its data representation, specifying key parity and cache. ```APIDOC ## XOnlyKey Initialization ### Description Initializes an XOnlyKey instance. ### Parameters - **dataRepresentation** (Data): The byte representation of the key. - **keyParity** (KeyParity): The parity of the key. - **cache** (Cache?): An optional cache for performance optimization. ``` -------------------------------- ### Initialize Key Agreement Keys Source: https://docs.21.dev/data/documentation/p256k/ellipticcurvediffiehellman Generate private keys for key agreement. These are byte-compatible with signing private keys. ```swift import P256K let alicePrivateKey = try P256K.KeyAgreement.PrivateKey() let bobPrivateKey = try P256K.KeyAgreement.PrivateKey() let alicePublicKey = alicePrivateKey.publicKey let bobPublicKey = bobPrivateKey.publicKey ``` -------------------------------- ### p256k/p256k/context/create() Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Creates a new P256k context. ```APIDOC ## p256k/p256k/context/create() ### Description Creates a new P256k context. ### Method `create()` ### Returns - `Context` - A new instance of the P256k context. ``` -------------------------------- ### p256k/p256k/keyagreement/privatekey/init(dataRepresentation:format:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Initializes a P256k private key from data representation and format. ```APIDOC ## p256k/p256k/keyagreement/privatekey/init(dataRepresentation:format:) ### Description Initializes a P256k private key from its data representation and specified format. ### Initializer `init(dataRepresentation: Data, format: P256k.KeyFormat)` ### Parameters - `dataRepresentation` (Data) - The raw data representing the private key. - `format` (P256k.KeyFormat) - The format of the private key data. ### Returns - `P256k.KeyAgreement.PrivateKey?` - An optional PrivateKey instance, or `nil` if the data is invalid or cannot be parsed. ``` -------------------------------- ### p256k/p256k/keyagreement/publickey/init(dataRepresentation:format:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Initializes a P256k public key from data representation and format. ```APIDOC ## p256k/p256k/keyagreement/publickey/init(dataRepresentation:format:) ### Description Initializes a P256k public key from its data representation and specified format. ### Initializer `init(dataRepresentation: Data, format: P256k.KeyFormat)` ### Parameters - `dataRepresentation` (Data) - The raw data representing the public key. - `format` (P256k.KeyFormat) - The format of the public key data. ### Returns - `P256k.KeyAgreement.PublicKey?` - An optional PublicKey instance, or `nil` if the data is invalid or cannot be parsed. ``` -------------------------------- ### p256k/p256k/recovery/privatekey/init(datarepresentation:format:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Initializes a private key from its data representation and format. ```APIDOC ## p256k/p256k/recovery/privatekey/init(datarepresentation:format:) ### Description Initializes a private key from its data representation and format. ### Method Not specified (likely a constructor or factory method) ### Parameters - **datarepresentation**: The data representation of the private key. - **format**: The format of the data representation. ``` -------------------------------- ### p256k/uint256/init(rawvalue:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Initializes a uint256 from its raw value representation. ```APIDOC ## p256k/uint256/init(rawvalue:) ### Description Initializes a uint256 from its raw value representation. ### Parameters #### Path Parameters - **rawValue** (UInt64) - Required - The raw value. ``` -------------------------------- ### p256k/p256k/keyagreement/publickey/init(derRepresentation:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Initializes a P256k public key from its DER representation. ```APIDOC ## p256k/p256k/keyagreement/publickey/init(derRepresentation:) ### Description Initializes a P256k public key from its DER representation. ### Initializer `init(derRepresentation: Data)` ### Parameters - `derRepresentation` (Data) - The DER-encoded data of the public key. ### Returns - `P256k.KeyAgreement.PublicKey?` - An optional PublicKey instance, or `nil` if the DER data is invalid. ``` -------------------------------- ### p256k/p256k/musig/xonlykey/init(datarepresentation:keyparity:cache:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Initializes an x-only key from a data representation with key parity and cache. ```APIDOC ## p256k/p256k/musig/xonlykey/init(datarepresentation:keyparity:cache:) ### Description Initializes an x-only key from a data representation with key parity and cache. ### Method Not specified (likely a constructor or factory method) ### Parameters - **datarepresentation**: The data representation of the x-only key. - **keyparity**: The parity of the key. - **cache**: Cache object for potential optimizations. ``` -------------------------------- ### p256k/p256k/musig/publickey/init(datarepresentation:format:cache:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Initializes a public key from a data representation with a specified format and cache. ```APIDOC ## p256k/p256k/musig/publickey/init(datarepresentation:format:cache:) ### Description Initializes a public key from a data representation with a specified format and cache. ### Method Not specified (likely a constructor or factory method) ### Parameters - **datarepresentation**: The data representation of the public key. - **format**: The format of the data representation. - **cache**: Cache object for potential optimizations. ``` -------------------------------- ### init(pemRepresentation:) Source: https://docs.21.dev/data/documentation/p256k/p256k/signing/privatekey Creates a secp256k1 private key for signing from a Privacy-Enhanced Mail (PEM) representation. ```APIDOC ## init(pemRepresentation:) ### Description Creates a secp256k1 private key for signing from a Privacy-Enhanced Mail (PEM) representation. ### Parameters #### Path Parameters - **pemRepresentation** (Data) - Description: The PEM encoded private key. ``` -------------------------------- ### p256k/uint256/init(integerliteral:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Initializes a uint256 from an integer literal. ```APIDOC ## p256k/uint256/init(integerliteral:) ### Description Initializes a uint256 from an integer literal. ### Parameters #### Path Parameters - **integerLiteral** (Int) - Required - The integer literal value. ``` -------------------------------- ### p256k/p256k/schnorr/partialsignature/init(datarepresentation:session:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Initializes a partial signature from its data representation and session. ```APIDOC ## p256k/p256k/schnorr/partialsignature/init(datarepresentation:session:) ### Description Initializes a partial signature from its data representation and session. ### Method Initializer ### Endpoint Not applicable (SDK method) ### Parameters - **datarepresentation** (Data) - Required - The data representation of the partial signature. - **session** (Session) - Required - The session associated with the signature. ``` -------------------------------- ### init(derRepresentation:) Source: https://docs.21.dev/data/documentation/p256k/p256k/signing/privatekey Creates a secp256k1 private key for signing from a Distinguished Encoding Rules (DER) encoded representation. ```APIDOC ## init(derRepresentation:) ### Description Creates a secp256k1 private key for signing from a Distinguished Encoding Rules (DER) encoded representation. ### Parameters #### Path Parameters - **derRepresentation** (Data) - Description: The DER encoded private key. ``` -------------------------------- ### Export and Import Raw Public Keys Source: https://docs.21.dev/data/documentation/p256k/serializingkeys Use `dataRepresentation` to export public keys as raw bytes and `init(dataRepresentation:format:)` to import them. The format can be explicitly specified. ```swift // Export (33 bytes compressed, 65 bytes uncompressed) let keyData = publicKey.dataRepresentation // Import with explicit format let restored = try P256K.Signing.PublicKey( dataRepresentation: keyData, format: .compressed ) ``` -------------------------------- ### p256k/uint256/init(littleendian:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Initializes a uint256 from a little-endian byte array. ```APIDOC ## p256k/uint256/init(littleendian:) ### Description Initializes a uint256 from a little-endian byte array. ### Parameters #### Path Parameters - **littleendian** (Data) - Required - The little-endian byte data. ``` -------------------------------- ### p256k/p256k/schnorr/nonce/starts(with:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Checks if the sequence begins with the elements of another sequence. ```APIDOC ## p256k/p256k/schnorr/nonce/starts(with:) ### Description Checks if the sequence begins with the elements of another sequence. ### Method Not specified (likely a method on a sequence type) ### Endpoint Not applicable (SDK method) ### Parameters - **possiblePrefix** (Self) - Required - The sequence to check for as a prefix. ``` -------------------------------- ### Taproot Output Key Construction (with Script Tree) Source: https://docs.21.dev/data/documentation/p256k/tweakingkeys Construct a Taproot output key when a script tree is involved. The Merkle root of the script tree is included in the tweak hash calculation. ```swift // H_TapTweak(internalKey || merkleRoot) let tweakHash = SHA256.taggedHash( tag: "TapTweak".data(using: .utf8)!, data: Data(internalKey.bytes) + merkleRoot ) let outputKey = try internalKey.add(Array(tweakHash)) ``` -------------------------------- ### p256k/p256k/schnorr/nonce/starts(with:by:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Checks if the sequence begins with the elements of another sequence, using a custom predicate for comparison. ```APIDOC ## p256k/p256k/schnorr/nonce/starts(with:by:) ### Description Checks if the sequence begins with the elements of another sequence, using a custom predicate for comparison. ### Method Not specified (likely a method on a sequence type) ### Endpoint Not applicable (SDK method) ### Parameters - **possiblePrefix** (Self) - Required - The sequence to check for as a prefix. - **areEquivalent** ((Self.Element, Self.Element) -> Bool) - Required - The closure used to compare elements. ``` -------------------------------- ### p256k/p256k/schnorr/nonce/sorted(using:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Returns a sequence with the elements sorted according to the provided key-path. ```APIDOC ## p256k/p256k/schnorr/nonce/sorted(using:) ### Description Returns a sequence with the elements sorted according to the provided key-path. ### Method Not specified (likely a method on a sequence type) ### Endpoint Not applicable (SDK method) ### Parameters - **keyPath** (KeyPath) - Required - The key path to sort by. ``` -------------------------------- ### p256k/p256k/schnorr/nonce/prefix(_:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Returns a subsequence containing the first `maxLength` elements. ```APIDOC ## p256k/p256k/schnorr/nonce/prefix(_:) ### Description Returns a subsequence containing the first `maxLength` elements. ### Method Not specified (likely a method on a sequence type) ### Endpoint Not applicable (SDK method) ### Parameters - **maxLength** (Int) - Required - The maximum number of elements to include. ``` -------------------------------- ### Construction from X-only Key Source: https://docs.21.dev/data/documentation/p256k/p256k/signing/publickey Creates a compressed secp256k1 public key from an x-only key by prepending the parity prefix. ```APIDOC ## init(xonlyKey:) ### Description Creates a compressed secp256k1 public key from an x-only key by prepending the 0x02 (even-Y) or 0x03 (odd-Y) parity prefix. ### Parameters #### Path Parameters - **xonlyKey** (Data) - Description ### Response #### Success Response (200) - **PublicKey** (PublicKey) - Description ``` -------------------------------- ### Add P256K to Your Project Source: https://docs.21.dev/data/documentation/p256k/gettingstarted Add the swift-secp256k1 library as a Swift Package Manager dependency. Import the P256K module in your Swift files. ```swift // Package.swift dependencies: [ // Pin with exact: because the API is pre-1.0 and not yet stable. .package(url: "https://github.com/21-DOT-DEV/swift-secp256k1.git", exact: "0.18.0"), ], targets: [ .target( name: "MyTarget", dependencies: [ .product(name: "P256K", package: "swift-secp256k1"), ] ) ] ``` ```swift import P256K ``` -------------------------------- ### Taproot Output Key Construction (Key-Path Only) Source: https://docs.21.dev/data/documentation/p256k/tweakingkeys Construct a Taproot output key for a key-path-only spending condition using a tagged hash tweak. The tweak is derived from the internal key. ```swift let internalKey = try P256K.Schnorr.PrivateKey( dataRepresentation: keyBytes ).xonly // Compute the taptweak: H_TapTweak(internalKey) let tweakHash = SHA256.taggedHash( tag: "TapTweak".data(using: .utf8)!, data: Data(internalKey.bytes) ) // Derive the output key: internalKey + tweakHash let outputKey = try internalKey.add(Array(tweakHash)) ``` -------------------------------- ### p256k/p256k/recovery/ecdsasignature/init(datarepresentation:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Initializes an ECDSA signature from its data representation. ```APIDOC ## p256k/p256k/recovery/ecdsasignature/init(datarepresentation:) ### Description Initializes an ECDSA signature from its data representation. ### Method Not specified (likely a constructor or factory method) ### Parameters - **datarepresentation**: The data representation of the signature. ``` -------------------------------- ### Create Private Keys with Specific Public Key Format Source: https://docs.21.dev/data/documentation/p256k/serializingkeys Specify the desired format (.compressed or .uncompressed) when creating new private keys. The public key's data representation length will reflect the chosen format. ```swift // Compressed (default): 33-byte public key with 0x02 or 0x03 prefix let compressed = try P256K.Signing.PrivateKey(format: .compressed) compressed.publicKey.dataRepresentation.count // 33 // Uncompressed: 65-byte public key with 0x04 prefix let uncompressed = try P256K.Signing.PrivateKey(format: .uncompressed) uncompressed.publicKey.dataRepresentation.count // 65 ``` -------------------------------- ### p256k/uint256/init(truncatingifneeded:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Initializes a uint256 from a larger integer type, truncating if necessary. ```APIDOC ## p256k/uint256/init(truncatingifneeded:) ### Description Initializes a uint256 from a larger integer type, truncating if necessary. ### Parameters #### Path Parameters - **truncatingIfNeeded** (UInt) - Required - The source integer value. ``` -------------------------------- ### p256k/p256k/format/rawrepresentable-implementations Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Provides RawRepresentable conformance for P256k formats. ```APIDOC ## p256k/p256k/format/rawrepresentable-implementations ### Description Provides RawRepresentable conformance for P256k formats, allowing conversion to and from raw values. ### Protocol Conformance `RawRepresentable` ``` -------------------------------- ### p256k/p256k/format/equatable-implementations Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Provides Equatable conformance for P256k formats. ```APIDOC ## p256k/p256k/format/equatable-implementations ### Description Provides Equatable conformance for P256k formats, allowing comparison for equality. ### Protocol Conformance `Equatable` ``` -------------------------------- ### XOnlyKey Operations Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Documentation for operations related to P256k Schnorr X-only keys. ```APIDOC ## XOnlyKey Methods ### `init(dataRepresentation:)` Initializes an X-only key from its data representation. - **dataRepresentation** (Data) - The byte representation of the X-only key. ### `add(_:)` Adds another X-only key to this one. - **other** (XOnlyKey) - The X-only key to add. ### `bytes` Returns the byte representation of the X-only key. ### `cache` Returns a cached representation of the X-only key. ### `==(_:_:)` Checks for equality between two X-only keys. ### `!=(_:_:)` Checks for inequality between two X-only keys. ``` -------------------------------- ### Public Key Data Representation Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Provides methods for initializing a PublicKey from various data representations and retrieving its data representation. ```APIDOC ## Public Key Data Representation ### Description Provides methods for initializing a PublicKey from various data representations and retrieving its data representation. ### Initializers - `init(datarepresentation: PublicKey.Format)`: Initializes a PublicKey from its data representation. - `init(derrepresentation: Data)`: Initializes a PublicKey from its DER representation. - `init(pemrepresentation: String)`: Initializes a PublicKey from its PEM representation. - `init(x963representation: Data)`: Initializes a PublicKey from its X963 representation. - `init(xonlykey: XOnlyKey)`: Initializes a PublicKey from an XOnlyKey. ### Properties - `uncompressedRepresentation`: Returns the uncompressed representation of the public key. - `xonly`: Returns the X-only representation of the public key. ``` -------------------------------- ### p256k/p256k/schnorr/nonce/shuffled() Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Returns a sequence with the elements in a random order. ```APIDOC ## p256k/p256k/schnorr/nonce/shuffled() ### Description Returns a sequence with the elements in a random order. ### Method Not specified (likely a method on a sequence type) ### Endpoint Not applicable (SDK method) ### Parameters None ``` -------------------------------- ### p256k/p256k/context/rawRepresentation Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Returns the raw representation of the P256k context. ```APIDOC ## p256k/p256k/context/rawRepresentation ### Description Returns the raw representation of the P256k context. ### Property `rawRepresentation` (Data) ### Remarks This property provides the context data in a raw byte format. ``` -------------------------------- ### p256k/p256k/schnorr/nonce/shuffled(using:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Returns a sequence with the elements in a random order, using the provided random number generator. ```APIDOC ## p256k/p256k/schnorr/nonce/shuffled(using:) ### Description Returns a sequence with the elements in a random order, using the provided random number generator. ### Method Not specified (likely a method on a sequence type) ### Endpoint Not applicable (SDK method) ### Parameters - **generator** (RandomAccessCollection) - Required - The random number generator to use. ``` -------------------------------- ### p256k/p256k/recovery/ecdsasignature/init(compactrepresentation:recoveryid:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Initializes an ECDSA signature from its compact representation and recovery ID. ```APIDOC ## p256k/p256k/recovery/ecdsasignature/init(compactrepresentation:recoveryid:) ### Description Initializes an ECDSA signature from its compact representation and recovery ID. ### Method Not specified (likely a constructor or factory method) ### Parameters - **compactrepresentation**: The compact representation of the signature. - **recoveryid**: The recovery ID associated with the signature. ``` -------------------------------- ### Create a New Context in P256K Source: https://docs.21.dev/data/documentation/p256k/p256k/context Call create() when an independently randomized context with isolated cryptographic state is needed. ```swift let ctx = P256K.Context.create() ``` -------------------------------- ### Construction from Serialized Bytes Source: https://docs.21.dev/data/documentation/p256k/p256k/signing/publickey Creates a secp256k1 public key from serialized bytes, supporting compressed (33-byte) or uncompressed (65-byte) formats. ```APIDOC ## init(dataRepresentation:format:) ### Description Creates a secp256k1 public key from serialized bytes. ### Parameters #### Path Parameters - **dataRepresentation** (Data) - Description - **format** (PublicKey.Format) - Description ### Response #### Success Response (200) - **PublicKey** (PublicKey) - Description ``` -------------------------------- ### Import Private and Public Keys from DER Bytes Source: https://docs.21.dev/data/documentation/p256k/serializingkeys Import private and public keys directly from DER-encoded binary data. ```swift let privateKey = try P256K.Signing.PrivateKey(derRepresentation: derBytes) let publicKey = try P256K.Signing.PublicKey(derRepresentation: derBytes) ``` -------------------------------- ### p256k/uint256/min Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Returns the minimum possible value for a uint256. ```APIDOC ## p256k/uint256/min ### Description Returns the minimum possible value for a uint256. ### Returns - **uint256** - The minimum value. ``` -------------------------------- ### XOnlyKey Equatable Implementations Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Provides details on how XOnlyKey conforms to the Equatable protocol, allowing for equality checks between keys. ```APIDOC ## XOnlyKey Equatable Implementations This section details the Equatable conformance for the XOnlyKey type, enabling direct comparison of two XOnlyKey instances for equality. ``` -------------------------------- ### p256k/p256k/schnorr/nonce/reversed() Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Returns a sequence with the elements in reverse order. ```APIDOC ## p256k/p256k/schnorr/nonce/reversed() ### Description Returns a sequence with the elements in reverse order. ### Method Not specified (likely a method on a sequence type) ### Endpoint Not applicable (SDK method) ### Parameters None ``` -------------------------------- ### p256k/p256k/format/hash(into:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Computes the hash of the P256k format. ```APIDOC ## p256k/p256k/format/hash(into:) ### Description Computes the hash of the P256k format for use in hashable collections. ### Method `hash(into: inout Hasher)` ### Parameters - `hasher` (inout Hasher) - The hasher to use for computing the hash. ``` -------------------------------- ### Convert Compressed Public Key to Uncompressed Source: https://docs.21.dev/data/documentation/p256k/serializingkeys Convert a compressed public key (33 bytes) to its uncompressed form (65 bytes) using `uncompressedRepresentation`. ```swift let fullBytes = compressedPublicKey.uncompressedRepresentation // 65 bytes ``` -------------------------------- ### BIP-352 Tagged Hashes with P256K Source: https://docs.21.dev/data/documentation/p256k/silentpayments Demonstrates how to compute BIP-340-style tagged hashes using P256K's taggedHash function. Pass the tag string as UTF-8 bytes. ```swift try taggedHash(tag: "BIP0352/SharedSecret", data: input_hash.bytes + a.bytes + B.bytes) ``` -------------------------------- ### p256k/keyformats Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Defines the available formats for P256k keys. ```APIDOC ## p256k/keyformats ### Description Defines the available formats for P256k keys. ### Type `enum KeyFormat` ### Cases - `compressed` - `uncompressed` ``` -------------------------------- ### Import Public Key from PEM String Source: https://docs.21.dev/data/documentation/p256k/serializingkeys Import public keys from PEM-encoded strings using the `PUBLIC KEY` PEM type. ```swift let publicKey = try P256K.Signing.PublicKey(pemRepresentation: publicKeyPEM) ``` -------------------------------- ### p256k/p256k/schnorr/nonce/withcontiguousstorageifavailable(_:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Returns a view of the sequence that is contiguous if possible. ```APIDOC ## p256k/p256k/schnorr/nonce/withcontiguousstorageifavailable(_:) ### Description Returns a view of the sequence that is contiguous if possible. ### Method Not specified (likely a method on a sequence type) ### Endpoint Not applicable (SDK method) ### Parameters - **closure** ((UnsafeRawBufferPointer) -> Result) - Required - The closure to execute with the contiguous storage. ``` -------------------------------- ### p256k/p256k/format/compressed Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Represents the compressed format for P256k keys. ```APIDOC ## p256k/p256k/format/compressed ### Description Represents the compressed format for P256k keys. ### Case `compressed` ### Remarks In this format, the public key is represented by its x-coordinate and a single byte indicating the sign of the y-coordinate. ``` -------------------------------- ### Generate Compressed Public Key (Default) Source: https://docs.21.dev/data/documentation/p256k/keyformats Generates a new secp256k1 private key and retrieves its public key in the default compressed format. The compressed format is standard for Bitcoin and uses 33 bytes. ```swift let key = try P256K.Signing.PrivateKey() // compressed by default key.publicKey.dataRepresentation.count // 33 key.publicKey.format // .compressed ``` -------------------------------- ### Construction from ANSI X9.63 Representation Source: https://docs.21.dev/data/documentation/p256k/p256k/signing/publickey Creates a secp256k1 public key from an ANSI X9.63 representation. ```APIDOC ## init(x963Representation:) ### Description Creates a secp256k1 public key from an ANSI X9.63 representation. ### Parameters #### Path Parameters - **x963Representation** (Data) - Description ### Response #### Success Response (200) - **PublicKey** (PublicKey) - Description ``` -------------------------------- ### p256k/p256k/schnorr/nonce/min() Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Finds the minimum element in the nonce sequence. ```APIDOC ## p256k/p256k/schnorr/nonce/min() ### Description Finds the minimum element in the nonce sequence. ### Method Not specified (likely a method on a sequence type) ### Endpoint Not applicable (SDK method) ### Parameters None ``` -------------------------------- ### Generate Schnorr Key Pair Source: https://docs.21.dev/data/documentation/p256k/gettingstarted Initialize a P256K.Schnorr.PrivateKey to create a random Schnorr key pair for BIP-340 compatible signatures. Schnorr verification uses an x-only public key. ```swift // Generate a random Schnorr key pair (BIP-340) let schnorrPrivateKey = try P256K.Schnorr.PrivateKey() let xonlyPublicKey = schnorrPrivateKey.xonly ``` -------------------------------- ### Import Private Key from PEM String Source: https://docs.21.dev/data/documentation/p256k/serializingkeys Import private keys from PEM-encoded strings. Supports both SEC1 (`EC PRIVATE KEY`) and PKCS#8 (`PRIVATE KEY`) formats. ```swift let pemString = """ -----BEGIN EC PRIVATE KEY----- MHQCAQEEIBXwHPDpec6b07GeLbnwetT0dvWzp0nV3MR+4pPKXIc7oAcGBSuBBAAK oUQDQgAEt2uDn+2GqqYs/fmkBr5+rCQ3oiFSIJMAcjHIrTDS6HEELgguOatmFBOp 2wU4P2TAl/0Ihiq+nMkrAIV69m2W8g== -----END EC PRIVATE KEY----- """ let privateKey = try P256K.Signing.PrivateKey(pemRepresentation: pemString) ``` -------------------------------- ### p256k/p256k/schnorr/nonce/sorted() Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Returns a sequence with the elements sorted in ascending order. ```APIDOC ## p256k/p256k/schnorr/nonce/sorted() ### Description Returns a sequence with the elements sorted in ascending order. ### Method Not specified (likely a method on a sequence type) ### Endpoint Not applicable (SDK method) ### Parameters None ``` -------------------------------- ### p256k/p256k/schnorr/nonce/reduce(_:_:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Combines the elements of the sequence into a single value using a combining closure and an initial result. ```APIDOC ## p256k/p256k/schnorr/nonce/reduce(_:_:) ### Description Combines the elements of the sequence into a single value using a combining closure and an initial result. ### Method Not specified (likely a method on a sequence type) ### Endpoint Not applicable (SDK method) ### Parameters - **initialResult** (Result) - Required - The initial value to use in the reduction. - **nextPartialResult** ((Result, Self.Element) -> Result) - Required - The closure that combines elements. ``` -------------------------------- ### p256k/p256k/format/!=(_:_:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Checks if two P256k formats are not equal. ```APIDOC ## p256k/p256k/format/!=(_:_:) ### Description Checks if two P256k formats are not equal. ### Operator `!=` ### Parameters - `lhs` (P256k.Format) - The left-hand side format. - `rhs` (P256k.Format) - The right-hand side format. ### Returns - `Bool` - `true` if the formats are not equal, `false` otherwise. ``` -------------------------------- ### p256k/p256k/format/uncompressed Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Represents the uncompressed format for P256k keys. ```APIDOC ## p256k/p256k/format/uncompressed ### Description Represents the uncompressed format for P256k keys. ### Case `uncompressed` ### Remarks In this format, the public key is represented by its x and y coordinates. ``` -------------------------------- ### Generate ECDSA Key Pair Source: https://docs.21.dev/data/documentation/p256k/gettingstarted Initialize a P256K.Signing.PrivateKey to create a random ECDSA key pair. The private key generates the associated public key on demand. Serialize the private key for storage. ```swift // Generate a random ECDSA key pair let privateKey = try P256K.Signing.PrivateKey() let publicKey = privateKey.publicKey // Serialize the private key for storage let privateKeyBytes = privateKey.dataRepresentation ``` -------------------------------- ### p256k/p256k/schnorr/nonce/map(_:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Applies a transformation to each element of the nonce sequence. ```APIDOC ## p256k/p256k/schnorr/nonce/map(_:) ### Description Applies a transformation to each element of the nonce sequence. ### Method Not specified (likely a method on a sequence type) ### Endpoint Not applicable (SDK method) ### Parameters - **closure** ((Self.Element) -> T) - Required - The transformation to apply. ``` -------------------------------- ### XOnlyKey Operations Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Provides operations related to XOnlyKey, including initialization and property access. ```APIDOC ## XOnlyKey Operations ### Description Provides operations related to XOnlyKey, including initialization and property access. ### Initializers - `init(datarepresentation: Data, keyparity: KeyParity)`: Initializes an XOnlyKey from its data representation and parity. ### Properties - `bytes`: Returns the byte representation of the XOnlyKey. - `parity`: Returns the parity of the XOnlyKey. ``` -------------------------------- ### PrivateKey Operations Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Details operations that can be performed with a PrivateKey, such as addition, multiplication, negation, and generating signatures. ```APIDOC ## PrivateKey Operations ### Description Provides methods for manipulating and using PrivateKeys. ### Methods - `add(_: PrivateKey)` - `multiply(_: PrivateKey)` - `negation`: Returns the negation of the private key. - `signature(for: Message)`: Generates a signature for a given message. ``` -------------------------------- ### Sender: Deriving Destination Output with Single Input Source: https://docs.21.dev/data/documentation/p256k/silentpayments This snippet demonstrates how a sender derives the destination output key for a Silent Payment with a single input. It involves hashing the outpoint and public key, tweaking the sender's private key, performing ECDH, and deriving the shared secret. ```swift import Foundation import P256K // Inputs: sender's private key, receiver's published public key, an outpoint let aliceSigningKey = try P256K.Signing.PrivateKey() // (a, A) // Bob's `B` is published as a compressed 33-byte point; create both views. // `bobECDHKey` participates in ECDH; `bobSigningKey` is the base point we // add the shared-secret tweak to in Step 4. Both wrap the same point. let bobPublicKeyBytes: Data = /* 33-byte compressed B from Bob's address */ let bobECDHKey = try P256K.KeyAgreement.PublicKey( dataRepresentation: bobPublicKeyBytes, format: .compressed ) let bobSigningKey = try P256K.Signing.PublicKey( dataRepresentation: bobPublicKeyBytes, format: .compressed ) let smallestOutpoint: Data = /* 36-byte COutPoint: little-endian txid || vout */ // Step 1: input_hash = hash_BIP0352/Inputs(outpoint_L || A) let inputHashInput = smallestOutpoint + aliceSigningKey.publicKey.dataRepresentation let inputHash = SHA256.taggedHash( tag: "BIP0352/Inputs".data(using: .utf8)!, data: inputHashInput ) // Step 2: ECDH between (input_hash * a) and B. // The spec writes the shared point as input_hash·a·B; with one input, this is // input_hash·a applied as a private-key tweak via `multiply`, then ECDH with B. let tweakedPrivateKey = try aliceSigningKey.multiply(Array(inputHash)) let tweakedECDHKey = try P256K.KeyAgreement.PrivateKey( dataRepresentation: tweakedPrivateKey.dataRepresentation ) let sharedPoint = tweakedECDHKey.sharedSecretFromKeyAgreement(with: bobECDHKey) // Step 3: shared_secret_k = hash_BIP0352/SharedSecret(sharedPoint || ser_32(k)) let k: UInt32 = 0 let kBytes = withUnsafeBytes(of: k.bigEndian) { Data($0) } let sharedSecret = SHA256.taggedHash( tag: "BIP0352/SharedSecret".data(using: .utf8)!, data: Data(sharedPoint.bytes) + kBytes ) // Step 4: P_k = B + sharedSecret·G — produce the BIP-341 x-only output key. let destination = try bobSigningKey.add(Array(sharedSecret)) let destinationXonly = destination.xonly.bytes // [UInt8] of length 32 // The taproot scriptPubKey is: OP_1 OP_PUSHBYTES_32 ``` -------------------------------- ### p256k/p256k/schnorr/nonce/publisher Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Provides a Combine publisher for the nonce sequence. ```APIDOC ## p256k/p256k/schnorr/nonce/publisher ### Description Provides a Combine publisher for the nonce sequence. ### Method Not specified (likely a property or method on a sequence type) ### Endpoint Not applicable (SDK method) ### Parameters None ``` -------------------------------- ### PublicKey Operations Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt This section details the methods available for P256k Schnorr public keys. ```APIDOC ## PublicKey Methods ### `init(dataRepresentation:format:)` Initializes a public key from its data representation and format. - **dataRepresentation** (Data) - The byte representation of the public key. - **format** (PublicKeyFormat) - The format of the public key data. ### `init(xOnlyKey:)` Initializes a public key from an X-only key. - **xOnlyKey** (XOnlyKey) - The X-only key. ### `publicKey` Returns the public key itself (for compatibility). ### `xOnly` Derives the X-only public key. ### `dataRepresentation` Returns the byte representation of the public key. ### `format` Returns the format of the public key. ``` -------------------------------- ### Export and Import Raw Private Keys Source: https://docs.21.dev/data/documentation/p256k/serializingkeys Private keys are always exported as 32-byte raw data using `dataRepresentation`. They can be imported using the `init(dataRepresentation:)` initializer. ```swift let privKeyData = privateKey.dataRepresentation // 32 bytes let restored = try P256K.Signing.PrivateKey(dataRepresentation: privKeyData) ``` -------------------------------- ### Create MuSig2 Partial Signature Source: https://docs.21.dev/data/documentation/p256k/musig2multisignatures Create a partial signature using a signer's private key, secret nonce, and the aggregated nonce and public key. ```swift let alicePartial = try alice.partialSignature( for: messageHash, pubnonce: aliceNonce.pubnonce, secureNonce: aliceNonce.secnonce, publicNonceAggregate: aggregateNonce, publicKeyAggregate: aggregate ) ``` -------------------------------- ### p256k/p256k/schnorr/nonce/min(by:) Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Finds the minimum element in the nonce sequence based on a provided comparison closure. ```APIDOC ## p256k/p256k/schnorr/nonce/min(by:) ### Description Finds the minimum element in the nonce sequence based on a provided comparison closure. ### Method Not specified (likely a method on a sequence type) ### Endpoint Not applicable (SDK method) ### Parameters - **comparison** ((Self.Element, Self.Element) -> Bool) - Required - The closure used for comparison. ``` -------------------------------- ### Define PrivateKey Structure Source: https://docs.21.dev/data/documentation/p256k/p256k/recovery/privatekey Defines the PrivateKey structure for secp256k1 recoverable signatures. ```swift struct PrivateKey ``` -------------------------------- ### ECDSA Signature Initialization Source: https://docs.21.dev/data/documentation/p256k/llms-full.txt Details various methods for initializing an ECDSA Signature from different data representations. ```APIDOC ## ECDSA Signature Initialization ### Description Initializes an ECDSA Signature from various data formats. ### Methods - `init(compactRepresentation: Data)` - `init(dataRepresentation: Data)` - `init(derRepresentation: Data)` - `init(unsafeBytes: Data)` ```