# Generating offerings for Swift getOffering ## Created an offering ```js import { DidDht, DidJwk, DidResolver } from '@web5/dids'; import { DevTools, Offering } from '@tbdex/protocol' const bearerDid = await DidDht.create({ options: { publish: true, services: [{ id: 'pfi', type: 'PFI', serviceEndpoint: 'https://localhost:9000' }] } }) const pfiDid = bearerDid; const defaultOfferingData = DevTools.createOfferingData() const mockOffering = DevTools.createOffering({ from: pfiDid, offeringData: { ...defaultOfferingData, payinCurrency: { ...defaultOfferingData.payinCurrency, currencyCode: 'USD' }, payoutCurrency: { ...defaultOfferingData.payoutCurrency, currencyCode: 'KES' } } }); await mockOffering.sign(pfiDid) console.log(JSON.stringify(mockOffering)) ``` ## Output ```json {"metadata":{"from":{"uri":"did:dht:xhguosiycpy4df5gf3s3f64kxfbbdwccarh7ixjfyt6m7y5xemmo","document":{"id":"did:dht:xhguosiycpy4df5gf3s3f64kxfbbdwccarh7ixjfyt6m7y5xemmo","verificationMethod":[{"id":"did:dht:xhguosiycpy4df5gf3s3f64kxfbbdwccarh7ixjfyt6m7y5xemmo#0","type":"JsonWebKey","controller":"did:dht:xhguosiycpy4df5gf3s3f64kxfbbdwccarh7ixjfyt6m7y5xemmo","publicKeyJwk":{"crv":"Ed25519","kty":"OKP","x":"fw04WqBjQaGXZi5tkvtKeUIR0YzBOdq9JQR8voNvQtc","kid":"DmmxxzG5HOGaC-lLJgOdbMTl5sbAkgp2RnfvYeNJLuc","alg":"EdDSA"}}],"authentication":["did:dht:xhguosiycpy4df5gf3s3f64kxfbbdwccarh7ixjfyt6m7y5xemmo#0"],"assertionMethod":["did:dht:xhguosiycpy4df5gf3s3f64kxfbbdwccarh7ixjfyt6m7y5xemmo#0"],"capabilityDelegation":["did:dht:xhguosiycpy4df5gf3s3f64kxfbbdwccarh7ixjfyt6m7y5xemmo#0"],"capabilityInvocation":["did:dht:xhguosiycpy4df5gf3s3f64kxfbbdwccarh7ixjfyt6m7y5xemmo#0"],"service":[{"id":"did:dht:xhguosiycpy4df5gf3s3f64kxfbbdwccarh7ixjfyt6m7y5xemmo#pfi","type":"PFI","serviceEndpoint":"https://localhost:9000"}]},"metadata":{"published":true,"versionId":"1711040604"},"keyManager":{"_algorithmInstances":{},"_keyStore":{"store":{}}}},"kind":"offering","id":"offering_01hsgzf9fqeh49wnzbec3f5qpz","createdAt":"2024-03-21T17:03:23.640Z","protocol":"1.0"},"data":{"description":"Selling BTC for USD","payinCurrency":{"currencyCode":"USD","minAmount":"0.0","maxAmount":"999999.99"},"payoutCurrency":{"currencyCode":"KES","maxAmount":"999526.11"},"payoutUnitsPerPayinUnit":"0.00003826","payinMethods":[{"kind":"DEBIT_CARD","requiredPaymentDetails":{"$schema":"http://json-schema.org/draft-07/schema","type":"object","properties":{"cardNumber":{"type":"string","description":"The 16-digit debit card number","minLength":16,"maxLength":16},"expiryDate":{"type":"string","description":"The expiry date of the card in MM/YY format","pattern":"^(0[1-9]|1[0-2])\\/([0-9]{2})$"},"cardHolderName":{"type":"string","description":"Name of the cardholder as it appears on the card"},"cvv":{"type":"string","description":"The 3-digit CVV code","minLength":3,"maxLength":3}},"required":["cardNumber","expiryDate","cardHolderName","cvv"],"additionalProperties":false}}],"payoutMethods":[{"kind":"BTC_ADDRESS","requiredPaymentDetails":{"$schema":"http://json-schema.org/draft-07/schema","type":"object","properties":{"btcAddress":{"type":"string","description":"your Bitcoin wallet address"}},"required":["btcAddress"],"additionalProperties":false}}],"requiredClaims":{"id":"7ce4004c-3c38-4853-968b-e411bafcd945","input_descriptors":[{"id":"bbdb9b7c-5754-4f46-b63b-590bada959e0","constraints":{"fields":[{"path":["$.type"],"filter":{"type":"string","const":"YoloCredential"}}]}}]}},"signature":"eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDpkaHQ6eGhndW9zaXljcHk0ZGY1Z2YzczNmNjRreGZiYmR3Y2Nhcmg3aXhqZnl0Nm03eTV4ZW1tbyMwIn0..P1LpO_itxQwaIF19rLsf82fCj6bdnEPz85Cb-BiFVA4cMVTCSfZdLtAP623dQAXmD3I766n5rgW6LPy1o8TqBw"} ``` ## Stringified for Swift/To match current offering JSON that uses USD to BTC ```json "{\"metadata\":{\"from\":{\"uri\":\"did:dht:xhguosiycpy4df5gf3s3f64kxfbbdwccarh7ixjfyt6m7y5xemmo\",\"document\":{\"id\":\"did:dht:xhguosiycpy4df5gf3s3f64kxfbbdwccarh7ixjfyt6m7y5xemmo\",\"verificationMethod\":[{\"id\":\"did:dht:xhguosiycpy4df5gf3s3f64kxfbbdwccarh7ixjfyt6m7y5xemmo#0\",\"type\":\"JsonWebKey\",\"controller\":\"did:dht:xhguosiycpy4df5gf3s3f64kxfbbdwccarh7ixjfyt6m7y5xemmo\",\"publicKeyJwk\":{\"crv\":\"Ed25519\",\"kty\":\"OKP\",\"x\":\"fw04WqBjQaGXZi5tkvtKeUIR0YzBOdq9JQR8voNvQtc\",\"kid\":\"DmmxxzG5HOGaC-lLJgOdbMTl5sbAkgp2RnfvYeNJLuc\",\"alg\":\"EdDSA\"}}],\"authentication\":[\"did:dht:xhguosiycpy4df5gf3s3f64kxfbbdwccarh7ixjfyt6m7y5xemmo#0\"],\"assertionMethod\":[\"did:dht:xhguosiycpy4df5gf3s3f64kxfbbdwccarh7ixjfyt6m7y5xemmo#0\"],\"capabilityDelegation\":[\"did:dht:xhguosiycpy4df5gf3s3f64kxfbbdwccarh7ixjfyt6m7y5xemmo#0\"],\"capabilityInvocation\":[\"did:dht:xhguosiycpy4df5gf3s3f64kxfbbdwccarh7ixjfyt6m7y5xemmo#0\"],\"service\":[{\"id\":\"did:dht:xhguosiycpy4df5gf3s3f64kxfbbdwccarh7ixjfyt6m7y5xemmo#pfi\",\"type\":\"PFI\",\"serviceEndpoint\":\"https://localhost:9000\"}]},\"metadata\":{\"published\":true,\"versionId\":\"1711040604\"},\"keyManager\":{\"_algorithmInstances\":{},\"_keyStore\":{\"store\":{}}}},\"kind\":\"offering\",\"id\":\"offering_01hsgzf9fqeh49wnzbec3f5qpz\",\"createdAt\":\"2024-03-21T17:03:23.640Z\",\"protocol\":\"1.0\"},\"data\":{\"description\":\"Selling BTC for USD\",\"payinCurrency\":{\"currencyCode\":\"USD\",\"minAmount\":\"0.0\",\"maxAmount\":\"999999.99\"},\"payoutCurrency\":{\"currencyCode\":\"KES\",\"maxAmount\":\"999526.11\"},\"payoutUnitsPerPayinUnit\":\"0.00003826\",\"payinMethods\":[{\"kind\":\"DEBIT_CARD\",\"requiredPaymentDetails\":{\"$schema\":\"http://json-schema.org/draft-07/schema\",\"type\":\"object\",\"properties\":{\"cardNumber\":{\"type\":\"string\",\"description\":\"The 16-digit debit card number\",\"minLength\":16,\"maxLength\":16},\"expiryDate\":{\"type\":\"string\",\"description\":\"The expiry date of the card in MM/YY format\",\"pattern\":\"^(0[1-9]|1[0-2])\\\\/([0-9]{2})$\"},\"cardHolderName\":{\"type\":\"string\",\"description\":\"Name of the cardholder as it appears on the card\"},\"cvv\":{\"type\":\"string\",\"description\":\"The 3-digit CVV code\",\"minLength\":3,\"maxLength\":3}},\"required\":[\"cardNumber\",\"expiryDate\",\"cardHolderName\",\"cvv\"],\"additionalProperties\":false}}],\"payoutMethods\":[{\"kind\":\"BTC_ADDRESS\",\"requiredPaymentDetails\":{\"$schema\":\"http://json-schema.org/draft-07/schema\",\"type\":\"object\",\"properties\":{\"btcAddress\":{\"type\":\"string\",\"description\":\"your Bitcoin wallet address\"}},\"required\":[\"btcAddress\"],\"additionalProperties\":false}}],\"requiredClaims\":{\"id\":\"7ce4004c-3c38-4853-968b-e411bafcd945\",\"input_descriptors\":[{\"id\":\"bbdb9b7c-5754-4f46-b63b-590bada959e0\",\"constraints\":{\"fields\":[{\"path\":[\"$.type\"],\"filter\":{\"type\":\"string\",\"const\":\"YoloCredential\"}}]}}]}},\"signature\":\"eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDpkaHQ6eGhndW9zaXljcHk0ZGY1Z2YzczNmNjRreGZiYmR3Y2Nhcmg3aXhqZnl0Nm03eTV4ZW1tbyMwIn0..P1LpO_itxQwaIF19rLsf82fCj6bdnEPz85Cb-BiFVA4cMVTCSfZdLtAP623dQAXmD3I766n5rgW6LPy1o8TqBw\"}" ``` ## Asked ChatGPT put it in a variable and wrap it in "{\"data\": ## Also tried replacing the values manually ```swift public static let offeringJson = "{\"data\":[ {\"metadata\":{\"from\":\"did:dht:xhguosiycpy4df5gf3s3f64kxfbbdwccarh7ixjfyt6m7y5xemmo\",\"kind\":\"offering\",\"id\":\"offering_01hsgzf9fqeh49wnzbec3f5qpz\",\"createdAt\":\"2024-03-21T17:03:23.640Z\",\"protocol\":\"1.0\"},\"data\":{\"description\":\"Selling BTC for USD\",\"payinCurrency\":{\"currencyCode\":\"USD\",\"minAmount\":\"0.0\",\"maxAmount\":\"999999.99\"},\"payoutCurrency\":{\"currencyCode\":\"KES\",\"maxAmount\":\"999526.11\"},\"payoutUnitsPerPayinUnit\":\"0.00003826\",\"payinMethods\":[{\"kind\":\"DEBIT_CARD\",\"requiredPaymentDetails\":{\"$schema\":\"http://json-schema.org/draft-07/schema\",\"type\":\"object\",\"properties\":{\"cardNumber\":{\"type\":\"string\",\"description\":\"The 16-digit debit card number\",\"minLength\":16,\"maxLength\":16},\"expiryDate\":{\"type\":\"string\",\"description\":\"The expiry date of the card in MM/YY format\",\"pattern\":\"^(0[1-9]|1[0-2])\\\\/([0-9]{2})$\"},\"cardHolderName\":{\"type\":\"string\",\"description\":\"Name of the cardholder as it appears on the card\"},\"cvv\":{\"type\":\"string\",\"description\":\"The 3-digit CVV code\",\"minLength\":3,\"maxLength\":3}},\"required\":[\"cardNumber\",\"expiryDate\",\"cardHolderName\",\"cvv\"],\"additionalProperties\":false}}],\"payoutMethods\":[{\"kind\":\"BTC_ADDRESS\",\"requiredPaymentDetails\":{\"$schema\":\"http://json-schema.org/draft-07/schema\",\"type\":\"object\",\"properties\":{\"btcAddress\":{\"type\":\"string\",\"description\":\"your Bitcoin wallet address\"}},\"required\":[\"btcAddress\"],\"additionalProperties\":false}}],\"requiredClaims\":{\"id\":\"7ce4004c-3c38-4853-968b-e411bafcd945\",\"input_descriptors\":[{\"id\":\"bbdb9b7c-5754-4f46-b63b-590bada959e0\",\"constraints\":{\"fields\":[{\"path\":[\"$.type\"],\"filter\":{\"type\":\"string\",\"const\":\"YoloCredential\"}}]}}]}},\"signature\":\"eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDpkaHQ6eGhndW9zaXljcHk0ZGY1Z2YzczNmNjRreGZiYmR3Y2Nhcmg3aXhqZnl0Nm03eTV4ZW1tbyMwIn0..P1LpO_itxQwaIF19rLsf82fCj6bdnEPz85Cb-BiFVA4cMVTCSfZdLtAP623dQAXmD3I766n5rgW6LPy1o8TqBw\"} ]}" ``` ## Insert it into my code but I get back invalid offering with an empty [] from let offerings = try await tbDEXHttpClient.getOfferings(pfiDIDURI: pfiDid)